[R] lme in R and Splus

Douglas Bates bates at stat.wisc.edu
Wed Sep 3 21:37:58 CEST 2003


Michael Fugate <fugate at lanl.gov> writes:

> ############## BEGINNING OF CODE ###########################
> # a fake dataset to make the bumps with
> nn <- 30  # of data points
> mm <- 7   # number of support sites for x(s)
> # create sites s
> ss <- seq(1,10,length=nn)
> # create the data y
> e1 <- rnorm(nn,sd=0.1)
> e2 <- cos(ss/10*2*pi*4)*.2
> yy <- sin(ss/10*2*pi)+e2+e1
> plot(ss,yy)
> 
> # locations of support points
> ww <- seq(1-2,10+2,length=mm)
> # width of kernel
> sdkern <- 2
> 
> # create the matrix KK
> KK <- matrix(NA,ncol=mm,nrow=nn)
> for(ii in 1:mm){
> KK[,ii] <- dnorm(ss,mean=ww[ii],sd=sdkern)
> }
> 
> # create a dataframe to hold the data
> df1 <- data.frame(y=yy,K=KK,sub=1)
> df1$sub <- as.factor(df1$sub)
> 
> # now fit a mixed model using lme
> a1 <- lme(fixed= y ~ 1,
>           random= pdIdent(~KK-1),
>           data=df1,na.action=na.omit)

You don't have a grouping factor in the random specification and I
can't tell from the simulation what you would expect the groups to be.

> # obtain and plot the fitted values
> a1p <- as.vector(predict(a1,df1))
> lines(ss,a1p,lty=1)
> 
> ##################### END OF CODE ######################################3
> 
> -- 
> *********************************************************************
> | Michael Fugate                         Temp Phone: (505) 665-1817 |
> | Statistical Sciences Group, D-1                                   |
> | Los Alamos National Laboratory         email: fugate at lanl.gov     |
> | Los Alamos, NM 87545                                              |
> | Mail Stop: F600                                                   |
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help

-- 
Douglas Bates                            bates at stat.wisc.edu
Statistics Department                    608/262-2598
University of Wisconsin - Madison        http://www.stat.wisc.edu/~bates/




More information about the R-help mailing list