3
$\begingroup$

I'm currently trying to do power calculation using SIMR package in R. To start off, I first created the following model which defines my study design with simulated output y:

model1 <- glmer(y ~ (a*b) +
                        (1 + (a*b)|subj), family="binomial",
                        data = simulated.df, 
                        control = glmerControl(optCtrl = list(maxfun = 1e+9)))

I would now like to adjust the variance-covariance matrix of this model based on my pilot data. The varcorr matrix of my pilot data is as follows:

#> VarCorr(m_pilot)
  #Groups   Name             Std.Dev. Corr                
  #subj     (Intercept)      0.11582                      
  #a1                        0.12624  -0.254              
  #b1                        0.12239  -0.080  0.563       
  #a1:b1                     0.10523   0.267 -0.600 -0.337

How can I change the varcorr matrix of my stimulated model (model1) to the varcor matrix from my pilot data?

I would be very grateful for any help.

Maria

$\endgroup$
1
  • 1
    $\begingroup$ R code questions might be better received on the r-sig-mixed-models mailing list. $\endgroup$
    – mdewey
    Commented Apr 29, 2018 at 16:08

2 Answers 2

1
$\begingroup$

In general the simr package takes a fitted model as input, so I'm not quite sure why you don't just pass m_pilot to doSim() ...

More generally, the covariance matrices in lme4 are parameterized as the (scaled) Cholesky factor. That is, suppose you have a fitted model m. Then you can get the parameters expected by [g]lmer (or by the simulate.formula method in lme4) directly via getME(m, "theta"), or — if you have the covariance matrix (e.g. vc <- VarCorr(m)[[1]]), then

cc <- chol(vc)
cc2 <- c(t(cc)[lower.tri(cc, diag = TRUE)])

will get the unscaled Cholesky factor, and cc2/sigma(m) will get the scaled Cholesky factor (sigma(m) is 1 for binomial and Poisson models)

$\endgroup$
0
$\begingroup$

You should be able to copy the variance-covariance matrix from one model to the other with:

VarCorr(model1) <- VarCorr(m_pilot)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.