The following code evaluates the similarity between two time series:
set.seed(10)
RandData <- rnorm(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,
DecTime = rep(seq(1, length(RandData)/2) / (length(RandData)/2),
2))
require(mgcv)
mod1 <- gam(Temp ~ Loc + s(Doy) + s(Doy,by = Loc) +
s(Tod) + s(Tod,by = Loc),data = DatNew, method = "ML")
Here, gam
is used to evaluate how the temperature at New York and Miami vary from the mean temperature (of both locations) at different times of the day. The problem that I now have is that I need to include an interaction term which shows how the temperature of each location varies throughout at the day for different days of the year. I eventually hope to display all of this information on one graph (for each location). So, for Miami I hope to have one graph that shows how the temperature varies from the mean during different times of the day and different times of the year (3d plot?)