[R] lme4 and lmeSplines

From: Kevin Wright <kwright68_at_gmail.com>
Date: Thu 03 Aug 2006 - 05:25:20 EST

I'm trying to use the lmeSplines package together with lme4.

Below is (1) an example of lmeSplines together with nlme (2) an attempt to use lmeSplines with lme4 (3) then a comparison of the random effects from the two different methods.


dat <- smSplineEx1
dat.lo <- loess(y~time, data=dat)
dat$all <- rep(1,nrow(dat))
times20 <- seq(1,100,length=20)
Zt20 <- smspline(times20)
dat$Zt20 <- approx.Z(Zt20, times20, dat$time) fit1.20 <- lme(y~time, data=dat, random=list(all=pdIdent(~Zt20-1)))
# Loess model

dat.lo <- loess(y~time, data=dat)
# Spline model

with(dat, lines(fitted(fit1.20)~time, col="red"))
# Save random effects for later

ranef.nlme <- unlist(ranef(fit1.20))

(2) Now an attempt to use lme4:

# Use 20 spline in lme4

dat <- smSplineEx1
times20 <- seq(1,100,length=20)
Zt20 <- smspline(times20)
dat <- cbind(dat, approx.Z(Zt20, times20, dat$time)) names(dat)[4:21] <- paste("Zt",names(dat)[4:21],sep="") dat$all <- rep(1, nrow(dat))
fit1.20 <- lmer(y~time


# Plot the data and loess fit

dat.lo <- loess(y~time, data=dat)
# Fitting with splines

with(dat, lines(fitted(fit1.20)~time, col="red")) ranef.lme4 <- unlist(ranef(fit1.20))

(3) Compare nlme lme4 random effects


The plot of fitted values from lme4 is visually appealing, but the random effects from lme4 are peculiar--three are non-zero and the rest are essentially zero.

Any help in getting lme4 + lmeSplines working would be appreciated. It is not unlikely that I have the lmer syntax wrong.

Kevin Wright

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu Aug 03 05:30:46 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 10 Aug 2006 - 06:21:08 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.