0

Does anyone know how to extract the parameter estimates of random term when using the (1 | …) syntax in a glmer model (including se, t ratio and p value)? I’m only able to access the average variance and std. deviance with the summary function.

Some background: I used cohort and period random terms (both factorized), where period = each survey year, and cohort = 8 birth cohorts. My model empty model looks like this : glmer(pid ~ age + age2 + (1 | cohort) + (1| period)

andreafg
  • 1
  • 1

1 Answers1

1

There's a bit of a conceptual problem with what you are doing. The random effects do not have the same standing in statistical theory as the fixed effects. You are not really supposed to be making inferences on their estimates since you don't have a random sampling from their overall population. Hence you need to make some unteseted assumptions on their distribution. That said, there are apparently times when you might want to do it but with care that you are not making unsupportable claims. See: https://stats.stackexchange.com/questions/392314/interpretation-of-fixed-effect-coefficients-from-glms-and-glmms .

Dimitris Rizopoulosthen responded to a request for the possibility of getting "an average" of the random effects conditional on the fixed effects (rather the flipped version of mixed models inference). He offered a function in his GLMM package:

https://drizopoulos.github.io/GLMMadaptive/articles/Methods_MixMod.html#marginalized-coefficients

This is his example ......

install.packages("GLMMadaptive"); library(GLMMadaptive)
set.seed(1234)
n <- 100 # number of subjects
K <- 8 # number of measurements per subject
t_max <- 15 # maximum follow-up time

# we constuct a data frame with the design: 
# everyone has a baseline measurment, and then measurements at random follow-up times
DF <- data.frame(id = rep(seq_len(n), each = K),
                 time = c(replicate(n, c(0, sort(runif(K - 1, 0, t_max))))),
                 sex = rep(gl(2, n/2, labels = c("male", "female")), each = K))

# design matrices for the fixed and random effects
X <- model.matrix(~ sex * time, data = DF)
Z <- model.matrix(~ time, data = DF)

betas <- c(-2.13, -0.25, 0.24, -0.05) # fixed effects coefficients
D11 <- 0.48 # variance of random intercepts
D22 <- 0.1 # variance of random slopes

# we simulate random effects
b <- cbind(rnorm(n, sd = sqrt(D11)), rnorm(n, sd = sqrt(D22)))
# linear predictor
eta_y <- as.vector(X %*% betas + rowSums(Z * b[DF$id, ]))
# we simulate binary longitudinal data
DF$y <- rbinom(n * K, 1, plogis(eta_y))
#We continue by fitting the mixed effects logistic regression for y assuming random intercepts and random slopes for the random-effects part.

fm <- mixed_model(fixed = y ~ sex * time, random = ~ time | id, data = DF,
                  family = binomial())

.... and then the call to his marginal_coefs function.

marginal_coefs(fm, std_errors=TRUE)
               Estimate Std.Err z-value   p-value
(Intercept)     -1.6025  0.2906 -5.5154   < 1e-04
sexfemale       -1.0975  0.3676 -2.9859 0.0028277
time             0.1766  0.0337  5.2346   < 1e-04
sexfemale:time   0.0508  0.0366  1.3864 0.1656167
IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • Thank you for your input! I'm simply following the steps from Ylang and Land (2016) book "Age-Period-Cohort Analysis : New Models, Methods, and Empirical Applications", where they show the t ratio of each cohort and their p-value, then I try to find the explained variance from the random effects (each cohort instead of cohorts as a whole). – andreafg Dec 06 '21 at 17:59
  • You misspelled the first author's name. It's Yang and Land.The book is available online. https://www.taylorfrancis.com/books/oa-mono/10.1201/b13902/age-period-cohort-analysis-yang-yang-kenneth-land . If you want R code for a particular section of the book then you should specify chapter and section since the book is made available for download. – IRTFM Dec 06 '21 at 18:24