SE for all levels of a factor after a glmm
When you are doing a LM, GLM or GLMM with fixed effect with categorical variable, it is impossible to get the SE for all levels because always one level is fixed to 0. But sometimes, you need to know how this level is really known.
Two solutions are presented for this problem.
The first solution is to force the intercept to be 0 but it works only when there is only one categorical fixed factor. The second is to use a method know as quasi-variance:
Firth, D., de Mezezes, R.X., 2004. Quasi-variances. Biometrika 91, 65-80.
x <- rnorm(100)
y <- rnorm(100)
G <- as.factor(sample(c("A", "B", "C", "D"), 100, replace = TRUE))
H <- as.factor(sample(c("A", "B", "C", "D"), 100, replace = TRUE))
R <- as.factor(rep(1:25, 4))
G <- relevel(G, "A")
H <- relevel(H, "A")
library(lme4)
# No SE for GA
m <- lmer(y ~ x + G + (1 | R))
summary(m)$coefficients
# SE for GA but not for (intercept)
m <- lmer(y ~ x + G + 0 + (1 | R))
summary(m)$coefficients
# SE for both GA and (intercept)
library(HelpersMG)
install.packages("https://hebergement.universite-paris-saclay.fr/marcgirondot/CRAN/HelpersMG.tar.gz", repos=NULL, type="source")
m <- lmer(y ~ x + G + (1 | R))
qvlmer(m, factorname="G")
library(lme4)
# No SE for GA and HA
m <- lmer(y ~ x + G + H + (1 | R))
summary(m)$coefficients
# SE for GA but not for HA and (intercept)
m <- lmer(y ~ x + G + H + 0 + (1 | R))
summary(m)$coefficients
# SE for GA, HA, and (intercept)
library(HelpersMG)
install.packages("https://hebergement.universite-paris-saclay.fr/marcgirondot/CRAN/HelpersMG.tar.gz", repos=NULL, type="source")
m <- lmer(y ~ x + G + H + (1 | R))
qvlmer(m, factorname="G")
qvlmer(m, factorname="H")
Two solutions are presented for this problem.
The first solution is to force the intercept to be 0 but it works only when there is only one categorical fixed factor. The second is to use a method know as quasi-variance:
Firth, D., de Mezezes, R.X., 2004. Quasi-variances. Biometrika 91, 65-80.
It is available in package qvcalc for lm() and glm() and in package HelpersMG for lmer().
Here is an example with lmer():
x <- rnorm(100)
y <- rnorm(100)
G <- as.factor(sample(c("A", "B", "C", "D"), 100, replace = TRUE))
H <- as.factor(sample(c("A", "B", "C", "D"), 100, replace = TRUE))
R <- as.factor(rep(1:25, 4))
G <- relevel(G, "A")
H <- relevel(H, "A")
library(lme4)
# No SE for GA
m <- lmer(y ~ x + G + (1 | R))
summary(m)$coefficients
# SE for GA but not for (intercept)
m <- lmer(y ~ x + G + 0 + (1 | R))
summary(m)$coefficients
# SE for both GA and (intercept)
library(HelpersMG)
install.packages("https://hebergement.universite-paris-saclay.fr/marcgirondot/CRAN/HelpersMG.tar.gz", repos=NULL, type="source")
m <- lmer(y ~ x + G + (1 | R))
qvlmer(m, factorname="G")
library(lme4)
# No SE for GA and HA
m <- lmer(y ~ x + G + H + (1 | R))
summary(m)$coefficients
# SE for GA but not for HA and (intercept)
m <- lmer(y ~ x + G + H + 0 + (1 | R))
summary(m)$coefficients
# SE for GA, HA, and (intercept)
library(HelpersMG)
install.packages("https://hebergement.universite-paris-saclay.fr/marcgirondot/CRAN/HelpersMG.tar.gz", repos=NULL, type="source")
m <- lmer(y ~ x + G + H + (1 | R))
qvlmer(m, factorname="G")
qvlmer(m, factorname="H")
Commentaires
Enregistrer un commentaire