pub struct LinearMixedModel { /* private fields */ }Expand description
A fitted random-intercept linear mixed model
yᵢⱼ = xᵢⱼᵀβ + bⱼ + εᵢⱼ, bⱼ ~ N(0, σ²_b), εᵢⱼ ~ N(0, σ²_e),
for observations i nested in groups j (one random intercept per group).
The marginal covariance is V = σ²_e I + σ²_b ZZᵀ; because there is a single
grouping factor, V⁻¹ is block-diagonal in closed form, so the whole fit
reduces to a one-dimensional search over the variance ratio
λ = σ²_b/σ²_e, profiling out β (by GLS) and σ²_e analytically at each
λ. Method::Reml (default) gives unbiased variance components.
The headline diagnostics are the variance components, the intraclass
correlation ICC = σ²_b/(σ²_b + σ²_e) (the share of variance between
groups, and the correlation of two observations in the same group), and the
BLUPs — shrinkage-predicted group intercepts.
Implementations§
Source§impl LinearMixedModel
impl LinearMixedModel
Sourcepub fn new(x: Array2<f64>, y: Array1<f64>, groups: &[usize]) -> Result<Self>
pub fn new(x: Array2<f64>, y: Array1<f64>, groups: &[usize]) -> Result<Self>
Fit a random-intercept model of y on fixed-effect design X with group
labels groups (one per observation; arbitrary integer labels are
remapped internally), by REML.
X carries the fixed effects including any intercept column, as
elsewhere in the crate.
§Errors
RegressionError::EmptyInput/RegressionError::ShapeMismatch.RegressionError::NoResidualDegreesOfFreedomifn ≤ p.RegressionError::InvalidResponseif there are fewer than two groups.RegressionError::RankDeficientif the GLS information is singular.
Sourcepub fn with_method(
x: Array2<f64>,
y: Array1<f64>,
groups: &[usize],
method: Method,
) -> Result<Self>
pub fn with_method( x: Array2<f64>, y: Array1<f64>, groups: &[usize], method: Method, ) -> Result<Self>
Like LinearMixedModel::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 coefficients(&self) -> ArrayView1<'_, f64>
pub fn coefficients(&self) -> ArrayView1<'_, f64>
Fixed-effect coefficients β̂ (GLS at the estimated variance ratio).
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 group_variance(&self) -> f64
pub fn group_variance(&self) -> f64
Between-group (random-intercept) variance σ̂²_b.
Sourcepub fn variance_ratio(&self) -> f64
pub fn variance_ratio(&self) -> f64
Estimated variance ratio λ̂ = σ̂²_b / σ̂²_e.
Sourcepub fn icc(&self) -> f64
pub fn icc(&self) -> f64
Intraclass correlation ICC = σ̂²_b / (σ̂²_b + σ̂²_e) — the fraction of
total variance attributable to between-group differences, equivalently the
correlation between two observations in the same group.
Sourcepub fn random_effects(&self) -> ArrayView1<'_, f64>
pub fn random_effects(&self) -> ArrayView1<'_, f64>
BLUPs — best linear unbiased predictors of the group random
intercepts b̂_j, indexed by densified group order (first-seen order of
the labels). Each is the group’s mean residual shrunk toward zero by
(λ n_j)/(1 + λ n_j).
Sourcepub fn log_likelihood(&self) -> f64
pub fn log_likelihood(&self) -> f64
The profile log-likelihood (REML or ML per method) at
the estimated variance components.
Trait Implementations§
Source§impl Clone for LinearMixedModel
impl Clone for LinearMixedModel
Source§fn clone(&self) -> LinearMixedModel
fn clone(&self) -> LinearMixedModel
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 LinearMixedModel
impl RefUnwindSafe for LinearMixedModel
impl Send for LinearMixedModel
impl Sync for LinearMixedModel
impl Unpin for LinearMixedModel
impl UnsafeUnpin for LinearMixedModel
impl UnwindSafe for LinearMixedModel
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.