[R-sig-ME] bivariate response mixed model using lme4 and residual (co)variances
Ben Bolker
bbolker at gmail.com
Wed Sep 21 04:03:41 CEST 2011
Ned Dochtermann <ned.dochtermann at ...> writes:
>
> All,
>
> I am attempting to "cheat" with lme4 to calculate the correlation between
> two traits--y & z--measured repeatedly (simulation data actually) for
> individuals by use of dummy variables. I can calculate the
> between-individual variances and covariances with the data structured as:
>
> ind y_rand z_rand yz
> A 1 0 -1.941248639
> A 1 0 0.747675528
> B 1 0 2.502358777
> B 1 0 2.752530485
[snip]
> and then fitting the following model:
>
> yz.mm<-lmer(yz~-1+y_rand+z_rand+(y_rand+z_rand-1|ind),data=ind.data)
>
> This gives seemingly correct results (i.e. consistent with results from
> MCMCglmm and ASReml) for the between-individual estimates. The issue that
> I'm running into is that since I'm treating y and z as the same variable, I
> can't figure out how to get any sort of within-individual estimates beyond a
> single variance estimate. This makes sense given the way I've formulated the
> model.
>
> Is there any way to likewise cheat to get within-individual/group variance
> and covariance estimates with lme4? I can get what I need from MCMCglmm but,
> for computational reasons I'd prefer lme4.
>
> Thanks for any help,
> Ned
>
> p.s. just realized that I can probably get what I want from lme...
>
Maybe displaying my ignorance, but is there a particular reason
to use dummy variables instead of a factor? That is, if I start with
ind y z
A 1.2 2.4
A 1.3 2.1
B 2.1 3.2
B 2.3 4.6
...
and then use melt(data,id.var=1) from reshape I get data that look like
ind variable value
A y 1.2
A z 2.4
A y 1.3
A z 2.1
....
and then
lmer(value~variable-1+(variable-1|ind),data=ind.data) ?
it seems you could also add an "obs" variable to the original
data frame, use it as an id var as well, and be able to get a
correlation among observations taken at the same time within
the same individual ...
More information about the R-sig-mixed-models
mailing list