0

I'm learning how to predict with gls but I keep getting an error when I try to do that. Here's the code I'm using.

data("airquality")
airquality$Date=as.Date(paste(1973,airquality$Month,airquality$Day,sep="-"))
air1<-subset(airquality,complete.cases(Ozone))
library(nlme)
model1=gls(Ozone~Wind*Date,air1,correlation=corAR1())

This works fine so far. Now, I would like to predict the Ozone for a specific Wind Speed on a specific Date. So I use.

newdata<-data.frame(Wind=10,Date="1973-05-04")
newdata$Date<-as.Date(newdata$Date)
predict(model1,newdata)

The last code line gives me the following error:

Error in eval(expr, envir, enclos) : object 'Ozone' not found

I then tried the following code to predict:

predict.gls(model1,newdata)

This is the error I'm getting although the nlme library was included.

Error: could not find function "predict.gls"

Can anyone advise why these errors are coming up? Also, what would be the right way code to use here to make the prediction?

  • what is `Date` in the `gls` call ? How did you defined it ? – etienne Nov 23 '15 at 10:08
  • I just added that line of code I used. It's the second line now. –  Nov 23 '15 at 10:15
  • I haven't got the error. it returns 35.37236. Are all of your packages up-to-date ? – etienne Nov 23 '15 at 10:19
  • Ya, I had just installed them. I tried restarting RStudio and now the first generic predict works but I get the same error as above when using the predict.gls function. Any idea why? –  Nov 23 '15 at 10:27
  • 2
    For the `predict.gls` error I don't know, it's the same for me. But as `predict` works I guess you don't need to use the `.gls` extension. – etienne Nov 23 '15 at 10:31

1 Answers1

1

After researching the topic further, I realized that predict.gls is not a function in itself but rather used in the help files to identify and explain the arguments necessary to pass along with a gls object to the predict function.