0

Could anyone provides me guidance on how to use function (apply or map family) to find the best beta from each column used to calculate HOLT forecasting. Here is the data that has a total of two columns.

structure(list(T = c(6753L, 6763L, 6803L, 6806L, 6777L, 6799L, 
6809L, 6832L, 6838L, 6831L, 6838L, 6807L, 6782L, 6809L, 6785L, 
6766L, 6788L, 6704L, 6656L, 7093L, 7091L, 7100L, 7074L, 7047L, 
7063L, 7070L, 7068L, 7054L, 7056L, 7067L, 7040L, 7027L, 7032L, 
7055L, 7058L, 7051L, 7074L, 7109L, 7103L, 7127L, 7121L, 7111L, 
7123L, 7147L, 7119L, 7106L, 7103L, 7091L, 7097L, 7103L, 7086L, 
7099L, 7094L, 7139L, 7186L, 7198L, 7248L, 7274L, 7319L, 7329L, 
7384L, 7410L, 7479L), C = c(2307L, 2296L, 2297L, 2287L, 2273L, 
2259L, 2246L, 2230L, 2215L, 2194L, 2175L, 2110L, 2098L, 2074L, 
2070L, 2107L, 2117L, 2128L, 2106L, 1687L, 1674L, 1664L, 1638L, 
1641L, 1672L, 1679L, 1677L, 1675L, 1681L, 1675L, 1665L, 1697L, 
1694L, 1693L, 1693L, 1691L, 1703L, 1706L, 1700L, 1695L, 1698L, 
1712L, 1688L, 1701L, 1693L, 1674L, 1690L, 1688L, 1710L, 1711L, 
1692L, 1688L, 1700L, 1684L, 1755L, 1744L, 1764L, 1762L, 1753L, 
1753L, 1768L, 1763L, 1788L)), class = "data.frame", row.names = c(NA, 
-63L))

Following is how I calculate RMSE value when there is only ONE column. I am trying to have two betas at once instead of running the same codes multiple times.

beta<-seq(.05,.9,by=0.001)
RMSE<-NULL
for (i in seq_along(beta)){
  fit<-holt(cretrain, beta=beta[i],h = length(cretest))
  RMSE[i]<-accuracy(fit,cretest)[2,2]
}

beta.fit<-data_frame(beta,RMSE)
beta.min<-filter(beta.fit,RMSE==min(RMSE))

I am trying to get the best beta.min for each column and use it in Holt forecasting. Any suggestion is appreciated!

Ivan
  • 76
  • 7
  • You showed two columnss in single dataset i.e. T and C columns. But your description is two datasets – akrun Apr 24 '20 at 02:29
  • where does function holt() come from? You could help us out by making your question reproducible as outlined here: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Chase Apr 24 '20 at 02:35
  • it should be one dataset with two columns. holt is from the forecast package – Ivan Apr 24 '20 at 02:55

0 Answers0