lme4

How to get covariance matrix for random effects (BLUPs/conditional modes) from lme4

☆樱花仙子☆ 提交于 2019-11-29 07:35:15
So, I've fitted a linear mixed model with two random intercepts in R: Y = X beta + Z b + e_i, where b ~ MVN (0, Sigma) ; X and Z are the fixed- and random-effects model matrices respectively, and beta and b are the fixed-effect parameters and random-effects BLUPs/conditional modes. I would like to get my hands on the underlying covariance matrix of b , which doesn't seem to be a trivial thing in lme4 package. You can get only the variances by VarCorr , not the actual correlation matrix. According to one of the package vignettes (page 2), you can calculate the covariance of beta: e_i * lambda *

nlmer longitudinal data

ⅰ亾dé卋堺 提交于 2019-11-29 03:04:06
问题 I've been working with the R Orthodont dataset in the "nlme" package. Just use install.packages("nlme");library(nlme);head(Orthodont) to take a look. The dataset is comprised of distance between the pituitary and the pterygomaxillary fissure measured in 27 children over time. Using the lme4 package I can fit a nonlinear mixed effects model using a logistic curve as my functional form. I can choose to have the asymptote and midpoint entered as random effects nm1 <- nlmer(distance ~ SSlogis(age

unscale and uncenter glmer parameters

时光怂恿深爱的人放手 提交于 2019-11-28 11:27:29
I've been struggling with converting scaled and centered model coefficients from a glmer model back to uncentered and unscaled values. I analysed a dataset using GLMM in the lme4 (v1.1.7) package. It involves the calculation of maximum detection range of acoustic receivers and effect of environmental variables. Sample data: dd <- structure(list(SUR.ID = c(10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L, 10186L,

How to unscale the coefficients from an lmer()-model fitted with a scaled response

删除回忆录丶 提交于 2019-11-28 09:24:11
I fitted a model in R with the lmer() -function from the lme4 package. I scaled the dependent variable: mod <- lmer(scale(Y) ~ X + (X | Z), data = df, REML = FALSE) I look at the fixed-effect coefficients with fixef(mod) : > fixef(mod) (Intercept) X1 X2 X3 X4 0.08577525 -0.16450047 -0.15040043 -0.25380073 0.02350007 It is quite easy to calculate the means by hand from the fixed-effects coefficients. However, I want them to be unscaled and I am unsure how to do this exactly. I am aware that scaling means substracting the mean from every Y and deviding by the standard deviation. But both, mean

Error message in lme4::glmer: “ 'what' must be a character string or a function”

寵の児 提交于 2019-11-28 04:10:01
问题 I am running a multi-level model. I use the following commands with validatedRS6 as the outcome, random as the predictor and clustno as the random effects variable. new<-as.data.frame(read.delim("BABEX.dat", header=TRUE)) install.packages("lme4") library(lme4) model1<- glmer(validatedRS6 ~ random + (1|clustno), data=new, family=binomial("logit"), nAGQ = 1L) However, I get the following error Error in do.call(new, c(list(Class = "glmResp", family = family), ll[setdiff(names(ll), : 'what' must

Convergence error for development version of lme4

断了今生、忘了曾经 提交于 2019-11-28 03:07:01
I am attempting to do a power analysis for a mixed-effects model using the development version of lme4 and this tutorial. I notice in the tutorial that lme4 throws a convergence error: ## Warning: Model failed to converge with max|grad| = 0.00187101 (tol = ## 0.001) The same warning comes up when I run the code for my dataset, with: ## Warning message: In checkConv(attr(opt, "derivs"), opt$par, checkCtrl = control$checkConv, : Model failed to converge with max|grad| = 0.774131 (tol = 0.001) The estimates from a regular glmer call with this updated version are also slightly different from when

In R, plotting random effects from lmer (lme4 package) using qqmath or dotplot: how to make it look fancy?

随声附和 提交于 2019-11-28 02:47:50
The qqmath function makes great caterpillar plots of random effects using the output from the lmer package. That is, qqmath is great at plotting the intercepts from a hierarchical model with their errors around the point estimate. An example of the lmer and qqmath functions are below using the built-in data in the lme4 package called Dyestuff. The code will produce the hierarchical model and a nice plot using the ggmath function. library("lme4") data(package = "lme4") # Dyestuff # a balanced one-way classiï¬cation of Yield # from samples produced from six Batches summary(Dyestuff) # Batch is

Using glmer for logistic regression, how to verify response reference

拜拜、爱过 提交于 2019-11-28 02:40:28
问题 My question is quite simple, but I've been unable to find a clear answer in either R manuals or online searching. Is there a good way to verify what your reference is for the response variable when doing a logistic regression with glmer? I am getting results that consistently run the exact opposite of theory and I think my response variable must be reversed from my intention, but I have been unable to verify. My response variable is coded in 0's and 1's. Thanks! 回答1: You could simulate some

How to get coefficients and their confidence intervals in mixed effects models?

£可爱£侵袭症+ 提交于 2019-11-27 17:32:14
In lm and glm models, I use functions coef and confint to achieve the goal: m = lm(resp ~ 0 + var1 + var1:var2) # var1 categorical, var2 continuous coef(m) confint(m) Now I added random effect to the model - used mixed effects models using lmer function from lme4 package. But then, functions coef and confint do not work any more for me! > mix1 = lmer(resp ~ 0 + var1 + var1:var2 + (1|var3)) # var1, var3 categorical, var2 continuous > coef(mix1) Error in coef(mix1) : unable to align random and fixed effects > confint(mix1) Error: $ operator not defined for this S4 class I tried to google and use

use stepAIC on a list of models

最后都变了- 提交于 2019-11-27 14:33:10
I want to do stepwise regression using AIC on a list of linear models. idea is to use e a list of linear models and then apply stepAIC on each list element. It fails. Hi guys I tried to track the problem down. I think I found the problem. However, I dont understand the cause. Try the code to see the difference between three cases. require(MASS) n<-30 x1<-rnorm(n, mean=0, sd=1) #create rv x1 x2<-rnorm(n, mean=1, sd=1) x3<-rnorm(n, mean=2, sd=1) epsilon<-rnorm(n,mean=0,sd=1) # random error variable dat<-as.data.frame(cbind(x1,x2,x3,epsilon)) # combine to a data frame dat$id<-c(rep(1,10),rep(2,10