Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up VarCorr #173

Open
pitakakariki opened this issue Jan 16, 2020 · 11 comments
Open

Fix up VarCorr #173

pitakakariki opened this issue Jan 16, 2020 · 11 comments

Comments

@pitakakariki
Copy link
Owner

Pivoting bug. Look at safe_chol in lme4 codebase?

@pitakakariki
Copy link
Owner Author

Add lots of tests and maybe error in VarCorr<- if VarCorr doesn't match afterwards.

@pitakakariki
Copy link
Owner Author

> V2
          [,1]      [,2]      [,3]
[1,] 0.1583598 0.1166801 0.1761762
[2,] 0.1166801 0.3506677 0.2832665
[3,] 0.1761762 0.2832665 0.3423178
> model <- makeLmer(y ~ x + x2 + (x + x2|g),
+                   fixef=b, VarCorr=V2,
+                   sigma=s, data=X)
> print(model)
Linear mixed model fit by REML ['lmerMod']
Formula: y ~ x + x2 + (x + x2 | g)
   Data: X
REML criterion at convergence: 6108.123
Random effects:
 Groups   Name        Std.Dev. Corr     
 g        (Intercept) 0.3457           
          x           0.5922   0.00     
          x2          0.5851   0.40 0.82
 Residual             1.1076           
Number of obs: 1920, groups:  g, 32
Fixed Effects:
(Intercept)            x           x2 
    -0.0166       0.1216       0.1942

@pitakakariki
Copy link
Owner Author

While you're at it make some more documentation for VarCorr.

@pitakakariki
Copy link
Owner Author

Note that VarCorr<- can also update sigma so that should be properly documented.

@hulahoopmagic
Copy link

Hi, I was wondering whether there is still a bug in how makeLmer uses the variance-covariance matrix?
In the example you posted above, I don't feel like the variances and covariances in V2 correspond to the variances and covariances in model? For instance, shouldn't be the value of the first column and first row (0.1583598) be the squared standard deviation of the by-g random intercept (and hence be 0.1195085)? Further, the value of the second column and first row and first column and second row (0.1166801) should be zero if there is indeed a correlation of zero of the by-g random intercept and by-g random slope of x, right?

@pitakakariki
Copy link
Owner Author

Yes, the 30 April post is an example of the bug. Still working out how to fix it, but I have some workarounds if you're being affected by the bug.

@hulahoopmagic
Copy link

Ah I see! Yes, it seems like I am affected by this bug. I tried to figure out what’s wrong with my variance-covariance matrix, but probably it’s nothing wrong with it :)
Hence, I am very interested in your workarounds!

@pitakakariki
Copy link
Owner Author

Where did yours come from? Is it from a previously fit lme4 model, or have you specified it by hand?

@hulahoopmagic
Copy link

hulahoopmagic commented Jul 12, 2021

I actually tried both, one that I made up and another one that I extracted from a lme4 model :)

@pitakakariki
Copy link
Owner Author

If you already have one in another model, that's the easiest option because you can just copy the theta parameter across:

newmodel@theta <- oldmodel@theta

If your variance-covariance matrix V is positive-definite then this should work too:

newmodel@theta <- t(chol(V))[lower.tri(V, diag=TRUE)]

@hulahoopmagic
Copy link

Wow, cool! Thanks so much, that works just fine :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants