Random effect and variance-covariance matrix of random effect with lme4 package are extracted as following:
library(lme4)
fm1 <- lmer(Reaction ~ Days + (1|Subject), sleepstudy)
fm1.rr <- ranef(fm1,condVar=TRUE)
fm1.pv <- attr(rr[[1]],"postVar")
I wonder how I can do this with mgcv? 'gam.vcomp' function does extract the estimated variance components, but not for each level of random effect.
library(mgcv)
fm2 <- gam(Reaction ~ Days + s (Subject, bs="re"), data = sleepstudy, method = "REML")
gam.vcomp(fm2)
mgcv::random.effects()
ornlme::ranef()
do what you need? Must admit I'm less familiar withmgcv
. If not can you post a small sample of your data, perhaps withdput()
? See stackoverflow.com/questions/5963269/… for help – PhilSubject
. @Phil: The questioner loaded the data into his workspace because it is in hte lme4 package. You need to execute:data(sleepstudy, package="lme4")
if you didn't run the first bit of code. You will also need to usedata=sleepstudy
, sincegam
's second argument is notdata
. – IRTFMSubject
, i.e. 18 random effects and 18 variances. Inmgcv
I get only 1 estimate around the spline. Basically I want to get same output withmgcv
as it is produced bylme4
. Am I missing something? The reason I want to usemgcv
is because my real model contains a few other types of splines as well as random effects. – olyashevska