earowang / hts Goto Github PK
View Code? Open in Web Editor NEWHierarchical and Grouped Time Series
Home Page: http://pkg.earo.me/hts
Hierarchical and Grouped Time Series
Home Page: http://pkg.earo.me/hts
Hello,
I have a population dataset with 3 grouping variables (Age, Gender and Urban/Rural Setting).
I would like to generate bottom level predictions ( for Age * Gender * UrbanRuralSetting) and to make them match with higher level predictions (Age*Gender) that we have from external sources (outputs of a model).
I am discovering the hts package, but I think this is something I can do with the combinef function. Is it correct?
Is there a better way to proceed with the functions provided by the package ? I was initially thinking to use an arima model with the higher levels as external predictors (following this tutorial : https://robjhyndman.com/hyndsight/hts-with-regressors/), but I have read that external predictors should be other explanatory variables, and not predictions. Do you confirm this point? I'll be happy to provide a reproductible example once I am sure of the function I should use.
Best regards,
Améline Vallet
Here is the code I am running -
fit <- forecast.gts(new_ts,h = 365,fmethod = "arima",xreg = train,newxreg = holidayf$Total,method = "comb")
Error in auto.arima(x, lambda = lambda, xreg = xreg, parallel = FALSE, : No suitable ARIMA model found In addition: Warning message: In auto.arima(x, lambda = lambda, xreg = xreg, parallel = FALSE, : Unable to calculate AIC offset
It would massively help if I knew which bottom level series is causing the error so that I can isolate it.
each and every time series in grouped time series are forecasted separately in forecast.gts function. If I have forecasts from a different method (State space method) for both top and bottom levels, can I have them included in the forecast.gts function?
I am trying to reconcile a set of time series forecast that are already in hierarchal format using combinef.
Issue is there are some missing node (time series) for example A -> AA AB, B -> BA BB, AA-> AAA AAB, BB -> BBA BBB.
As you notice in this example there is not series for AB. In this situation the combinef function is erroring out.
Not sure it should be a new issue or this is an existing issue.
Error in utmat %*% fcasts: Cholmod error 'X and/or Y have wrong dimensions' at file ../MatrixOps/cholmod_sdmult.c, line 90
Traceback:
When calling gts over a large colname the grouping fails to mapply since duplicates are dropped.
Lets begin with the following data.frame
bnames1 <- c("CO0993W01010011388888NA0001TF001001XXXXXXXPR0011",
"CO0993W01110011388888NA0001TF001002XXXXXXXPR0012",
"CO0994W02210011388888NA0001TF001003XXXXXXXPR0013",
"CO0994W02310011388889NA0002TF001004XXXXXXXPR0014",
"RE0995W01410011388889NA0002TF001005XXXXXXXPR0015",
"RE0995W02510011388889NA0003TF001006XXXXXXXPR0016",
"RE0996W03110011388889NA0003TF001007XXXXXXXPR0017",
"WA0997W01210011388889NA0003TF001008XXXXXXXPR0018",
"WA0998W01310011488898NA0004TF001009XXXXXXXPR0019",
"WA0999W03410011488898NA0004TF001010XXXXXXXPR0010",
"FL0983W01510011488898NA0004TF001011XXXXXXXPR0011",
"FL0983W02110011488878NA0005TF001012XXXXXXXPR0011",
"FL0983W02210011488878NA0005TF001013XXXXXXXPR0013",
"IC0973W01310011488878NA0005TF001014XXXXXXXPR0011",
"IC0972W01410011488878NA0006TF001015XXXXXXXPR0011",
"IC0972W01510011488878NA0006TF001016XXXXXXXPR0011")
bts1 <- matrix(ts(rnorm(160)), ncol = 16)
colnames(bts1) <- bnames1
x1 <- gts(bts1, characters = list(c(2, 4, 3, 4), c(3, 5, 6, 15, 6)))
This will generate the following warning:
Warning message:
In mapply(rep, as.list(gnames), times, SIMPLIFY = FALSE) :
longer argument not a multiple of length of shorter
And the following groups with NA assignments
$G1
[1] "G1/CO" "G1/RE" "G1/WA" "G1/FL" "G1/IC"
$G2
[1] "G2/CO0993" "G2/CO0994" "G2/RE0995" "G2/RE0996" "G2/WA0997" "G2/WA0998" "G2/WA0999"
[8] "G2/FL0983" "G2/IC0973" "G2/IC0972"
$G3
[1] "G3/CO0993W01" "G3/CO0994W02" "G3/RE0995W01" "G3/RE0995W02" "G3/RE0996W03" "G3/WA0997W01"
[7] "G3/WA0998W01" "G3/WA0999W03" "G3/FL0983W01" "G3/FL0983W02" "G3/IC0973W01" "G3/IC0972W01"
$G4
[1] "G4/CO0993W010100" "G4/CO0993W011100" "G4/CO0994W022100" "G4/CO0994W023100"
[5] "G4/RE0995W014100" "G4/RE0995W025100" "G4/RE0996W031100" "G4/WA0997W012100"
[9] "G4/WA0998W013100" "G4/WA0999W034100" "G4/FL0983W015100" "G4/FL0983W021100"
[13] "G4/FL0983W022100" "G4/IC0973W013100" "G4/IC0972W014100" "G4/IC0972W015100"
$G5
[1] "G5/113" "G5/114"
$G6
[1] "G6/11388888" "G6/11388889" "G6/11488898" "G6/11488878"
$G7
[1] "G7/11388888NA0001" "G7/11388889NA0002" "G7/11388889NA0003" "G7/11488898NA0004"
[5] "G7/11488878NA0005" "G7/11488878NA0006"
$G8
[1] "G8/11388888NA0001TF001001XXXXXXX" "G8/11388888NA0001TF001002XXXXXXX"
[3] "G8/11388888NA0001TF001003XXXXXXX" "G8/11388889NA0002TF001004XXXXXXX"
[5] "G8/11388889NA0002TF001005XXXXXXX" "G8/11388889NA0003TF001006XXXXXXX"
[7] "G8/11388889NA0003TF001007XXXXXXX" "G8/11388889NA0003TF001008XXXXXXX"
[9] "G8/11488898NA0004TF001009XXXXXXX" "G8/11488898NA0004TF001010XXXXXXX"
[11] "G8/11488898NA0004TF001011XXXXXXX" "G8/11488878NA0005TF001012XXXXXXX"
[13] "G8/11488878NA0005TF001013XXXXXXX" "G8/11488878NA0005TF001014XXXXXXX"
[15] "G8/11488878NA0006TF001015XXXXXXX" "G8/11488878NA0006TF001016XXXXXXX"
$G9
[1] "G9/11388888NA0001TF001001XXXXXXXPR0011" "G9/11388888NA0001TF001002XXXXXXXPR0012"
[3] "G9/11388888NA0001TF001003XXXXXXXPR0013" "G9/11388889NA0002TF001004XXXXXXXPR0014"
[5] "G9/11388889NA0002TF001005XXXXXXXPR0015" "G9/11388889NA0003TF001006XXXXXXXPR0016"
[7] "G9/11388889NA0003TF001007XXXXXXXPR0017" "G9/11388889NA0003TF001008XXXXXXXPR0018"
[9] "G9/11488898NA0004TF001009XXXXXXXPR0019" "G9/11488898NA0004TF001010XXXXXXXPR0010"
[11] "G9/11488898NA0004TF001011XXXXXXXPR0011" "G9/11488878NA0005TF001012XXXXXXXPR0011"
[13] "G9/11488878NA0005TF001013XXXXXXXPR0013" "G9/11488878NA0005TF001014XXXXXXXPR0011"
[15] "G9/11488878NA0006TF001015XXXXXXXPR0011" "G9/11488878NA0006TF001016XXXXXXXPR0011"
$G10
[1] "G10/CO113" "G10/RE113" "G10/WA113" "G10/WA114" "G10/FL114" "G10/IC114"
$G11
[1] "G11/CO11388888" "G11/CO11388889" "G11/RE11388889" "G11/WA11388889" "G11/WA11488898"
[6] "G11/FL11488898" "G11/FL11488878" "G11/IC11488878"
$<NA>
[1] "G1/CO11388888NA0001" "G1/CO11388889NA0002" "G1/RE11388889NA0002" "G1/RE11388889NA0003"
[5] "G1/WA11388889NA0003" "G1/WA11488898NA0004" "G1/FL11488898NA0004" "G1/FL11488878NA0005"
[9] "G1/IC11488878NA0005" "G1/IC11488878NA0006"
$<NA>
[1] "G2/CO11388888NA0001TF001001XXXXXXX" "G2/CO11388888NA0001TF001002XXXXXXX"
[3] "G2/CO11388888NA0001TF001003XXXXXXX" "G2/CO11388889NA0002TF001004XXXXXXX"
[5] "G2/RE11388889NA0002TF001005XXXXXXX" "G2/RE11388889NA0003TF001006XXXXXXX"
[7] "G2/RE11388889NA0003TF001007XXXXXXX" "G2/WA11388889NA0003TF001008XXXXXXX"
[9] "G2/WA11488898NA0004TF001009XXXXXXX" "G2/WA11488898NA0004TF001010XXXXXXX"
[11] "G2/FL11488898NA0004TF001011XXXXXXX" "G2/FL11488878NA0005TF001012XXXXXXX"
[13] "G2/FL11488878NA0005TF001013XXXXXXX" "G2/IC11488878NA0005TF001014XXXXXXX"
[15] "G2/IC11488878NA0006TF001015XXXXXXX" "G2/IC11488878NA0006TF001016XXXXXXX"
$<NA>
[1] "G3/CO11388888NA0001TF001001XXXXXXXPR0011" "G3/CO11388888NA0001TF001002XXXXXXXPR0012"
[3] "G3/CO11388888NA0001TF001003XXXXXXXPR0013" "G3/CO11388889NA0002TF001004XXXXXXXPR0014"
[5] "G3/RE11388889NA0002TF001005XXXXXXXPR0015" "G3/RE11388889NA0003TF001006XXXXXXXPR0016"
[7] "G3/RE11388889NA0003TF001007XXXXXXXPR0017" "G3/WA11388889NA0003TF001008XXXXXXXPR0018"
[9] "G3/WA11488898NA0004TF001009XXXXXXXPR0019" "G3/WA11488898NA0004TF001010XXXXXXXPR0010"
[11] "G3/FL11488898NA0004TF001011XXXXXXXPR0011" "G3/FL11488878NA0005TF001012XXXXXXXPR0011"
[13] "G3/FL11488878NA0005TF001013XXXXXXXPR0013" "G3/IC11488878NA0005TF001014XXXXXXXPR0011"
[15] "G3/IC11488878NA0006TF001015XXXXXXXPR0011" "G3/IC11488878NA0006TF001016XXXXXXXPR0011"
$<NA>
[1] "G4/CO0993113" "G4/CO0994113" "G4/RE0995113" "G4/RE0996113" "G4/WA0997113" "G4/WA0998114"
[7] "G4/WA0999114" "G4/FL0983114" "G4/IC0973114" "G4/IC0972114"
$<NA>
[1] "G5/CO099311388888" "G5/CO099411388888" "G5/CO099411388889" "G5/RE099511388889"
[5] "G5/RE099611388889" "G5/WA099711388889" "G5/WA099811488898" "G5/WA099911488898"
[9] "G5/FL098311488898" "G5/FL098311488878" "G5/IC097311488878" "G5/IC097211488878"
$<NA>
[1] "G6/CO099311388888NA0001" "G6/CO099411388888NA0001" "G6/CO099411388889NA0002"
[4] "G6/RE099511388889NA0002" "G6/RE099511388889NA0003" "G6/RE099611388889NA0003"
[7] "G6/WA099711388889NA0003" "G6/WA099811488898NA0004" "G6/WA099911488898NA0004"
[10] "G6/FL098311488898NA0004" "G6/FL098311488878NA0005" "G6/IC097311488878NA0005"
[13] "G6/IC097211488878NA0006"
$<NA>
[1] "G7/CO099311388888NA0001TF001001XXXXXXX" "G7/CO099311388888NA0001TF001002XXXXXXX"
[3] "G7/CO099411388888NA0001TF001003XXXXXXX" "G7/CO099411388889NA0002TF001004XXXXXXX"
[5] "G7/RE099511388889NA0002TF001005XXXXXXX" "G7/RE099511388889NA0003TF001006XXXXXXX"
[7] "G7/RE099611388889NA0003TF001007XXXXXXX" "G7/WA099711388889NA0003TF001008XXXXXXX"
[9] "G7/WA099811488898NA0004TF001009XXXXXXX" "G7/WA099911488898NA0004TF001010XXXXXXX"
[11] "G7/FL098311488898NA0004TF001011XXXXXXX" "G7/FL098311488878NA0005TF001012XXXXXXX"
[13] "G7/FL098311488878NA0005TF001013XXXXXXX" "G7/IC097311488878NA0005TF001014XXXXXXX"
[15] "G7/IC097211488878NA0006TF001015XXXXXXX" "G7/IC097211488878NA0006TF001016XXXXXXX"
$<NA>
[1] "G8/CO099311388888NA0001TF001001XXXXXXXPR0011"
[2] "G8/CO099311388888NA0001TF001002XXXXXXXPR0012"
[3] "G8/CO099411388888NA0001TF001003XXXXXXXPR0013"
[4] "G8/CO099411388889NA0002TF001004XXXXXXXPR0014"
[5] "G8/RE099511388889NA0002TF001005XXXXXXXPR0015"
[6] "G8/RE099511388889NA0003TF001006XXXXXXXPR0016"
[7] "G8/RE099611388889NA0003TF001007XXXXXXXPR0017"
[8] "G8/WA099711388889NA0003TF001008XXXXXXXPR0018"
[9] "G8/WA099811488898NA0004TF001009XXXXXXXPR0019"
[10] "G8/WA099911488898NA0004TF001010XXXXXXXPR0010"
[11] "G8/FL098311488898NA0004TF001011XXXXXXXPR0011"
[12] "G8/FL098311488878NA0005TF001012XXXXXXXPR0011"
[13] "G8/FL098311488878NA0005TF001013XXXXXXXPR0013"
[14] "G8/IC097311488878NA0005TF001014XXXXXXXPR0011"
[15] "G8/IC097211488878NA0006TF001015XXXXXXXPR0011"
[16] "G8/IC097211488878NA0006TF001016XXXXXXXPR0011"
$<NA>
[1] "G9/CO0993W01113" "G9/CO0994W02113" "G9/RE0995W01113" "G9/RE0995W02113" "G9/RE0996W03113"
[6] "G9/WA0997W01113" "G9/WA0998W01114" "G9/WA0999W03114" "G9/FL0983W01114" "G9/FL0983W02114"
[11] "G9/IC0973W01114" "G9/IC0972W01114"
$<NA>
[1] "G10/CO0993W0111388888" "G10/CO0994W0211388888" "G10/CO0994W0211388889"
[4] "G10/RE0995W0111388889" "G10/RE0995W0211388889" "G10/RE0996W0311388889"
[7] "G10/WA0997W0111388889" "G10/WA0998W0111488898" "G10/WA0999W0311488898"
[10] "G10/FL0983W0111488898" "G10/FL0983W0211488878" "G10/IC0973W0111488878"
[13] "G10/IC0972W0111488878"
$<NA>
[1] "G11/CO0993W0111388888NA0001" "G11/CO0994W0211388888NA0001" "G11/CO0994W0211388889NA0002"
[4] "G11/RE0995W0111388889NA0002" "G11/RE0995W0211388889NA0003" "G11/RE0996W0311388889NA0003"
[7] "G11/WA0997W0111388889NA0003" "G11/WA0998W0111488898NA0004" "G11/WA0999W0311488898NA0004"
[10] "G11/FL0983W0111488898NA0004" "G11/FL0983W0211488878NA0005" "G11/IC0973W0111488878NA0005"
[13] "G11/IC0972W0111488878NA0006"
$<NA>
[1] "G1/CO0993W0111388888NA0001TF001001XXXXXXX" "G1/CO0993W0111388888NA0001TF001002XXXXXXX"
[3] "G1/CO0994W0211388888NA0001TF001003XXXXXXX" "G1/CO0994W0211388889NA0002TF001004XXXXXXX"
[5] "G1/RE0995W0111388889NA0002TF001005XXXXXXX" "G1/RE0995W0211388889NA0003TF001006XXXXXXX"
[7] "G1/RE0996W0311388889NA0003TF001007XXXXXXX" "G1/WA0997W0111388889NA0003TF001008XXXXXXX"
[9] "G1/WA0998W0111488898NA0004TF001009XXXXXXX" "G1/WA0999W0311488898NA0004TF001010XXXXXXX"
[11] "G1/FL0983W0111488898NA0004TF001011XXXXXXX" "G1/FL0983W0211488878NA0005TF001012XXXXXXX"
[13] "G1/FL0983W0211488878NA0005TF001013XXXXXXX" "G1/IC0973W0111488878NA0005TF001014XXXXXXX"
[15] "G1/IC0972W0111488878NA0006TF001015XXXXXXX" "G1/IC0972W0111488878NA0006TF001016XXXXXXX"
$<NA>
[1] "G2/CO0993W0111388888NA0001TF001001XXXXXXXPR0011"
[2] "G2/CO0993W0111388888NA0001TF001002XXXXXXXPR0012"
[3] "G2/CO0994W0211388888NA0001TF001003XXXXXXXPR0013"
[4] "G2/CO0994W0211388889NA0002TF001004XXXXXXXPR0014"
[5] "G2/RE0995W0111388889NA0002TF001005XXXXXXXPR0015"
[6] "G2/RE0995W0211388889NA0003TF001006XXXXXXXPR0016"
[7] "G2/RE0996W0311388889NA0003TF001007XXXXXXXPR0017"
[8] "G2/WA0997W0111388889NA0003TF001008XXXXXXXPR0018"
[9] "G2/WA0998W0111488898NA0004TF001009XXXXXXXPR0019"
[10] "G2/WA0999W0311488898NA0004TF001010XXXXXXXPR0010"
[11] "G2/FL0983W0111488898NA0004TF001011XXXXXXXPR0011"
[12] "G2/FL0983W0211488878NA0005TF001012XXXXXXXPR0011"
[13] "G2/FL0983W0211488878NA0005TF001013XXXXXXXPR0013"
[14] "G2/IC0973W0111488878NA0005TF001014XXXXXXXPR0011"
[15] "G2/IC0972W0111488878NA0006TF001015XXXXXXXPR0011"
[16] "G2/IC0972W0111488878NA0006TF001016XXXXXXXPR0011"
$<NA>
[1] "G3/CO0993W010100113" "G3/CO0993W011100113" "G3/CO0994W022100113" "G3/CO0994W023100113"
[5] "G3/RE0995W014100113" "G3/RE0995W025100113" "G3/RE0996W031100113" "G3/WA0997W012100113"
[9] "G3/WA0998W013100114" "G3/WA0999W034100114" "G3/FL0983W015100114" "G3/FL0983W021100114"
[13] "G3/FL0983W022100114" "G3/IC0973W013100114" "G3/IC0972W014100114" "G3/IC0972W015100114"
$<NA>
[1] "G4/CO0993W01010011388888" "G4/CO0993W01110011388888" "G4/CO0994W02210011388888"
[4] "G4/CO0994W02310011388889" "G4/RE0995W01410011388889" "G4/RE0995W02510011388889"
[7] "G4/RE0996W03110011388889" "G4/WA0997W01210011388889" "G4/WA0998W01310011488898"
[10] "G4/WA0999W03410011488898" "G4/FL0983W01510011488898" "G4/FL0983W02110011488878"
[13] "G4/FL0983W02210011488878" "G4/IC0973W01310011488878" "G4/IC0972W01410011488878"
[16] "G4/IC0972W01510011488878"
$<NA>
[1] "G5/CO0993W01010011388888NA0001" "G5/CO0993W01110011388888NA0001"
[3] "G5/CO0994W02210011388888NA0001" "G5/CO0994W02310011388889NA0002"
[5] "G5/RE0995W01410011388889NA0002" "G5/RE0995W02510011388889NA0003"
[7] "G5/RE0996W03110011388889NA0003" "G5/WA0997W01210011388889NA0003"
[9] "G5/WA0998W01310011488898NA0004" "G5/WA0999W03410011488898NA0004"
[11] "G5/FL0983W01510011488898NA0004" "G5/FL0983W02110011488878NA0005"
[13] "G5/FL0983W02210011488878NA0005" "G5/IC0973W01310011488878NA0005"
[15] "G5/IC0972W01410011488878NA0006" "G5/IC0972W01510011488878NA0006"
$<NA>
[1] "G6/CO0993W01010011388888NA0001TF001001XXXXXXX"
[2] "G6/CO0993W01110011388888NA0001TF001002XXXXXXX"
[3] "G6/CO0994W02210011388888NA0001TF001003XXXXXXX"
[4] "G6/CO0994W02310011388889NA0002TF001004XXXXXXX"
[5] "G6/RE0995W01410011388889NA0002TF001005XXXXXXX"
[6] "G6/RE0995W02510011388889NA0003TF001006XXXXXXX"
[7] "G6/RE0996W03110011388889NA0003TF001007XXXXXXX"
[8] "G6/WA0997W01210011388889NA0003TF001008XXXXXXX"
[9] "G6/WA0998W01310011488898NA0004TF001009XXXXXXX"
[10] "G6/WA0999W03410011488898NA0004TF001010XXXXXXX"
[11] "G6/FL0983W01510011488898NA0004TF001011XXXXXXX"
[12] "G6/FL0983W02110011488878NA0005TF001012XXXXXXX"
[13] "G6/FL0983W02210011488878NA0005TF001013XXXXXXX"
[14] "G6/IC0973W01310011488878NA0005TF001014XXXXXXX"
[15] "G6/IC0972W01410011488878NA0006TF001015XXXXXXX"
[16] "G6/IC0972W01510011488878NA0006TF001016XXXXXXX"
if the line in charge of duplicates in GmatrixG is removed
GmatrixG <- function(xmat) {
if (is.character(xmat)) {
# Convert character to integer
gmat <- t(apply(xmat, 1, function(x) as.integer(factor(x, unique(x)))))
} else {
gmat <- xmat
}
# Insert the first & last rows
nc.xmat <- ncol(xmat)
gmat <- rbind(rep(1L, nc.xmat), gmat, seq(1L, nc.xmat))
#Remove line in charge of duplicates
#gmat <- gmat[!duplicated(gmat), , drop = FALSE] # Remove possible duplicated
return(structure(gmat, class = "gmatrix"))
}
Then the groups are generated as expected
$G1
[1] "G1/CO" "G1/RE" "G1/WA" "G1/FL" "G1/IC"
$G2
[1] "G2/CO0993" "G2/CO0994" "G2/RE0995" "G2/RE0996" "G2/WA0997" "G2/WA0998" "G2/WA0999"
[8] "G2/FL0983" "G2/IC0973" "G2/IC0972"
$G3
[1] "G3/CO0993W01" "G3/CO0994W02" "G3/RE0995W01" "G3/RE0995W02" "G3/RE0996W03" "G3/WA0997W01"
[7] "G3/WA0998W01" "G3/WA0999W03" "G3/FL0983W01" "G3/FL0983W02" "G3/IC0973W01" "G3/IC0972W01"
$G4
[1] "G4/CO0993W010100" "G4/CO0993W011100" "G4/CO0994W022100" "G4/CO0994W023100"
[5] "G4/RE0995W014100" "G4/RE0995W025100" "G4/RE0996W031100" "G4/WA0997W012100"
[9] "G4/WA0998W013100" "G4/WA0999W034100" "G4/FL0983W015100" "G4/FL0983W021100"
[13] "G4/FL0983W022100" "G4/IC0973W013100" "G4/IC0972W014100" "G4/IC0972W015100"
$G5
[1] "G5/113" "G5/114"
$G6
[1] "G6/11388888" "G6/11388889" "G6/11488898" "G6/11488878"
$G7
[1] "G7/11388888NA0001" "G7/11388889NA0002" "G7/11388889NA0003" "G7/11488898NA0004"
[5] "G7/11488878NA0005" "G7/11488878NA0006"
$G8
[1] "G8/11388888NA0001TF001001XXXXXXX" "G8/11388888NA0001TF001002XXXXXXX"
[3] "G8/11388888NA0001TF001003XXXXXXX" "G8/11388889NA0002TF001004XXXXXXX"
[5] "G8/11388889NA0002TF001005XXXXXXX" "G8/11388889NA0003TF001006XXXXXXX"
[7] "G8/11388889NA0003TF001007XXXXXXX" "G8/11388889NA0003TF001008XXXXXXX"
[9] "G8/11488898NA0004TF001009XXXXXXX" "G8/11488898NA0004TF001010XXXXXXX"
[11] "G8/11488898NA0004TF001011XXXXXXX" "G8/11488878NA0005TF001012XXXXXXX"
[13] "G8/11488878NA0005TF001013XXXXXXX" "G8/11488878NA0005TF001014XXXXXXX"
[15] "G8/11488878NA0006TF001015XXXXXXX" "G8/11488878NA0006TF001016XXXXXXX"
$G9
[1] "G9/11388888NA0001TF001001XXXXXXXPR0011" "G9/11388888NA0001TF001002XXXXXXXPR0012"
[3] "G9/11388888NA0001TF001003XXXXXXXPR0013" "G9/11388889NA0002TF001004XXXXXXXPR0014"
[5] "G9/11388889NA0002TF001005XXXXXXXPR0015" "G9/11388889NA0003TF001006XXXXXXXPR0016"
[7] "G9/11388889NA0003TF001007XXXXXXXPR0017" "G9/11388889NA0003TF001008XXXXXXXPR0018"
[9] "G9/11488898NA0004TF001009XXXXXXXPR0019" "G9/11488898NA0004TF001010XXXXXXXPR0010"
[11] "G9/11488898NA0004TF001011XXXXXXXPR0011" "G9/11488878NA0005TF001012XXXXXXXPR0011"
[13] "G9/11488878NA0005TF001013XXXXXXXPR0013" "G9/11488878NA0005TF001014XXXXXXXPR0011"
[15] "G9/11488878NA0006TF001015XXXXXXXPR0011" "G9/11488878NA0006TF001016XXXXXXXPR0011"
$G10
[1] "G10/CO113" "G10/RE113" "G10/WA113" "G10/WA114" "G10/FL114" "G10/IC114"
$G11
[1] "G11/CO11388888" "G11/CO11388889" "G11/RE11388889" "G11/WA11388889" "G11/WA11488898"
[6] "G11/FL11488898" "G11/FL11488878" "G11/IC11488878"
$G12
[1] "G12/CO11388888NA0001" "G12/CO11388889NA0002" "G12/RE11388889NA0002"
[4] "G12/RE11388889NA0003" "G12/WA11388889NA0003" "G12/WA11488898NA0004"
[7] "G12/FL11488898NA0004" "G12/FL11488878NA0005" "G12/IC11488878NA0005"
[10] "G12/IC11488878NA0006"
$G13
[1] "G13/CO11388888NA0001TF001001XXXXXXX" "G13/CO11388888NA0001TF001002XXXXXXX"
[3] "G13/CO11388888NA0001TF001003XXXXXXX" "G13/CO11388889NA0002TF001004XXXXXXX"
[5] "G13/RE11388889NA0002TF001005XXXXXXX" "G13/RE11388889NA0003TF001006XXXXXXX"
[7] "G13/RE11388889NA0003TF001007XXXXXXX" "G13/WA11388889NA0003TF001008XXXXXXX"
[9] "G13/WA11488898NA0004TF001009XXXXXXX" "G13/WA11488898NA0004TF001010XXXXXXX"
[11] "G13/FL11488898NA0004TF001011XXXXXXX" "G13/FL11488878NA0005TF001012XXXXXXX"
[13] "G13/FL11488878NA0005TF001013XXXXXXX" "G13/IC11488878NA0005TF001014XXXXXXX"
[15] "G13/IC11488878NA0006TF001015XXXXXXX" "G13/IC11488878NA0006TF001016XXXXXXX"
$G14
[1] "G14/CO11388888NA0001TF001001XXXXXXXPR0011" "G14/CO11388888NA0001TF001002XXXXXXXPR0012"
[3] "G14/CO11388888NA0001TF001003XXXXXXXPR0013" "G14/CO11388889NA0002TF001004XXXXXXXPR0014"
[5] "G14/RE11388889NA0002TF001005XXXXXXXPR0015" "G14/RE11388889NA0003TF001006XXXXXXXPR0016"
[7] "G14/RE11388889NA0003TF001007XXXXXXXPR0017" "G14/WA11388889NA0003TF001008XXXXXXXPR0018"
[9] "G14/WA11488898NA0004TF001009XXXXXXXPR0019" "G14/WA11488898NA0004TF001010XXXXXXXPR0010"
[11] "G14/FL11488898NA0004TF001011XXXXXXXPR0011" "G14/FL11488878NA0005TF001012XXXXXXXPR0011"
[13] "G14/FL11488878NA0005TF001013XXXXXXXPR0013" "G14/IC11488878NA0005TF001014XXXXXXXPR0011"
[15] "G14/IC11488878NA0006TF001015XXXXXXXPR0011" "G14/IC11488878NA0006TF001016XXXXXXXPR0011"
$G15
[1] "G15/CO0993113" "G15/CO0994113" "G15/RE0995113" "G15/RE0996113" "G15/WA0997113"
[6] "G15/WA0998114" "G15/WA0999114" "G15/FL0983114" "G15/IC0973114" "G15/IC0972114"
$G16
[1] "G16/CO099311388888" "G16/CO099411388888" "G16/CO099411388889" "G16/RE099511388889"
[5] "G16/RE099611388889" "G16/WA099711388889" "G16/WA099811488898" "G16/WA099911488898"
[9] "G16/FL098311488898" "G16/FL098311488878" "G16/IC097311488878" "G16/IC097211488878"
$G17
[1] "G17/CO099311388888NA0001" "G17/CO099411388888NA0001" "G17/CO099411388889NA0002"
[4] "G17/RE099511388889NA0002" "G17/RE099511388889NA0003" "G17/RE099611388889NA0003"
[7] "G17/WA099711388889NA0003" "G17/WA099811488898NA0004" "G17/WA099911488898NA0004"
[10] "G17/FL098311488898NA0004" "G17/FL098311488878NA0005" "G17/IC097311488878NA0005"
[13] "G17/IC097211488878NA0006"
$G18
[1] "G18/CO099311388888NA0001TF001001XXXXXXX" "G18/CO099311388888NA0001TF001002XXXXXXX"
[3] "G18/CO099411388888NA0001TF001003XXXXXXX" "G18/CO099411388889NA0002TF001004XXXXXXX"
[5] "G18/RE099511388889NA0002TF001005XXXXXXX" "G18/RE099511388889NA0003TF001006XXXXXXX"
[7] "G18/RE099611388889NA0003TF001007XXXXXXX" "G18/WA099711388889NA0003TF001008XXXXXXX"
[9] "G18/WA099811488898NA0004TF001009XXXXXXX" "G18/WA099911488898NA0004TF001010XXXXXXX"
[11] "G18/FL098311488898NA0004TF001011XXXXXXX" "G18/FL098311488878NA0005TF001012XXXXXXX"
[13] "G18/FL098311488878NA0005TF001013XXXXXXX" "G18/IC097311488878NA0005TF001014XXXXXXX"
[15] "G18/IC097211488878NA0006TF001015XXXXXXX" "G18/IC097211488878NA0006TF001016XXXXXXX"
$G19
[1] "G19/CO099311388888NA0001TF001001XXXXXXXPR0011"
[2] "G19/CO099311388888NA0001TF001002XXXXXXXPR0012"
[3] "G19/CO099411388888NA0001TF001003XXXXXXXPR0013"
[4] "G19/CO099411388889NA0002TF001004XXXXXXXPR0014"
[5] "G19/RE099511388889NA0002TF001005XXXXXXXPR0015"
[6] "G19/RE099511388889NA0003TF001006XXXXXXXPR0016"
[7] "G19/RE099611388889NA0003TF001007XXXXXXXPR0017"
[8] "G19/WA099711388889NA0003TF001008XXXXXXXPR0018"
[9] "G19/WA099811488898NA0004TF001009XXXXXXXPR0019"
[10] "G19/WA099911488898NA0004TF001010XXXXXXXPR0010"
[11] "G19/FL098311488898NA0004TF001011XXXXXXXPR0011"
[12] "G19/FL098311488878NA0005TF001012XXXXXXXPR0011"
[13] "G19/FL098311488878NA0005TF001013XXXXXXXPR0013"
[14] "G19/IC097311488878NA0005TF001014XXXXXXXPR0011"
[15] "G19/IC097211488878NA0006TF001015XXXXXXXPR0011"
[16] "G19/IC097211488878NA0006TF001016XXXXXXXPR0011"
$G20
[1] "G20/CO0993W01113" "G20/CO0994W02113" "G20/RE0995W01113" "G20/RE0995W02113"
[5] "G20/RE0996W03113" "G20/WA0997W01113" "G20/WA0998W01114" "G20/WA0999W03114"
[9] "G20/FL0983W01114" "G20/FL0983W02114" "G20/IC0973W01114" "G20/IC0972W01114"
$G21
[1] "G21/CO0993W0111388888" "G21/CO0994W0211388888" "G21/CO0994W0211388889"
[4] "G21/RE0995W0111388889" "G21/RE0995W0211388889" "G21/RE0996W0311388889"
[7] "G21/WA0997W0111388889" "G21/WA0998W0111488898" "G21/WA0999W0311488898"
[10] "G21/FL0983W0111488898" "G21/FL0983W0211488878" "G21/IC0973W0111488878"
[13] "G21/IC0972W0111488878"
$G22
[1] "G22/CO0993W0111388888NA0001" "G22/CO0994W0211388888NA0001" "G22/CO0994W0211388889NA0002"
[4] "G22/RE0995W0111388889NA0002" "G22/RE0995W0211388889NA0003" "G22/RE0996W0311388889NA0003"
[7] "G22/WA0997W0111388889NA0003" "G22/WA0998W0111488898NA0004" "G22/WA0999W0311488898NA0004"
[10] "G22/FL0983W0111488898NA0004" "G22/FL0983W0211488878NA0005" "G22/IC0973W0111488878NA0005"
[13] "G22/IC0972W0111488878NA0006"
$G23
[1] "G23/CO0993W0111388888NA0001TF001001XXXXXXX" "G23/CO0993W0111388888NA0001TF001002XXXXXXX"
[3] "G23/CO0994W0211388888NA0001TF001003XXXXXXX" "G23/CO0994W0211388889NA0002TF001004XXXXXXX"
[5] "G23/RE0995W0111388889NA0002TF001005XXXXXXX" "G23/RE0995W0211388889NA0003TF001006XXXXXXX"
[7] "G23/RE0996W0311388889NA0003TF001007XXXXXXX" "G23/WA0997W0111388889NA0003TF001008XXXXXXX"
[9] "G23/WA0998W0111488898NA0004TF001009XXXXXXX" "G23/WA0999W0311488898NA0004TF001010XXXXXXX"
[11] "G23/FL0983W0111488898NA0004TF001011XXXXXXX" "G23/FL0983W0211488878NA0005TF001012XXXXXXX"
[13] "G23/FL0983W0211488878NA0005TF001013XXXXXXX" "G23/IC0973W0111488878NA0005TF001014XXXXXXX"
[15] "G23/IC0972W0111488878NA0006TF001015XXXXXXX" "G23/IC0972W0111488878NA0006TF001016XXXXXXX"
$G24
[1] "G24/CO0993W0111388888NA0001TF001001XXXXXXXPR0011"
[2] "G24/CO0993W0111388888NA0001TF001002XXXXXXXPR0012"
[3] "G24/CO0994W0211388888NA0001TF001003XXXXXXXPR0013"
[4] "G24/CO0994W0211388889NA0002TF001004XXXXXXXPR0014"
[5] "G24/RE0995W0111388889NA0002TF001005XXXXXXXPR0015"
[6] "G24/RE0995W0211388889NA0003TF001006XXXXXXXPR0016"
[7] "G24/RE0996W0311388889NA0003TF001007XXXXXXXPR0017"
[8] "G24/WA0997W0111388889NA0003TF001008XXXXXXXPR0018"
[9] "G24/WA0998W0111488898NA0004TF001009XXXXXXXPR0019"
[10] "G24/WA0999W0311488898NA0004TF001010XXXXXXXPR0010"
[11] "G24/FL0983W0111488898NA0004TF001011XXXXXXXPR0011"
[12] "G24/FL0983W0211488878NA0005TF001012XXXXXXXPR0011"
[13] "G24/FL0983W0211488878NA0005TF001013XXXXXXXPR0013"
[14] "G24/IC0973W0111488878NA0005TF001014XXXXXXXPR0011"
[15] "G24/IC0972W0111488878NA0006TF001015XXXXXXXPR0011"
[16] "G24/IC0972W0111488878NA0006TF001016XXXXXXXPR0011"
$G25
[1] "G25/CO0993W010100113" "G25/CO0993W011100113" "G25/CO0994W022100113"
[4] "G25/CO0994W023100113" "G25/RE0995W014100113" "G25/RE0995W025100113"
[7] "G25/RE0996W031100113" "G25/WA0997W012100113" "G25/WA0998W013100114"
[10] "G25/WA0999W034100114" "G25/FL0983W015100114" "G25/FL0983W021100114"
[13] "G25/FL0983W022100114" "G25/IC0973W013100114" "G25/IC0972W014100114"
[16] "G25/IC0972W015100114"
$G26
[1] "G26/CO0993W01010011388888" "G26/CO0993W01110011388888" "G26/CO0994W02210011388888"
[4] "G26/CO0994W02310011388889" "G26/RE0995W01410011388889" "G26/RE0995W02510011388889"
[7] "G26/RE0996W03110011388889" "G26/WA0997W01210011388889" "G26/WA0998W01310011488898"
[10] "G26/WA0999W03410011488898" "G26/FL0983W01510011488898" "G26/FL0983W02110011488878"
[13] "G26/FL0983W02210011488878" "G26/IC0973W01310011488878" "G26/IC0972W01410011488878"
[16] "G26/IC0972W01510011488878"
$G27
[1] "G27/CO0993W01010011388888NA0001" "G27/CO0993W01110011388888NA0001"
[3] "G27/CO0994W02210011388888NA0001" "G27/CO0994W02310011388889NA0002"
[5] "G27/RE0995W01410011388889NA0002" "G27/RE0995W02510011388889NA0003"
[7] "G27/RE0996W03110011388889NA0003" "G27/WA0997W01210011388889NA0003"
[9] "G27/WA0998W01310011488898NA0004" "G27/WA0999W03410011488898NA0004"
[11] "G27/FL0983W01510011488898NA0004" "G27/FL0983W02110011488878NA0005"
[13] "G27/FL0983W02210011488878NA0005" "G27/IC0973W01310011488878NA0005"
[15] "G27/IC0972W01410011488878NA0006" "G27/IC0972W01510011488878NA0006"
$G28
[1] "G28/CO0993W01010011388888NA0001TF001001XXXXXXX"
[2] "G28/CO0993W01110011388888NA0001TF001002XXXXXXX"
[3] "G28/CO0994W02210011388888NA0001TF001003XXXXXXX"
[4] "G28/CO0994W02310011388889NA0002TF001004XXXXXXX"
[5] "G28/RE0995W01410011388889NA0002TF001005XXXXXXX"
[6] "G28/RE0995W02510011388889NA0003TF001006XXXXXXX"
[7] "G28/RE0996W03110011388889NA0003TF001007XXXXXXX"
[8] "G28/WA0997W01210011388889NA0003TF001008XXXXXXX"
[9] "G28/WA0998W01310011488898NA0004TF001009XXXXXXX"
[10] "G28/WA0999W03410011488898NA0004TF001010XXXXXXX"
[11] "G28/FL0983W01510011488898NA0004TF001011XXXXXXX"
[12] "G28/FL0983W02110011488878NA0005TF001012XXXXXXX"
[13] "G28/FL0983W02210011488878NA0005TF001013XXXXXXX"
[14] "G28/IC0973W01310011488878NA0005TF001014XXXXXXX"
[15] "G28/IC0972W01410011488878NA0006TF001015XXXXXXX"
[16] "G28/IC0972W01510011488878NA0006TF001016XXXXXXX"
Ps: Sorry for the large example.
Need to explain c("lu", "cg", "chol", "recursive", "slm"),
I was trying to use forecastHybrid with hierarchical time series and external regressors but I cannot figure out how to do that. I am trying in this way:
library(hts)
library(forecastHybrid )
forecast(htseg1, a.args = list(xreg = data.frame(1:10)), models = "aet",
xreg = data.frame(11:20), FUN = hybridModel)
But I got the following error:
Error in forecast.Arima(object$auto.arima, h = h, xreg = xreg, level = level) : No regressors provided
I repeatedly get an annoying error with the hts() function even for the example in the help.
http://stackoverflow.com/questions/31753779/error-with-hts-package
I already generated independent base forecast for each series in the hierarchy, As these base forecasts are independently generated they will not be aggregate consistent" (i.e.,
they will not add up according to the hierarchical structure).I just want to generates a
set of revised forecasts that would aggregate consistently with the hierarchical structure. Can use your funcitons?
Hello, when i use MinT function,input 7 days(2018.10.22-28) forecasts and 7 days(2018.10.15-21) residual, but I got the error:
Error in if (!is.symmetric.matrix(x)) stop("argument x is not a symmetric matrix") :
missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In cov2cor(covm) :
diag(.) had 0 or NA entries; non-finite result is doubtful
2: In cov2cor(tar) :
diag(.) had 0 or NA entries; non-finite result is doubtful
How to solve this error? I looking forward to hearing from you
Here is a slightly altered example from the help docs:
bnames1 <- c("VICMelb", "VICGeel",
"NSWSynd", "NSWWoll")
bts1 <- matrix(ts(rnorm(160)), ncol = 4)
colnames(bts1) <- bnames1
x1 <- gts(bts1, characters = c(3, 4))
x1$groups
plot(x1)
From there, we can see in the graph that the third level isn't titled Bottom
, and the series there all begin with G1/...
instead of Bottom/...
or G1/VIC/...
and G1/NSW/...
. I don't imagine that was what was intended (but I could be wrong).
Additionally, it doesn't appear I can rename the Bottom
level; the gnames
argument to gts()
in this case only accepts a character vector of length 1 and applies that to the middle level. Is this intended?
> sessionInfo()
R version 3.1.1 (2014-07-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] hts_4.4 forecast_5.6 timeDate_3010.98 zoo_1.7-11
loaded via a namespace (and not attached):
[1] colorspace_1.2-4 fracdiff_1.4-2 grid_3.1.1 lattice_0.20-29 nnet_7.3-8 parallel_3.1.1 quadprog_1.5-5
[8] Rcpp_0.11.2 SparseM_1.05 tools_3.1.1 tseries_0.10-32
# sessionInfo()
# hts_4.5
# forecast_6.1
nodes <- list(2, c(3, 2))
abc <- ts(5 + matrix(sort(rnorm(500)), ncol = 5, nrow = 100), frequency = 7)
frequency(abc) # 7
frequency(hts(abc, nodes)) # 1
My intention is that after I create a hts
object, I'd like to obtain the first K
fourier terms of each underlying time series.
When I call fourier(hts(abc, nodes), K = 5)
, I am thrown an exception - "K must not be greater than period/2" because frequency(hts(abc, nodes))
is 1.
The options here are confusing, and the default should not be MinT as it is much slower than WLS without giving much better accuracy.
I suggest we use
method = c( "comb", "bu", "mo", "tdgsa", "tdgsf", "tdfp")
-- the same as in the current CRAN version -- and
weights = c("wls", "ols", "mint", "nseries")
We could allow "none" and "sd" to be equivalent to "ols" and "wls" respectively, for backwards compatibility.
Hello,
I already have forcast data, when I use combinef to revise the forcast, return this error. The input format is the same as the example of function combinef(). What cause this error?
as.matrix(dat)
Time Series:
Start = 1
End = 2
Frequency = 1
Total yCN01 yCN02 y755Y y023Y y010A y755AC y755AG y023Y00001 y010AAC
1 120 90 20 41 55 15 19 20 55 10
2 201 139 89 61 87 100 29 55 87 115
gtnode
$level 0
[1] 2
$level 1
[1] 3 1
$level 2
[1] 2 1 1
com <- combinef(fcasts=as.matrix(dat), nodes=gtnode, weights = NULL, keep = "all", algorithms = "lu")
Error in rowsum.default(repcount, rep(1L:nlist[i], xlist[[i]])) :
incorrect length for 'group'
Currently hts package is limited to arima,ets, and rw forecasting methods. Can we extend it to nnetar?
It would be helpful, as we include neural network in hierarchical methods.
Currently a multiple seasonal object is converted to ts within hts and gts. This precludes the use of tbats for forecasting. We should be able to leave msts and ts objects as they are, and only convert to ts if the y has no time series characteristics.
frequency(my.hts)
seems to return 1
even if frequency(my.hts$bts)
returns 12. Looks like an error because the forecast.hts()
method looks at the frequency of the hts object to determine the default forecast horizon. See the slightly modified stock example below.
> require(hts)
> abc <- ts(5 + matrix(sort(rnorm(1600)), ncol = 16, nrow = 100),frequency=12)
> sex <- rep(c("female", "male"), each = 8)
> state <- rep(c("NSW", "VIC", "QLD", "SA", "WA", "NT", "ACT", "TAS"), 2)
> gc <- rbind(sex, state) # a matrix consists of strings.
> gn <- rbind(rep(1:2, each = 8), rep(1:8, 2)) # a numerical matrix
> rownames(gc) <- rownames(gn) <- c("Sex", "State")
> x <- gts(abc, groups = gc)
> frequency(x)
[1] 1
> frequency(x$bts)
[1] 12
> sessionInfo()
R version 3.1.1 (2014-07-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] hts_4.4 forecast_5.6 timeDate_3010.98 zoo_1.7-11
loaded via a namespace (and not attached):
[1] colorspace_1.2-4 fracdiff_1.4-2 grid_3.1.1 lattice_0.20-29 nnet_7.3-8 parallel_3.1.1
[7] quadprog_1.5-5 Rcpp_0.11.2 SparseM_1.05 tools_3.1.1 tseries_0.10-32
Hi,
I'm facing a problem with a really simple model having only two hierarchical levels (root + one level).
Here's an example to reproduce the problem:
A <- matrix(c(5,5,5,5,2,2,2,2,2,2,2,2), 4,3)
Nodes <- list()
Nodes[["Level 0"]] <- 2
Weights <- c(1,10,10)
rbasedfcst <- combinef(fcasts=A, nodes=Nodes,
weights = Weights,
keep = "gts")
that raises this error:
Error in
colnames<-
(*tmp*
, value = unlist(labels[length(labels)])) :
length of 'dimnames' [2] not equal to array extent
If I try with 3 or more levels it seems to work perfectly, e.g. :
A <- matrix(c(5,5,5,5,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1), 4,7)
Nodes <- list()
Nodes[["Level 0"]] <- 2
Nodes[["Level 1"]] <- c(2,2)
Weights <- c(1,10,10,10,10,10,10)
rbasedfcst <- combinef(fcasts=A, nodes=Nodes,
weights = Weights,
keep = "gts")
The error seems located in the private function HierName
.
Environment :
It seems that the is.hts
and is.gts
functions are not exported but I think that they are useful during code development (at least for me :) ).
When forecasts are made using the stlf
method (one of the methods recommended by the author), the input forecast horizon is ignored and instead the default horizon of 2L * frequency(object$bts)
is used. The problem can be reproduced using the code below.
nodes <- list(2, c(3, 2))
abc <- ts(5 + matrix(sort(rnorm(500)), ncol = 5, nrow = 100),frequency=4)
x <- hts(abc, nodes)
forecast(x, h = 4, method = "comb", algorithms = "lu",FUN = stlf)
Thank you!
Hello,
sorry for my novice behaviour regarding pull requests and so on.
I'm opening an issue for this as I've announced:
It would be great if nodes could be specified by a separator such as an underscore.
This way the function could handle different length of nodes names.
My current solution looks for hts.R can be found in my fork repo. This time I only use function from base R:
I've tested with the examples:
abc <- ts(5 + matrix(sort(rnorm(1000)), ncol = 10, nrow = 100))
colnames(abc) <- c("AA_100_A_172", "AA_100_A_172", "A_10_C_A", "A_2_B_21", "A_2_B_DA","B30_A_1_H", "B30_B_3_Z", "B30_B_1_%", "B_40_A_2", "B_40_A_3")
y <- hts(abc, characters = c(1, 2, 1), sep="_")
and
abc <- ts(5 + matrix(sort(rnorm(1000)), ncol = 10, nrow = 100))
colnames(abc) <- c("AA_100_A", "AA_10_B1Z2", "A_10_C", "A_2_AB", "A_2_B","B30_A_1", "B30_B_3", "B30_CA_1", "B_40_A", "B_40_B")
y <- hts(abc, characters = c(1, 2, 1), sep="_")
gave me for y$nodes
:
$`Level 1`
[1] 4
$`Level 2`
AA A B30 B
2 3 3 2
$`Level 3`
AA100 A10 A2 B30A B30B B40
2 1 2 1 2 2
$`Level 4`
AA100A A10C A2B B30A1 B30B3 B30B1 B40A
2 1 2 1 1 1 2
and respectively:
$`Level 1`
[1] 4
$`Level 2`
AA A B30 B
2 3 3 2
$`Level 3`
AA100 AA10 A10 A2 B30A B30B B30CA B40
1 1 1 2 1 1 1 2
Best
When trying to install 'hts' on a Ubuntu 18.04.6 LTS AWS server
with R version 3.4.4 using this command
sudo R -e 'install.packages("hts", dependencies = TRUE)'
the installation breaks because RcppEigen is not found
These are the logs
ubuntu@ip-172-31-16-51:~$ sudo R -e 'install.packages("hts", dependencies = TRUE)'
R version 3.4.4 (2018-03-15) -- "Someone to Lean On"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> install.packages("hts", dependencies = TRUE)
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/hts_6.0.2.tar.gz'
Content type 'application/x-gzip' length 821684 bytes (802 KB)
==================================================
downloaded 802 KB
* installing *source* package ‘hts’ ...
** package ‘hts’ successfully unpacked and MD5 sums checked
** libs
g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -I"/usr/local/lib/R/site-library/RcppEigen/include" -fpic -g -O2 -fdebug-prefix-map=/build/r-base-AitvI6/r-base-3.4.4=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c RcppExports.cpp -o RcppExports.o
RcppExports.cpp:4:10: fatal error: RcppEigen.h: No such file or directory
#include <RcppEigen.h>
^~~~~~~~~~~~~
compilation terminated.
/usr/lib/R/etc/Makeconf:168: recipe for target 'RcppExports.o' failed
make: *** [RcppExports.o] Error 1
ERROR: compilation failed for package ‘hts’
* removing ‘/usr/local/lib/R/site-library/hts’
The downloaded source packages are in
‘/tmp/RtmpO7eOeq/downloaded_packages’
Warning message:
In install.packages("hts", dependencies = TRUE) :
installation of package ‘hts’ had non-zero exit status
>
>
Allow tbats as a base model.
Also we could have any function that takes a time series returns the point forecasts for each series within forecast.gts.
In the Usage, "demo(infangts) # gts" should be "demo(infantgts) # gts". There is a "t" missed.
hts version is 4.4 from CRAN
See the reproducible example below
library(hts)
myhts <- hts(cbind(wineind, 0))
# The total is fine here
aggts(myhts)
# The forecast produces NAN at all levels,
# including Total and wineind
forecast.gts(myhts)
Hello,
I suspect a bug in the forecast when using a gts object. It attached zip file contains the R code in txt format and the data file in csv format. The error thrown by the forecast command is:
Error in x[, (1 + cs[i]):cs[i + 1]] <- xx :
number of items to replace is not a multiple of replacement length
I have been unsuccessful finding assistance with this online and noticed that if I permute the second column of the time series matrix, all works fine but not if the first column is permuted. Thus, I thought there may be an issue with the interaction between the forcast command and the gts object.
Respecfully,
Brad Gubser
[email protected]
library(hts)
#> Loading required package: forecast
#> Loading required package: SparseM
#>
#> Attaching package: 'SparseM'
#> The following object is masked from 'package:base':
#>
#> backsolve
#> Loading required package: Matrix
#> Loading required package: matrixcalc
forecast(htseg1, fmethod = "arima", method = "tdfp", h = 1)
#> Warning in flist[[2L]]/new.flist[[1L]]: Recycling array of length 1 in vector-array arithmetic is deprecated.
#> Use c() or as.vector() instead.
#> Hierarchical Time Series
#> 3 Levels
#> Number of nodes at each level: 1 2 5
#> Total number of series: 8
#> Number of observations in each historical series: 10
#> Number of forecasts per series: 1
#> Top level series of forecasts:
#> Time Series:
#> Start = 2002
#> End = 2002
#> Frequency = 1
#> [1] 53.71128
forecast.gts(
htseg1, h = 10, method = "comb", algorithms = "lu",weights = "mint",
FUN = function(x) snaive(x), parallel = T,num.cores = 2
)
Hi,
This is some great work here. I noticed though, that it's still based on the forecast framework. Are there any plans to port it to tidyverts or make a replacement? Or has this been done already?
Just noting for the README
file that the arguments to install from GitHub are in the wrong order. Should be
install_github("hts","robjhyndman")
The equations are given in the CSDA 2011 paper. Can we add prediction intervals as an optional output to forecast.gts?
Currently, the following code will work:
htseg2x <- matrix(rnorm(16*17),nrow=16,ncol=17)
htseg2nx <- matrix(rnorm(10*17),nrow=10,ncol=17)
forecast(htseg2 , h=10, fmethod="arima", xreg=rnorm(16), newxreg=rnorm(10))
But this only allows the same xreg
and newxreg
vectors to be applied to all time series. We need to allow a matrix to be passed for each argument.
Hi,
I have created a grouped time series with 2 groups and 3 levels in each. When I pass this data to forecast.gts function error pops up saying:
Error in forecast.gts(gtsdf, h = 5, method = "comb", fmethod = "arima", :
object 'fcasts' not found
the code for creating ts:
gtsdata <- gts(tsdata, characters=list(c(6,2,3),c(2,1,1)))
modelFcsts<-forecast.gts(gtsdata, h=5, method="comb", fmethod="arima", weights='mint', covariance='shr', keep.fitted = T, keep.resid = T, nonnegative = T)
I've been digging a bit through the source code and I think the issue is in line 281 in [https://github.com/earowang/hts/blob/master/R/forecast-gts.R]
where it should state: pfcasts[pfcasts < 0] <- 0
Fully reproducible example on the public data that can be used to recreate problem is here (I've used the example from [https://otexts.com/fpp2/gts.html] with small adjustment to get negative forecasts):
library(fpp2)
library(hts)
prisonNeg<-prison
prisonNeg[,1]<-seq(nrow(prisonNeg), 1, -1) # just changing this column to get negative predictions from the model
prison.gts <- gts(prisonNeg, characters = c(3,1,9), gnames = c("State", "Gender", "Legal", "State*Gender", "State*Legal", "Gender*Legal"))
modelFcsts<-forecast.gts(prison.gts, h=5, method="comb", fmethod="arima", weights='mint', covariance='shr', keep.fitted = T, keep.resid = T, nonnegative = T)
Is there a way to enforce positive definite?
I also ran earlier into the same problem as #42 so I rounded both the forecasts and the residuals and replaced any 0s with 1s.
I am trying to install hts package on windows R machine and I am getting few warnings and then it crashes.
Warning in install.packages :
downloaded length 208896 != reported length 1320640
Warning in install.packages :
error 1 in extracting from zip file
Warning in install.packages :
cannot open compressed file 'hts/DESCRIPTION', probable reason 'No such file or directory'
Error in install.packages : cannot open the connection
When I try to manually download this package from your website, it also says broken link.
I was wondering how I could specify a one-level hierarchy, for instance, a single State divided in Cities( 7 digits id ).
I was trying to pass the city argument as "characters=c(7)" and unfortunately I am getting the following outcome
data.hts<-hts(data.ts, bnames = colnames(data.ts),characters=c(7))
Error in substr(unique.str[[x]], start = 1L, stop = end[x - 1L]) :
invalid substring arguments
install.packages('hts', dependencies = TRUE)
#>
#> There is a binary version available but the source version is
#> later:
#> binary source needs_compilation
#> hts 5.1.0 5.1.4 TRUE
#> installing the source package 'hts'
#> Warning in install.packages("hts", dependencies = TRUE): installation of
#> package 'hts' had non-zero exit status
Particular warnings (not in reprex output):
ld: warning: directory not found for option '-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0'
ld: warning: directory not found for option '-L/usr/local/gfortran/lib'
ld: library not found for -lgfortran
session info
sessionInfo()
#> R version 3.4.0 (2017-04-21)
#> Platform: x86_64-apple-darwin15.6.0 (64-bit)
#> Running under: macOS Sierra 10.12.5
#>
#> Matrix products: default
#> BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
#>
#> locale:
#> [1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> loaded via a namespace (and not attached):
#> [1] compiler_3.4.0 backports_1.1.0 magrittr_1.5 rprojroot_1.2
#> [5] tools_3.4.0 htmltools_0.3.6 yaml_2.1.14 Rcpp_0.12.11
#> [9] stringi_1.1.5 rmarkdown_1.6 knitr_1.16 stringr_1.2.0
#> [13] digest_0.6.12 evaluate_0.10.1
sensible_forecasts <-
function(forecasts,
force_signal = c("positive", "negative"),
max_iterations = 1000,
threshold = 0,
nodes,
groups,
weights = NULL,
algorithms = c("lu", "cg","chol", "recursive", "slm"),
prose = FALSE)
{
counter = 1
if (force_signal == "positve") {
comparisson = `>=`
rounding_function = ceiling
} else {
comparisson = `<=`
rounding_function = floor
}
transformation <- function(x) ifelse(comparisson(x,0),x,0)
repeat {
forecasts <- transformation(forecasts)
y_f <- combinef(forecasts,nodes,groups,weights,algorithms)
forecasts <- aggts(y_f) %>% rounding_function()
counter = counter + 1
if (all(comparisson(forecasts,threshold)) | counter == max_iterations ) {
forecasts <- transformation(forecasts)
if (prose == TRUE) {print(paste0("Number of attempts", counter)) }
break
}
}
return(forecasts)
}
Would be great if hts returned fitted and residual values when using comb nonnegative method
See this post
It seems that hts cannot create a hierarchical time series if we have only one observation in the series.
It returns: Error in if (nbts <= 1L) { : argument is of length zero
library(hts)
nodes <- list(2, c(3, 2))
abc <- ts(5 + matrix(sort(rnorm(500)), ncol = 5, nrow = 100))
y <- hts(abc[1,], nodes)
Is there any way of using weights or computing weights in combinef function so that they do not return negative forecasts in lower levels?
Hello, I'm new to the hts package so I apologize for any stupid questions I may have. For some reason, regardless of which method or fmethod I use, my forecasts always looks similar to this:
In this case, the code is:
fcast<-forecast(train. hts,h=101, fmethod='ets', method="tdgsa")
This is the summary of the hts object:
> train.hts
Hierarchical Time Series
4 Levels
Number of nodes at each level: 1 5 10 120
Total number of series: 136
Number of observations per series: 505
Top level series:
Time Series:
Start = 1
End = 505
Frequency = 1
Is there an obvious reason why the forecast is just the same value for each time period?
If more information is required to provide an answer, please let me know
Thanks and have a good day,
S
Thank you for this package! I'd like to confirm the sample covariance calculation in the "MinT" function here: https://github.com/earowang/hts/blob/master/R/MinT.R#L184
n <- nrow(res)
w.1 <- crossprod(res) / n
I expected w.1
to be the usual sample covariance matrix instead:
w.1 <- cov(allr)
# same as
n <- nrow(res)
res.centered <- scale(res, center=TRUE, scale=FALSE)
crossprod(res.centered)/(n-1)
The difference is that the usual sample covariance matrix (1) centers the residuals and (2) divides by n-1 instead of n for an unbiased estimate.
n
instead of n-1
also intentional?Thank you for confirming!
Labels get cropped in plots of an hts object. This is especialy a problem when handling lengthy label names. See http://stackoverflow.com/questions/22387811/r-hts-package-label-crop-in-plot
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.