user5594581
user5594581

Reputation:

Predict with gls

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?

Upvotes: 0

Views: 1586

Answers (1)

user5594581
user5594581

Reputation:

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.

Upvotes: 1

Related Questions