random-effects

how to allow for factor-specific variance of random effect in lme

吃可爱长大的小学妹 提交于 2020-01-21 05:06:24
问题 I assume that the random effects variances in my mixed effect model will be different for different levels of the fixed factor BTyp . Here is my model fm2 <- lme(CA ~ 1 + pF+Tiefe+BTyp+Tiefe:pF+BTyp:pF, data=data2, random = list(~ 1 + pF|Probe)) fm2_Btyphet<-update(fm2, weights=varIdent(form=~1|BTyp)) I managed to incorporate Btyp -specific variances for random effects using lmer function, but this function does not allow to consider variance heterogeneity of the within group error (which is

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

核能气质少年 提交于 2019-12-28 04:49:22
问题 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

How to plot random intercept and slope in a mixed model with multiple predictors?

跟風遠走 提交于 2019-12-21 02:43:07
问题 Is it possible to plot the random intercept or slope of a mixed model when it has more than one predictor? With one predictor I would do like this: #generate one response, two predictors and one factor (random effect) resp<-runif(100,1, 100) pred1<-c(resp[1:50]+rnorm(50, -10, 10),resp[1:50]+rnorm(50, 20, 5)) pred2<-resp+rnorm(100, -10, 10) RF1<-gl(2, 50) #gamm library(mgcv) mod<-gamm(resp ~ pred1, random=list(RF1=~1)) plot(pred1, resp, type="n") for (i in ranef(mod$lme)[[1]]) { abline(fixef

How does lmer (from the R package lme4) compute log likelihood?

这一生的挚爱 提交于 2019-12-20 10:08:03
问题 I'm trying to understand the function lmer. I've found plenty of information about how to use the command, but not much about what it's actually doing (save for some cryptic comments here: http://www.bioconductor.org/help/course-materials/2008/PHSIntro/lme4Intro-handout-6.pdf). I'm playing with the following simple example: library(data.table) library(lme4) options(digits=15) n<-1000 m<-100 data<-data.table(id=sample(1:m,n,replace=T),key="id") b<-rnorm(m) data$y<-rand[data$id]+rnorm(n)*0.1

Random effects estimation error with plm package due to negative variance

筅森魡賤 提交于 2019-12-11 08:55:32
问题 I'm trying to estimate a panel data model with random effects Swamy and Ahora transformation on market share data of tourism destinations. Please, find attached the dataset in https://github.com/Joseperles/Statistical-questions The model is estimated according the following code: random<-plm(ld_Share~ld_Gdp+ld_Gdppc+ld_Gkf+ld_Cpi+ld_Fdi+ld_Exrate, data=Panel, index=c("Country", "obs"), model="random") However I get this error message: Error in swar(object, data, effect) : the estimated

individual random effects model with standard errors clustered on a different variable in R (R-project)

大兔子大兔子 提交于 2019-12-09 19:06:26
问题 I'm currently working on some data from an experiment. Thus, I have data about some individuals who are randomly assigned to 2 different treatments. For each treatment, we ran three sessions. In each session, participants were asked to make a sequence of decisions. What I would like to do is to: (1) estimate the effect of the treatment with a model that includes random effects on individuals and afterwards, (2) clustering the standard errors by session. In R, I can easily estimate the random

Prediction with lme4 on new levels

﹥>﹥吖頭↗ 提交于 2019-12-04 21:09:05
问题 I'm trying to fit a mixed effects model and then use that model to generate estimates on a new dataset that may have different levels. I expected that the estimates on a new dataset would use the mean value of the estimated parameters, but that doesn't seem to be the case. Here's a minimum working example: library(lme4) d = data.frame(x = rep(1:10, times = 3), y = NA, grp = rep(1:3, each = 10)) d$y[d$grp == 1] = 1:10 + rnorm(10) d$y[d$grp == 2] = 1:10 * 1.5 + rnorm(10) d$y[d$grp == 3] = 1:10

How to plot random intercept and slope in a mixed model with multiple predictors?

[亡魂溺海] 提交于 2019-12-03 07:38:50
Is it possible to plot the random intercept or slope of a mixed model when it has more than one predictor? With one predictor I would do like this: #generate one response, two predictors and one factor (random effect) resp<-runif(100,1, 100) pred1<-c(resp[1:50]+rnorm(50, -10, 10),resp[1:50]+rnorm(50, 20, 5)) pred2<-resp+rnorm(100, -10, 10) RF1<-gl(2, 50) #gamm library(mgcv) mod<-gamm(resp ~ pred1, random=list(RF1=~1)) plot(pred1, resp, type="n") for (i in ranef(mod$lme)[[1]]) { abline(fixef(mod$lme)[1]+i, fixef(mod$lme)[2]) } #lmer library(lme4) mod<-lmer(resp ~ pred1 + (1|RF1)) plot(pred1,