I aim to model the temperature variations in two locations in America, example below:
set.seed(10)
RandData <- runif(8760*2)
America <- rep(c('NewYork','Miami'),each=8760)
Date = seq(from=as.POSIXct("1991-01-01 00:00"),
to=as.POSIXct("1991-12-31 23:00"), length=8760)
DatNew <- data.frame(Loc = America,
Doy = as.numeric(format(Date,format = "%j")),
Tod = as.numeric(format(Date,format = "%H")),
Temp = RandData)
require(mgcv)
mod1 <- gam(Temp ~ Loc + s(Doy) + s(Doy,by = Loc) +
s(Tod) + s(Tod,by = Loc),data = DatNew)
plot(mod1,pages = 1, scale = 0)
Instead of having an output showing the component smooth functions that make up the gam I would like to plot the model output on the original x and y axis i.e. show the temperatures on the y axis. When modelling 1 location I would use something along the lines of:
pred <- data.frame(Doy = DatNew$Doy)
pred <- transform(pred, yhat = predict(mod1, newdata = pred))
However, I do not know how to achieve this if I have several locations i.e. the model depends on the location not solely on the day of year/time of day.
How can this be achieved?