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
impl MixedModel
Sourcepub fn new(
x: Array2<f64>,
y: Array1<f64>,
terms: Vec<RandomEffect>,
) -> Result<Self>
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
RegressionError::EmptyInput/RegressionError::ShapeMismatch.RegressionError::NoResidualDegreesOfFreedomifn ≤ p.RegressionError::InvalidResponseif no terms are given.RegressionError::RankDeficientif the GLS system is singular.
Sourcepub fn with_method(
x: Array2<f64>,
y: Array1<f64>,
terms: Vec<RandomEffect>,
method: Method,
) -> Result<Self>
pub fn with_method( x: Array2<f64>, y: Array1<f64>, terms: Vec<RandomEffect>, method: Method, ) -> Result<Self>
Like MixedModel::new with an explicit Method.
Sourcepub fn n_observations(&self) -> usize
pub fn n_observations(&self) -> usize
Number of observations.
Sourcepub fn n_parameters(&self) -> usize
pub fn n_parameters(&self) -> usize
Number of fixed-effect coefficients.
Sourcepub fn n_random_effects(&self) -> usize
pub fn n_random_effects(&self) -> usize
Total number of random-effect coefficients across all terms.
Sourcepub fn coefficients(&self) -> ArrayView1<'_, f64>
pub fn coefficients(&self) -> ArrayView1<'_, f64>
Fixed-effect coefficients β̂.
Sourcepub fn covariance(&self) -> ArrayView2<'_, f64>
pub fn covariance(&self) -> ArrayView2<'_, f64>
Fixed-effect covariance σ̂²_e (XᵀV⁻¹X)⁻¹.
Sourcepub fn coefficient_standard_errors(&self) -> Array1<f64>
pub fn coefficient_standard_errors(&self) -> Array1<f64>
Fixed-effect standard errors.
Sourcepub fn residual_variance(&self) -> f64
pub fn residual_variance(&self) -> f64
Residual (within-group) variance σ̂²_e.
Sourcepub fn term_covariance(&self, t: usize) -> ArrayView2<'_, f64>
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.
Sourcepub fn random_effects(&self, t: usize) -> ArrayView2<'_, f64>
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).
Sourcepub fn log_likelihood(&self) -> f64
pub fn log_likelihood(&self) -> f64
The profile log-likelihood (REML or ML) at the estimate.
Trait Implementations§
Source§impl Clone for MixedModel
impl Clone for MixedModel
Source§fn clone(&self) -> MixedModel
fn clone(&self) -> MixedModel
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for MixedModel
impl RefUnwindSafe for MixedModel
impl Send for MixedModel
impl Sync for MixedModel
impl Unpin for MixedModel
impl UnsafeUnpin for MixedModel
impl UnwindSafe for MixedModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.