Skip to main content

MixedModel

Struct MixedModel 

Source
pub struct MixedModel { /* private fields */ }
Expand description

A fitted general linear mixed model with one or more random-effect terms — random slopes and/or crossed & nested grouping factors — estimated by REML (default) or ML.

The model is y = Xβ + Zb + ε, b ~ N(0, G), ε ~ N(0, σ²_e I), where Z and G are assembled from the supplied RandomEffect terms (G is block-diagonal, repeating each term’s k × k covariance across its groups). Estimation profiles β (by GLS) and σ²_e out analytically and optimizes the remaining relative covariance parameters with a Nelder–Mead search, using a dense Cholesky solve of the n × n marginal covariance at each step.

For the single random-intercept case prefer the closed-form LinearMixedModel; this type handles everything beyond it, and reduces to it exactly for one intercept term.

§Scale

The dense solve is O(n³) — appropriate for the grouped datasets these diagnostics target, not for very large n.

Implementations§

Source§

impl MixedModel

Source

pub fn new( x: Array2<f64>, y: Array1<f64>, terms: Vec<RandomEffect>, ) -> Result<Self>

Fit by REML. X holds the fixed effects (intercept included); terms are the random-effect terms.

§Errors
Source

pub fn with_method( x: Array2<f64>, y: Array1<f64>, terms: Vec<RandomEffect>, method: Method, ) -> Result<Self>

Like MixedModel::new with an explicit Method.

Source

pub fn n_observations(&self) -> usize

Number of observations.

Source

pub fn n_parameters(&self) -> usize

Number of fixed-effect coefficients.

Source

pub fn n_random_effects(&self) -> usize

Total number of random-effect coefficients across all terms.

Source

pub fn n_terms(&self) -> usize

Number of random-effect terms.

Source

pub fn method(&self) -> Method

Estimation method used.

Source

pub fn coefficients(&self) -> ArrayView1<'_, f64>

Fixed-effect coefficients β̂.

Source

pub fn covariance(&self) -> ArrayView2<'_, f64>

Fixed-effect covariance σ̂²_e (XᵀV⁻¹X)⁻¹.

Source

pub fn coefficient_standard_errors(&self) -> Array1<f64>

Fixed-effect standard errors.

Source

pub fn residual_variance(&self) -> f64

Residual (within-group) variance σ̂²_e.

Source

pub fn term_covariance(&self, t: usize) -> ArrayView2<'_, f64>

Estimated covariance matrix Σ̂ (k × k) of random-effect term t; the diagonal holds the intercept/slope variances, the off-diagonal their covariance.

Source

pub fn random_effects(&self, t: usize) -> ArrayView2<'_, f64>

BLUPs for random-effect term t, shape n_groups × k (row = group, column = the term’s component).

Source

pub fn log_likelihood(&self) -> f64

The profile log-likelihood (REML or ML) at the estimate.

Source

pub fn aic(&self) -> f64

AIC. Under ML the parameter count is p plus the number of covariance parameters plus one for σ²_e; under REML only the covariance parameters and σ²_e are counted.

Trait Implementations§

Source§

impl Clone for MixedModel

Source§

fn clone(&self) -> MixedModel

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MixedModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V