lme4

Design matrix for MLM from library(lme4) with fixed and random effects

情到浓时终转凉″ 提交于 2019-12-11 09:29:43
问题 Context of application I have a model with random slopes and intercepts. There are numerous levels of the random effects. The new data (to be predicted) may or may not have all of these levels. To make this more concrete, I am working with music revenue at the album level ( title ). Each album may come in multiple types format2 (CD, vinyl, e-audio, etc). I have measurements for revenue for each album at each type of album. The model is specified as: lmer(physical~ format2+ (0+format2|title))

dredge doesn't work when specifying glmer optimizer

☆樱花仙子☆ 提交于 2019-12-11 07:50:50
问题 I am trying to use dredge from the R package MuMIn with a global binomial glmer model. I find that I need to specify the optimizer with control = glmerControl(optimizer="bobyqa") for convergence. However, when I go to use dredge , I get an error. If I reduce the number of predictors in the model, I can remove the bobyqa specification, get convergence, and use dredge. Any way I can get dredge to go with glmerControl(optimizer="bobyqa") ? test.glob=glmer(exploitpark~X + as.factor(Y) + Z + A + B

Get Residual Variance-Covariance Matrix in lme4

半城伤御伤魂 提交于 2019-12-11 06:35:15
问题 I am fitting a linear mixed effects model using lme4 : library(lme4) data(Orthodont) dent <- Orthodont d.test <- lmer(distance ~ age + (1|Subject), data=dent) If we say generically Y = X * B + Z * d + e is the form of a linear mixed effects model, then I am trying to get Var(Y) = Z * Var(d) * Z^t + Var(e) from the results of the model. Is the following formulation the right way to do this? k <- table(dent$Subject)[1] vars <- VarCorr(d.test) v <- as.data.frame(vars) sigma <- attr(vars, "sc") s

How to convert Afex or car ANOVA models to lmer? Observed variables

有些话、适合烂在心里 提交于 2019-12-10 18:24:33
问题 In the afex package we can find this example of ANOVA analysis: data(obk.long, package = "afex") # estimate mixed ANOVA on the full design: # can be written in any of these ways: aov_car(value ~ treatment * gender + Error(id/(phase*hour)), data = obk.long, observed = "gender") aov_4(value ~ treatment * gender + (phase*hour|id), data = obk.long, observed = "gender") aov_ez("id", "value", obk.long, between = c("treatment", "gender"), within = c("phase", "hour"), observed = "gender") My question

How to plot predicted values with standard errors for lmer model results?

纵饮孤独 提交于 2019-12-10 16:09:56
问题 I have a transplant experiment for four locations and four substrates (taken from each location). I have determined survival for each population in each location and substrate combination. This experiment was replicated three times. I have created a lmm as follows: Survival.model <- lmer(Survival ~ Location + Substrate + Location:Substrate + (1|Replicate), data=Transplant.Survival,, REML = TRUE) I would like to use the predict command to extract predictions, for example: Survival.pred <-

lme warning message because of random effects

拜拜、爱过 提交于 2019-12-10 14:04:47
问题 I have a data frame with 5 variables: Lot / Wafer / Serial Number / Voltage / Amplification. In this data frame there are 1020 subsets grouped by Serial_number. Each subset has a certain number of measurement data points (Amplification against voltage). I fit the data with summary(fit2.lme <- lmer(log(log(Amplification)) ~ poly(Voltage, 3) + (poly(Voltage, 1) | Serial_number), + data = APD)) which yields: Linear mixed model fit by REML ['lmerMod'] Formula: log(log(Amplification)) ~ poly

Specified covariance matrix in lmer in R for penalized splines

﹥>﹥吖頭↗ 提交于 2019-12-10 13:26:32
问题 I have been trying to fit a penalized spline regression model in R using the connection between penalized splines and linear mixed models. While I am quite familiar with the R function lme , using its competitor lmer presents some difficulties. Here is a toy example I would like to generalize to lmer : require(nlme) grid <- seq(0, 1, len = 100) y <- rep(0, length(grid)) for(i in 1:length(grid)){ y[i] <- sin(3*pi*grid[i]) + rnorm(1, 0, 1) } X <- cbind(rep(1, length(grid)), grid, grid^2, grid^3

Problems installing Ime4 and ggplot2 on R 2.15.2

北城以北 提交于 2019-12-10 13:26:12
问题 I am having difficulty installing the lme4 and ggplot packages I've tried to install them by selecting a CRAN mirror (have tried several) and then selecting the packages, and have also tried the following; install.packages("lme4",repos="http://r-forge.r-project.org") and install.packages("ggplot2", dependencies=TRUE) but however I try to call these packages I get the warning message package ‘lme4’ is not available (for R version 2.15.2) or package ‘ggplot2’ is not available (for R version 2

How to have multiple groups in Python statsmodels linear mixed effects model?

筅森魡賤 提交于 2019-12-09 06:42:55
问题 I am trying to use the Python statsmodels linear mixed effects model to fit a model that has two random intercepts, e.g. two groups. I cannot figure out how to initialize the model so that I can do this. Here's the example. I have data that looks like the following (taken from here): subject gender scenario attitude frequency F1 F 1 pol 213.3 F1 F 1 inf 204.5 F1 F 2 pol 285.1 F1 F 2 inf 259.7 F1 F 3 pol 203.9 F1 F 3 inf 286.9 F1 F 4 pol 250.8 F1 F 4 inf 276.8 I want to make a linear mixed

How to predict terms of merMod objects (lme4)?

元气小坏坏 提交于 2019-12-08 16:37:53
问题 For simple glm objects, I can use predict(fit, type = "terms") to retrieve a matrix with fitted values for each term. What is the equivalent for lmer resp. glmer fitted models? As far as I can see, the predict.merMod function does not support type = terms . 回答1: What is the equivalent for lmer resp. glmer fitted models? I do not think there is one. Though, you can easily make one as follows ##### # fit model with one terms which is a matrix library(lme4) fit <- lmer(Reaction ~ cbind(Days,