library(foreign)
> library(nlme)
> file<-read.spss("file.sav",to.data.frame=TRUE)
> attach(file)
> x <- file$LaggedValue
> y <- file$StockIndex
> default.knots <- function(x,num.knots)
+ {
+ if (missing(num.knots))
+ num.knots <- max(5,min(floor(length(unique(x))/4),35))
+ return(quantile(unique(x),seq(0,1,length=
+ (num.knots+2))[-c(1,(num.knots+2))]))
+ }
> knots<-default.knots(x)
> n <- length(x)
> X <- cbind(rep(1,n),x)
> Z <- outer(x,knots,"-")
> Z <- Z*(Z>0)
> fit <- lme(y~-1+X,random=pdIdent(~-1+Z))
错误于getGroups.data.frame(dataMix, groups) : 
  Invalid formula for groups
> beta.hat <- fit$coef$fixed
错误: 找不到对象'fit'
> u.hat <- unlist(fit$coef$random)
错误于unlist(fit$coef$random) : 找不到对象'fit'
> f.hat <- X%*%beta.hat + Z%*%u.hat
错误: 找不到对象'beta.hat'
> sig.eps.hat <- fit$sigma
错误: 找不到对象'fit'
> sig.u.hat <- sig.eps.hat*exp(unlist(fit$modelStruct))
运行到fit那一栏就不行了,lme()这里面有问题吧,请各位高手帮帮忙