Home > OS >  Modelling time series data from multiple cities (one week period)
Modelling time series data from multiple cities (one week period)

Time:08-17

I am trying to model temperature data from my df which contains 4 different cities, i initially want to fit a model to model the temperature for 1 of my locations. Initially i want to fit a model to predict for High Wycombe but I'm not sure how to do this whilst keeping the data for each location. Is this something that is possible or do i need to split the data up further before doing this and model separately? For example I initially done this although want able to get my predicions and plot working;

dat_hw = c(15.4, 15.5,  9.8, 10.1, 11.7, 10.0, 14.1)
hw_ts = ts(dat_hw, frequency = 365, start = c(2020, 305))

mod = auto.arima(hw_ts)

preds = predict(mod)

plot(preds$pred)

In an ideal world i would be able to model all of my data and then jst predict for each individual location if possible

overall data

Date           Machrihanish High_Wycombe Camborne Dun_Fell
1 20201101         11.8         15.4     15       10.4
2 20201102         11.1         15.5     15       10.5
3 20201103         9.7          9.8      10.5     2.2
4 20201104         11           10.1     11.6     3.3
5 20201105         11.7         11.7     11.6     9.7
6 20201106         11.3         10       13.1     10.4
7 20201107         10           14.1     14.4     11.9

CodePudding user response:

You could wrap your prediction code in a function, and apply it to each column:

f <- function(d) {
  hw_ts = ts(d, frequency = 365, start = c(2020, 305))
  mod = auto.arima(hw_ts)
  predict(mod)
}
predictions = apply(data[,-(1:2)],2,f)
  • Related