r - lme4 random effect structure with dredge -
i have constructed lme4
model model selection in dredge
having trouble aligning random effects relevant fixed effects.the structure of full model follows.
fullmodel<-glmer(y ~x1 + x2 + (0+x1|year) + (0+x1|country) + (0+x2|year) + (0+x2|country) + (1 | year) +(1|country), family=binomial('logit'),data = alldata)
in model structure, model selection in dredge
produces 3 combinations of fixed effects, i.e. x1, x2, , x1+x2, random effect structure remains same in full model, such when fixed effect x1, random effect include (0+x2|year) + (0+x2|country)
. example model x1 fixed effect, still have x2 within random effects structure follows.
y ~x1 + (0+x1|year) + (0+x1|country) + (0+x2|year) +(0+x2|country) + (1 | year) +(1|country), family=binomial('logit')
is there way configure dredge
not select random effects have other fixed effects specified in them? have x1….x50.
you cannot out-of-box dredge
omits (x|g)
expressions, can make "wrapper" around (g
)lmer
replaces "|" terms in formula else (e.g. re(x,g)
), dredge
thinks these fixed effects. example:
glmerwrap <- function(formula) { cl <- origcall <- match.call() cl[[1l]] <- as.name("glmer") # replace 'lmerwrap' 'glmer' # replace "re" "|" in formula: f <- as.formula(do.call("substitute", list(formula, list(re = as.name("|"))))) environment(f) <- environment(formula) cl$formula <- f x <- eval.parent(cl) # evaluate modified call # store original call , formula in result: x@call <- origcall attr(x@frame, "formula") <- formula x } formals(glmerwrap) <- formals(lme4::glmer)
following example(glmer)
:
# note use of re(x,group) instead of (x|group) (fm <- glmerwrap(cbind(incidence, size - incidence) ~ period + re(1, herd) + re(1, obs), family = binomial, data = cbpp))
now,
dredge(fm)
manipulates both fixed , random effects.
Comments
Post a Comment