An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-mixed-models/attachments/20110303/9583accd/attachment.pl>
Lmer and variance-covariance matrix
10 messages · Antoine, Douglas Bates, Jarrod Hadfield +4 more
7 days later
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-mixed-models/attachments/20110311/a9c93d02/attachment.pl>
On Thu, Mar 3, 2011 at 7:03 AM, Antoine Paccard
<antoine.paccard at unine.ch> wrote:
Dear modelers, I have been trying in the past few months to obtain a variance- covariance matrix using lmer. I failed multiple times until I decided to do it under SAS. Now, I am going back on it and would like to run it with R. I measured 15 different traits and my data is organized this way: fam ? ? id ? ? trait ? ? score 57 ? ? 1 ? ? 1 ? ? 0.047207645 57 ? ? 2 ? ? 1 ? ? 1.420790311 57 ? ? 3 ? ? 1 ? ? -0.290782077 57 ? ? 1 ? ? 2 ? ? -0.585655473 57 ? ? 2 ? ? 2 ? ? -0.986483343 57 ? ? 3 ? ? 2 ? ? 0.290187057 57 ? ? 1 ? ? 3 ? ? 0.741162271 57 ? ? 2 ? ? 3 ? ? 1.59448736 57 ? ? 3 ? ? 3 ? ? . . ? ? . ? ? . ? ? . . ? ? . ? ? . ? ? . . ? ? . ? ? . ? ? . 57 ? ? 1 ? ? 15 ? ? . 57 ? ? 2 ? ? 15 ? ? . 57 ? ? 3 ? ? 15 ? ? . 58 ? ? 1 ? ? 1 ? ? . 58 ? ? 2 ? ? 1 ? ? . 58 ? ? 3 ? ? 1 ? ? . . ? ? . ? ? . ? ? . . ? ? . ? ? . ? ? . . ? ? . ? ? . ? ? . 58 ? ? 1 ? ? 15 ? ? . 58 ? ? 2 ? ? 15 58 ? ? 3 ? ? 15 . . . 100 ? ? 1 ? ? 15 100 ? ? 2 ? ? 15 100 ? ? 3 ? ? 15 with ?fam? being the family, ?id? the individual, ?trait? the traits measured and ?score? the result of each measures. So far I have been trying to fit this model: d <- data d$fam1 <- factor(d$fam) d$id1 <- factor(d$id) d$trait1 <- factor(d$trait) w.family <- lmer(score ~ (trait1 | fam1/id1 ), data=d)
But I was getting some ?stack overflow? error messages so I ran the model this way: w.family <- lmer(score ~ (trait1 | fam1/id1 ), data=d,control = list (maxIter = 500))
If there are 15 levels of trait you are trying to estimate 240 variance-covariance parameters (120 for fam1 and 120 for fam1:id1). That is a very large optimization problem, I'm not surprised that there is difficulty in finding the optimum.
Although it still didn?t work and I am now wondering what is wrong in this model. The reason why I have put ?trait1? in the random effect is because it was the only way for me to obtain a variance-covariance matrix on all my traits. I am currently trying to put ?trait1? also as fixed effect: w.family <- lmer(score ~ trait1 + (trait1 | fam1/id1 ), data=d,control = list (maxIter = 500)) I would be curious to know what you think about such a model and why it actually doesn?t work. Moreover, I am trying to write done the equation for the model: w.family <- lmer(score ~ (trait1 | fam1/id1 ), data=d) but can?t figure it out. I know I should get something as: Scoreij = ? + fam(i) + Ij(i) + ? But I am not sure if that?s right. What do you think? Thanks a lot for your help, Best, Antoine Paccard ----------- Antoine Paccard, Laboratory of Evolutionary Botany, Institut of biology, Facult? des Sciences, University of Neuch?tel, Unimail, Rue ?mile-Argand 11, 2000, Neuch?tel Switzerland Office: (0041) (0)32 718 23 49 Fax: (0041) (0)32 718 30 01 www.unine.ch/members/antoine.paccard/ http://www2.unine.ch/evobot ? ? ? ?[[alternative HTML version deleted]]
_______________________________________________ R-sig-mixed-models at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
Hi, In addition, each trait is only measured once for each id (correct?) which means that the likelihood could not be optimised even if the data-set was massive. If you could fix the residual variance to some value (preferably zero) then the problem has a unique solution given enough data, but I'm not sure this can be done in lmer? . Since the structure of the residuals is at the moment quite inflexible you probably can't use lmer to fit multi-response models, unless the responses are non-Gaussian and non-binary. Cheers, Jarrod
On 11 Mar 2011, at 13:18, Douglas Bates wrote:
On Thu, Mar 3, 2011 at 7:03 AM, Antoine Paccard <antoine.paccard at unine.ch> wrote:
Dear modelers, I have been trying in the past few months to obtain a variance- covariance matrix using lmer. I failed multiple times until I decided to do it under SAS. Now, I am going back on it and would like to run it with R. I measured 15 different traits and my data is organized this way: fam id trait score 57 1 1 0.047207645 57 2 1 1.420790311 57 3 1 -0.290782077 57 1 2 -0.585655473 57 2 2 -0.986483343 57 3 2 0.290187057 57 1 3 0.741162271 57 2 3 1.59448736 57 3 3 . . . . . . . . . . . . . 57 1 15 . 57 2 15 . 57 3 15 . 58 1 1 . 58 2 1 . 58 3 1 . . . . . . . . . . . . . 58 1 15 . 58 2 15 58 3 15 . . . 100 1 15 100 2 15 100 3 15 with ?fam? being the family, ?id? the individual, ?trait? the traits measured and ?score? the result of each measures. So far I have been trying to fit this model: d <- data d$fam1 <- factor(d$fam) d$id1 <- factor(d$id) d$trait1 <- factor(d$trait) w.family <- lmer(score ~ (trait1 | fam1/id1 ), data=d)
But I was getting some ?stack overflow? error messages so I ran the model this way: w.family <- lmer(score ~ (trait1 | fam1/id1 ), data=d,control = list (maxIter = 500))
If there are 15 levels of trait you are trying to estimate 240 variance-covariance parameters (120 for fam1 and 120 for fam1:id1). That is a very large optimization problem, I'm not surprised that there is difficulty in finding the optimum.
Although it still didn?t work and I am now wondering what is wrong in this model. The reason why I have put ?trait1? in the random effect is because it was the only way for me to obtain a variance-covariance matrix on all my traits. I am currently trying to put ?trait1? also as fixed effect: w.family <- lmer(score ~ trait1 + (trait1 | fam1/id1 ), data=d,control = list (maxIter = 500)) I would be curious to know what you think about such a model and why it actually doesn?t work. Moreover, I am trying to write done the equation for the model: w.family <- lmer(score ~ (trait1 | fam1/id1 ), data=d) but can?t figure it out. I know I should get something as: Scoreij = ? + fam(i) + Ij(i) + ? But I am not sure if that?s right. What do you think? Thanks a lot for your help, Best, Antoine Paccard ----------- Antoine Paccard, Laboratory of Evolutionary Botany, Institut of biology, Facult? des Sciences, University of Neuch?tel, Unimail, Rue ?mile-Argand 11, 2000, Neuch?tel Switzerland Office: (0041) (0)32 718 23 49 Fax: (0041) (0)32 718 30 01 www.unine.ch/members/antoine.paccard/ http://www2.unine.ch/evobot [[alternative HTML version deleted]]
_______________________________________________ R-sig-mixed-models at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
_______________________________________________ R-sig-mixed-models at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336.
On 12/03/11 02:56, Jarrod Hadfield wrote:
Hi, In addition, each trait is only measured once for each id (correct?) which means that the likelihood could not be optimised even if the data-set was massive. If you could fix the residual variance to some value (preferably zero) then the problem has a unique solution given enough data, but I'm not sure this can be done in lmer?.
<SNIP>
I think that it ***CANNOT*** be done. I once asked Doug about
the possibility of this, and he ignored me. As people so often
do. :-) Especially when I ask silly questions .....
cheers,
Rolf Turner
On Fri, Mar 11, 2011 at 2:37 PM, Rolf Turner <r.turner at auckland.ac.nz> wrote:
On 12/03/11 02:56, Jarrod Hadfield wrote:
Hi, In addition, each trait is only measured once for each id (correct?) which means that the likelihood could not be optimised even if the data-set was massive. If you could fix the residual variance to some value (preferably zero) then the problem has a unique solution given enough data, but I'm not sure this can be done in lmer?.
<SNIP> I think that it ***CANNOT*** be done. ?I once asked Doug about the possibility of this, and he ignored me. ?As people so often do. :-) Especially when I ask silly questions .....
Did Doug really ignore you or did he say that the methods in lmer are based on determining the solution to a penalized linear least squares problem so they can't be applied to a model that has zero residual variance. Also the basic parameterization for the variance-covariance matrix of the random effects is in terms of the relative standard deviation (\sigma_1/\sigma) which is problematic when \sigma is zero. (My apologies if I did ignore you, Rolf. I get a lot of email and sometimes such requests slip down the stack and then get lost. I'm very good at procrastinating about the answers to such questions.)
On 12/03/11 09:45, Douglas Bates wrote:
On Fri, Mar 11, 2011 at 2:37 PM, Rolf Turner<r.turner at auckland.ac.nz> wrote:
On 12/03/11 02:56, Jarrod Hadfield wrote: Hi, In addition, each trait is only measured once for each id (correct?) which means that the likelihood could not be optimised even if the data-set was massive. If you could fix the residual variance to some value (preferably zero) then the problem has a unique solution given enough data, but I'm not sure this can be done in lmer?. <SNIP> I think that it ***CANNOT*** be done. I once asked Doug about the possibility of this, and he ignored me. As people so often do. :-) Especially when I ask silly questions .....
Did Doug really ignore you or did he say that the methods in lmer are based on determining the solution to a penalized linear least squares problem so they can't be applied to a model that has zero residual variance. Also the basic parameterization for the variance-covariance matrix of the random effects is in terms of the relative standard deviation (\sigma_1/\sigma) which is problematic when \sigma is zero. (My apologies if I did ignore you, Rolf. I get a lot of email and sometimes such requests slip down the stack and then get lost. I'm very good at procrastinating about the answers to such questions.)
Yes, you really did ignore me. But not to worry; I'm used to it! :-)
I also (more recently) asked Ben Bolker about this issue. He
ignored me too! At that stage I kind of took the hint ......
Your explanation of why it can't be done makes perfect sense.
However I find this constraint sad, because I like to be able to
fit ``marginal case'' models, which can also be fitted in a more
simple-minded manner and compare the results from the
simple-minded procedure with those from the sophisticated
procedure. If they agree, then this augments my confidence
that I am implementing the sophisticated procedure correctly.
An example of such, relating to the current discussion, is a
simple repeated measures model with K (repeated) observations
on each of N subjects, with the within-subject covariance matrix
being an arbitrary positive definite K x K matrix.
This could be treated as a mixed model (if it were possible to
constrain the residual variance to be 0). It can also be treated
as a (simple-minded) multivariate model --- N iid observations
of K-dimensional vectors, the mean and covariance matrix of
these vectors to be estimated.
I would have liked to be able to compare lmer() results with the
(trivial) multivariate analysis estimates. To reassure myself that
I was understanding lmer() syntax correctly.
cheers,
Rolf
On 03/11/2011 05:11 PM, Rolf Turner wrote:
On 12/03/11 09:45, Douglas Bates wrote:
On Fri, Mar 11, 2011 at 2:37 PM, Rolf Turner<r.turner at auckland.ac.nz> wrote:
On 12/03/11 02:56, Jarrod Hadfield wrote: Hi, In addition, each trait is only measured once for each id (correct?) which means that the likelihood could not be optimised even if the data-set was massive. If you could fix the residual variance to some value (preferably zero) then the problem has a unique solution given enough data, but I'm not sure this can be done in lmer?. <SNIP> I think that it ***CANNOT*** be done. I once asked Doug about the possibility of this, and he ignored me. As people so often do. :-) Especially when I ask silly questions .....
Did Doug really ignore you or did he say that the methods in lmer are based on determining the solution to a penalized linear least squares problem so they can't be applied to a model that has zero residual variance. Also the basic parameterization for the variance-covariance matrix of the random effects is in terms of the relative standard deviation (\sigma_1/\sigma) which is problematic when \sigma is zero. (My apologies if I did ignore you, Rolf. I get a lot of email and sometimes such requests slip down the stack and then get lost. I'm very good at procrastinating about the answers to such questions.)
Yes, you really did ignore me. But not to worry; I'm used to it! :-) I also (more recently) asked Ben Bolker about this issue. He ignored me too! At that stage I kind of took the hint ......
I want to distinguish two cases here.
It would be reasonable (although I think not currently feasible) to
fix any variance parameter *other than the residual variance* to zero,
refitting the model with that constraint, to do a test of the effect of
that parameter (keeping in mind the various limitations of finite sample
sizes/unknown null distributions, testing on the boundary, blah blah
blah). This is a special case of the machinery that has to be built in
order for profiling of the random effects to work, and at a pinch you
can get the answer (if you can get lme4a to run on your system) by
fitting the profile and looking at the value at the boundary.
It is reasonable, but not within the framework of lme4, to set one
particular random effect -- the residual variance -- to zero, because
(as Doug points out) it has a special role.
cheers
Ben Bolker
Your explanation of why it can't be done makes perfect sense.
However I find this constraint sad, because I like to be able to
fit ``marginal case'' models, which can also be fitted in a more
simple-minded manner and compare the results from the
simple-minded procedure with those from the sophisticated
procedure. If they agree, then this augments my confidence
that I am implementing the sophisticated procedure correctly.
An example of such, relating to the current discussion, is a
simple repeated measures model with K (repeated) observations
on each of N subjects, with the within-subject covariance matrix
being an arbitrary positive definite K x K matrix.
This could be treated as a mixed model (if it were possible to
constrain the residual variance to be 0). It can also be treated
as a (simple-minded) multivariate model --- N iid observations
of K-dimensional vectors, the mean and covariance matrix of
these vectors to be estimated.
I would have liked to be able to compare lmer() results with the
(trivial) multivariate analysis estimates. To reassure myself that
I was understanding lmer() syntax correctly.
cheers,
Rolf
_______________________________________________ R-sig-mixed-models at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
1 day later
Dear Antoine: This is interesting, but... On Thu, Mar 3, 2011 at 7:03 AM, Antoine Paccard
<antoine.paccard at unine.ch> wrote:
Dear modelers, I have been trying in the past few months to obtain a variance- covariance matrix using lmer. I failed multiple times until I decided to do it under SAS.
Since many people here think your model cannot be fit, but you say it can be fit with SAS, can we please see your SAS command and the output? SAS may be throwing out some parameters from the model automatically, but lmer does not. Just guessing :) PJ
Paul E. Johnson Professor, Political Science 1541 Lilac Lane, Room 504 University of Kansas
1 day later
I sent this on Friday and forgot to copy to list: Antoine, If you reshape your data into the form Fam, Y1, Y2, Y3, ... , Y15, then summary( manova(cbind(Y1,Y2, ... ) ~ Fam ))$SS produces between and within family sums of squares and products matrices (15 x 15). Divide by appropriate number of d.f. to convert these to mean square and product matrices, subtract within from between and divide by family size to get the estimated matrix of between-family variances and covariances. Is it that simple? Or have I forgotten something?
Paul Johnson wrote:
Dear Antoine: This is interesting, but... On Thu, Mar 3, 2011 at 7:03 AM, Antoine Paccard <antoine.paccard at unine.ch> wrote:
Dear modelers,
I have been trying in the past few months to obtain a variance-
covariance matrix using lmer. I failed multiple times until I decided
to do it under SAS.
Since many people here think your model cannot be fit, but you say it can be fit with SAS, can we please see your SAS command and the output? SAS may be throwing out some parameters from the model automatically, but lmer does not. Just guessing :) PJ
The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336.