mixed-models

How do regression models deal with the factor variables?

喜夏-厌秋 提交于 2020-01-13 19:35:10
问题 Suppose I have a data with a factor and response variable. My questions: How linear regression and mixed effect models work with the factor variables? If I have a separate model for each level of the factor variable (m3 and m4) , how does that differ with models m1 and m2 ? Which one is the best model/approach? As an example I use Orthodont data in nlme package. library(nlme) data = Orthodont data2 <- subset(data, Sex=="Male") data3 <- subset(data, Sex=="Female") m1 <- lm (distance ~ age +

glmmLasso error and warning

﹥>﹥吖頭↗ 提交于 2020-01-04 07:55:25
问题 I am trying to perform variable selection in a generalized linear mixed model using glmmLasso, but am coming up with an error and a warning, that I can not resolve. The dataset is unbalanced, with some participants (PTNO) having more samples than others; no missing data. My dependent variable is binary, all other variables (beside the ID variable PTNO) are continous. I suspect something very generic is happening, but obviously fail to see it and have not found any solution in the

glmmLasso error and warning

亡梦爱人 提交于 2020-01-04 07:55:04
问题 I am trying to perform variable selection in a generalized linear mixed model using glmmLasso, but am coming up with an error and a warning, that I can not resolve. The dataset is unbalanced, with some participants (PTNO) having more samples than others; no missing data. My dependent variable is binary, all other variables (beside the ID variable PTNO) are continous. I suspect something very generic is happening, but obviously fail to see it and have not found any solution in the

How can one simulate quantities of interest from the posterior density in MCMCglmm?

旧街凉风 提交于 2020-01-02 19:22:09
问题 I would like to simulate quantities of interest from a model estimated with MCMCglmm more or less the way Zelig package does. In Zelig you can set the values you want for the independent values and software calculates the result for the outcome variable (expected value, probability, etc). An example: # Creating a dataset: set.seed(666) df <- data.frame(y=rnorm(100,20,20),z=rnorm(100,50,70)) # Loading Zelig library(Zelig) # Model m1.zelig <- zelig(y~z, data=df, model="ls") summary(m1.zelig) #

lmer error: grouping factor must be < number of observations

本秂侑毒 提交于 2020-01-02 06:39:31
问题 I am attempting to run a mixed effect model on some data but struggling with one of the fixed effects, I think primarily due to it a factor?! Sample data: data4<-structure(list(code = structure(1:10, .Label = c("10888", "10889", "10890", "10891", "10892", "10893", "10894", "10896", "10897", "10898", "10899", "10900", "10901", "10902", "10903", "10904", "10905", "10906", "10907", "10908", "10909", "10910", "10914", "10916", "10917", "10919", "10920", "10922", "10923", "10924", "10925", "10927"

How to predict and graph non-linear varying slopes in lmer or glmer?

≡放荡痞女 提交于 2020-01-01 05:48:05
问题 My goal is to calculate predicted values from a varying-intercept, varying-slope multilevel model using the lmer and glmer functions of the lme4 package in R. To make this concrete and clear, I present here a toy example with the "mtcars" data set: Here's how I usually create predicted values from a varying-intercept, varying-slope multilevel model (this code should work just fine): # loading in-built cars dataset data(mtcars) # the "gear" column will be the group-level factor, so we'll have

How to compare a model with no random effects to a model with a random effect using lme4?

五迷三道 提交于 2019-12-31 09:16:16
问题 I can use gls() from the nlme package to build mod1 with no random effects. I can then compare mod1 using AIC to mod2 built using lme() which does include a random effect. mod1 = gls(response ~ fixed1 + fixed2, method="REML", data) mod2 = lme(response ~ fixed1 + fixed2, random = ~1 | random1, method="REML",data) AIC(mod1,mod2) Is there something similar to gls() for the lme4 package which would allow me to build mod3 with no random effects and compare it to mod4 built using lmer() which does

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

R- analyzing repeated measures unbalanced design with lme4?

旧街凉风 提交于 2019-12-25 09:16:31
问题 For my experiment, I clipped plants and measured their responses, such as leaf mass produced, at the end of the season. I manipulated both clipping intensity and clipping time and crossed these two treatments. I also included a control clipped treatment resulting in 5 different clipping treatment combinations. With 12 plants per treatment there is a total of 60 plants which I followed over the course of two years. That is, I collected measurements on these 60 plants in year 1 and the same

Getting p-values for all included parameters using glmmLasso

南楼画角 提交于 2019-12-25 07:13:43
问题 I am fitting a mixed model using glmmLasso in R using the command: glmmLasso(fix = Activity ~ Novelty + Valence + ROI + Novelty:Valence + Novelty:ROI + Valence:ROI + Novelty:Valence:ROI, rnd = list(Subject = ~1), data = KNov, lambda = 195, switch.NR = F, final.re = TRUE) To give you a sense of the data, the output of head(KNov) is: Subject Activity ROI Novelty Valence Side STAIt 1 202 -0.4312944 H N E L -0.2993321 2 202 -0.6742497 H N N L -0.2993321 3 202 -1.0914216 H R E L -0.2993321 4 202