I need to extract the posterior SE estimates my each fixed effect from my model.
For illustrative purposes, a similar dataset to the one I am using would be the ChickWeight
dataset in base R
.
The way I extract the posterior estimates and intervals for my fixed effects is like so:
#load package
library(lme4)
#model
m.surv<-lmer(weight ~ Time + Diet + (1|Chick), data=ChickWeight)
#load packages
library(MCMCglmm)
library(arm)
#set up for fixed effects
sm.surv<-sim(m.surv)
smfixef.surv=sm.surv@fixef
smfixef.surv=as.mcmc(smfixef.surv)
#which gives
> posterior.mode(smfixef.surv)
(Intercept) Time Diet2 ...
8.5963329 8.7034260 5.1220436 ...
> HPDinterval(smfixef.surv)
lower upper
(Intercept) -0.90309142 21.3617805
Time 8.42279728 9.0306337
Diet2 -6.84371527 35.1745980
...
attr(,"Probability")
[1] 0.95
>
Any suggestions on how I can modify my code to extract the SEs for the fixed effects (Time
and Diet2
)?
You might want to extract them from the summary statistics of smfixef.surv
.
s <- summary(smfixef.surv)$statistics
s[grep("Time|Diet", rownames(s)), grep("SE", colnames(s))]
# Naive SE Time-series SE
# Time 0.02046371 0.02046371
# Diet2 0.96785150 0.96785150
# Diet3 1.02553234 1.02553234
# Diet4 1.07393122 1.66512213