how does one specify a nested covariance pattern in fitlme?

13 views (last 30 days)
i'm new to mixed effects models to begin with, but i'm having an impossible time understanding how to specify nested covariance patterns in fitlme. my current understanding is that with 'CovariancePattern', {'Full','Diagonal'} i'm actually specifying two patterns, one for each of two separate groupings, i.e. one grouping gets 'Full' and the other 'Diagonal'...
i thought the block example in the fitlmematrix documentation might help, but it showed me nothing new... which could very well be from my lack of knowledge in this arena. i'm trying to specify a covariance pattern that has matrices only along the diagonal, each of which has its own Full pattern (i.e. correlated locations are represented in the smaller matrices that each correspond to one animal, which is uncorrelated to other animals i have, which are all represented in the larger matrix.)
let me know if that wasn't confusing enough... thanks, b s

Answers (4)

Gautam Pendse
Gautam Pendse on 18 Nov 2015
Hi Ben,
Look at the example titled "Split-Plot Experiment" at:
Does this help?
Gautam
  2 Comments
Ben
Ben on 18 Nov 2015
yeah, that's for sure what i'm going for. what's missing is the specification; i'm not sure that ...,'CovariancePattern', {'Diagonal', 'Full'}... will actually specify what i'm looking for. maybe the bigger problem is i don't know how to check which grouping got which pattern... i'll look more into that example and report back. thanks for your effort
Ben
Ben on 21 Nov 2015
yeah, so i don't know what went wrong, but i couldn't troubleshoot it as seen below...

Sign in to comment.


Ben
Ben on 21 Nov 2015
if true
fitlme(tbl, 'KS_ISI ~ Pitx*DV + (Pitx*DV|animal:APxML)','CovariancePattern',{'Diagonal', 'Full'})
end
Error using classreg.regr.LinearLikeMixedModel/validateCovariancePattern (line 1639) 'CovariancePattern' must be a string, a logical matrix, or a cell array of length 1. Error in LinearMixedModel.fit (line 2383) covariancepattern = LinearMixedModel.validateCovariancePattern...
Error in fitlme (line 224) lme = LinearMixedModel.fit(ds,formula,varargin{:});
if true
>> fitlme(tbl, 'KS_ISI ~ Pitx*DV + (Pitx*DV|animal:APxML)','CovariancePattern',{{'Diagonal', 'Full'}})
end
Error using classreg.regr.LinearLikeMixedModel/validateCovariancePattern (line 1665) Element 1 of 'CovariancePattern' must be a string or a logical matrix.
Error in LinearMixedModel.fit (line 2383) covariancepattern = LinearMixedModel.validateCovariancePattern...
Error in fitlme (line 224) lme = LinearMixedModel.fit(ds,formula,varargin{:});
pretty sure that's not my fault...

Gautam Pendse
Gautam Pendse on 23 Nov 2015
Hi Ben,
The specification "(Pitx*DV|animal:APxML)" above has only 1 grouping variable - namely "animal:APxML". So 'CovariancePattern' could be {'Diagonal'} for example.
Suppose you have a model say 'y ~ 1 + (x | A) + (z | B)' then this model has two grouping variables A and B - now it would make sense to use 'CovariancePattern' equal to {'Diagonal','Full'}.
Hope this helps,
Gautam
  1 Comment
Ben
Ben on 23 Nov 2015
as in the tomato soil experiment, i used a colon for the grouping variable because i thought would cause one to be applied within the other (which i was calling "nesting" earlier) so that tomato type is taken into account along with the soil type it grew up in as both might vary among responses collected.
if that's so, then how can i specify a different covariance pattern for tomato than for soil? does it just assume both have the same single pattern that can be specified if what you're saying (that the entire "animal:APxML" grouping is a single grouping) is true?
if that's incorrect, then what does the colon operator perform in this case? and how else could i specify different patterns for different groupings that depend on each other?
thanks a lot for your efforts thus far and for any future input

Sign in to comment.


Ben
Ben on 11 Jul 2016
to address this point: "The specification "(Pitx*DV|animal:APxML)" above has only 1 grouping variable - namely "animal:APxML". So 'CovariancePattern' could be {'Diagonal'} for example.
Suppose you have a model say 'y ~ 1 + (x | A) + (z | B)' then this model has two grouping variables A and B - now it would make sense to use 'CovariancePattern' equal to {'Diagonal','Full'}."
my question is primarily how does one specify "nested" groupings, e.g. 'y ~ 1 + (x | A WITHIN B) + ...'?
  1 Comment
Mirko
Mirko on 4 Dec 2023
Have a look at this example that start from modeling a simple linear regression model up to multilevel mixed effect model in MATLAB
Hope it helps

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!