Hello all,

I've run into a problem where I can't run predict.lme on an object simplified via a stepAIC.  A similar post has been recorded on this list:
https://stat.ethz.ch/pipermail/r-help/2008-May/162047.html
but in my case, I'm going to great lengths to not repeat that poster's error and still coming up short.  Any advice would be much appreciated.  It would seem that, after stepAIC, predict.lme cannot find the training data for the lme object (and why is it even needed?).

Here's some example code:

foo = function() {
	x = c(1:20, 1:20)
	y = c(1:20, 5 + (1:20)) + rnorm(40)
	s = c(rep(1, 20), rep(2, 20))

	library(lattice)
	xyplot(y~x|s)

	dframe = data.frame(x, y, s)

	m = lme(y~x, random=~1|s, method='ML')
	
	newdf = data.frame(x=40, s = 2)
	res = predict(m, newdata=newdf)
	print(res)
	
	m2 = stepAIC(m, k=log(nrow(dframe)))
	#res2 = predict(m2, newdata=newdf)
	res2 = eval(substitute(predict(mL, newdata=nL), list(mL=m2, nL=newdf)))
	print(res2)
}

> foo()
       2 
45.86875 
attr(,"label")
[1] "Predicted values"
Start:  AIC=136.4
y ~ x

Error in eval(expr, envir, enclos) : object 'y' not found
	[[alternative HTML version deleted]]

