[R-sig-ME] mixed-ish model
David Stevens
david.stevens at usu.edu
Wed Jan 21 22:35:26 CET 2015
I have a mixed-effects model problem in which y ~ x|s where s is a
random effect and x is a fixed effect. s has three levels (0,1,2) and
I'm looking for a lmer(...) solution to the case where if s == c(1,2),
the slope is the same but the intercept is different. If s == 0, slope
and intercept are different.
lmer(y~x + (1+x|s)) yields three slopes and three intercepts
If I define s2 = 0 for s = 0 and s2 = 1 for s %in% (1,2)
lmer(y~x + (1+x|s2)) yields two slopes and two intercepts
I can brute force this using categorical variables and lm(...) , but I
was hoping for a more R-ish way. Any thoughts or pointers?
Here are the data
# ... x
x <- c(190,110,150,170,170,170,200,140,140,160,140,110,110,120,110,110,110)
x <- c(x,140,140,120,190,120,110,110,100,100,120,120,100,80,100)
x <- c(x,580,640,500,530,670,670,640,0640,560,590,640,590,600)
# ... y
y <-
c(5.96,6.08,5.93,5.99,6.01,5.97,5.88,6.06,6.06,6.03,6.02,6.17,6.31,6.27,6.42,6.28,6.43)
y <-
c(y,6.33,6.43,6.37,6.09,6.32,6.37,6.73,6.89,6.87,6.3,6.52,6.39,6.87,6.85)
y <- c(y,5.82,5.94,5.73,5.91,5.87,5.8,5.8,5.78,5.78,5.73,5.63,5.79,6.02)
# ... s
s <- as.factor(c(rep(1,17),rep(2,14),rep(0,13)))
y.df = data.frame(x=x,y=y,s=s)
y.df$s2 <- as.factor(1 - as.numeric( !(y.df$s %in% c(1,2))))
Thanks
David
--
David K Stevens, P.E., Ph.D.
Professor and Head, Environmental Engineering
Civil and Environmental Engineering
Utah Water Research Laboratory
8200 Old Main Hill
Logan, UT 84322-8200
435 797 3229 - voice
435 797 1363 - fax
david.stevens at usu.edu
More information about the R-sig-mixed-models
mailing list