config-i1 / smooth

The set of functions used for time series analysis and in forecasting.
89 stars 19 forks source link

no applicable method for 'smoothType' applied to an object of class "c('adam', 'smooth')" #204

Open mark0100 opened 1 year ago

mark0100 commented 1 year ago

When I run the example code from smoothCombine() i get the following error:

models <- list(es(BJsales), sma(BJsales)) smoothCombine(BJsales,models=models) Error in UseMethod("smoothType") : no applicable method for 'smoothType' applied to an object of class "c('adam', 'smooth')"

traceback() 4: FUN(X[[i]], ...) 3: lapply(models, smoothType) 2: unlist(lapply(models, smoothType)) 1: smoothCombine(BJsales, models = models)

I also get this error with my own data when i call smoothCombine() I tried detaching/removing and reinstalling the smooth package from CRAN but still the error persists.

I am on linux with R 4.3 and:

library(smooth) This is package "smooth", v3.2.0

If i look in the code for smoothCombine() there is a reference to a variable "smoothType" (on line 99) but it is never set:

if (is.null(names(models))) {
    names(models) <- unlist(lapply(models, smoothType))
}

And i can confirm that there are no names in the models object:

models <- list(es(BJsales), sma(BJsales)) names(models) NULL

So if i run this code snippet manually i get the same error:

unlist(lapply(models, smoothType)) Error: object 'smoothType' not found

What should smoothType be? Do i have to set it manually before calling smoothCombine()?

Making the models named parameters does solve the smoothType error but throws another error:

models <- list(es=es(BJsales), sma=sma(BJsales)) smoothCombine(BJsales,models=models) Error in match.arg(interval[1], c("none", "simulated", "approximate", : 'arg' must be NULL or a character vector

traceback() 6: stop("'arg' must be NULL or a character vector") 5: match.arg(interval[1], c("none", "simulated", "approximate", "semiparametric", "nonparametric", "confidence", "parametric", "prediction", "empirical", "complete")) 4: forecast.adam(X[[i]], ...) 3: FUN(X[[i]], ...) 2: lapply(models, forecast, h = h, interval = interval, level = 0, holdout = holdout, cumulative = cumulative, xreg = xreg) 1: smoothCombine(BJsales, models = models)

config-i1 commented 1 year ago

Hi,

Thanks for your message! smoothType is an internal function that extracts the type of model. It looks like a bug in how it is defined and how it is exported from the package. I'll fix this.

Also, I noticed an issue with the interval type. This is now fixed in d49850cd8824a5e3ad3b7e38d4d63994a592fb9b If you want to have the fix, you'll need to install the package from github.

config-i1 commented 1 year ago

Should be fixed now in db1546e396e132b071f056bd50a733c52eccf068 Please check and let me know if the problem (or a similar one) persists.

mark0100 commented 1 year ago

Hello Ivan,

Thanks for your quick reply.

I have tested the new version and the standard example for smoothCombine() now works. The smoothType error is fixed but with some data and parameter settings i still get the match.arg error on interval when calling smoothCombine():

models <- list(es(BJsales, h=12, holdout=TRUE, interval="p", silent=FALSE), sma(BJsales, h=12, holdout=TRUE, interval="p", silent=FALSE)) Forming the pool of models based on... ANN, AAN, Estimation progress: 100%... Done! Order 1 - 510.772; Order 69 - 1173.5638; Order 138 - 1250.2688 Order 1 - 510.772; Order 35 - 1088.5239; Order 69 - 1173.5638 Order 1 - 510.772; Order 18 - 965.1295; Order 35 - 1088.5239 Order 1 - 510.772; Order 9 - 831.8731; Order 18 - 965.1295 Order 1 - 510.772; Order 5 - 719.3918; Order 9 - 831.8731 Order 1 - 510.772; Order 3 - 632.8999; Order 5 - 719.3918 Order 1 - 510.772; Order 2 - 576.5735; Order 3 - 632.8999 Warning message: In es(BJsales, h = 12, holdout = TRUE, interval = "p", silent = FALSE) : Parameter "interval" is no longer supported in es(). Please use forecast() method to produce prediction interval.

smoothCombine(BJsales,models=models, h=12, holdout=TRUE, interval="p", silent=FALSE) Error in match.arg(interval[1], c("none", "simulated", "approximate", : 'arg' should be one of “none”, “simulated”, “approximate”, “semiparametric”, “nonparametric”, “confidence”, “parametric”, “prediction”, “empirical”, “complete”

traceback() 6: stop(sprintf(ngettext(length(chs <- unique(choices[nzchar(choices)])), "'arg' should be %s", "'arg' should be one of %s"), paste(dQuote(chs), collapse = ", ")), domain = NA) 5: match.arg(interval[1], c("none", "simulated", "approximate", "semiparametric", "nonparametric", "confidence", "parametric", "prediction", "empirical", "complete")) 4: forecast.adam(X[[i]], ...) 3: FUN(X[[i]], ...) 2: lapply(models, forecast, h = h, interval = intervalOriginal, level = 0, holdout = holdout, cumulative = cumulative, xreg = xreg) 1: smoothCombine(BJsales, models = models, h = 12, holdout = TRUE, interval = "p", silent = FALSE)

I am not sure this is still a bug or just me providing wrong parameters/data.

config-i1 commented 1 year ago

Can you please try interval="parametric" instead? There have been some changes in es() and sma() functions. As you see it no longer accepts interval as one of parameters. I haven't updated the smoothCombine() properly to align it with the new functions, but it should not matter much.

mark0100 commented 1 year ago

I have tried that but it makes no difference:

models <- list(es(BJsales, h=12, holdout=TRUE, interval="parametric", silent=FALSE), sma(BJsales, h=12, holdout=TRUE, interval="parametric", silent=FALSE)) Forming the pool of models based on... ANN, AAN, Estimation progress: 100%... Done! Order 1 - 510.772; Order 69 - 1173.5638; Order 138 - 1250.2688 Order 1 - 510.772; Order 35 - 1088.5239; Order 69 - 1173.5638 Order 1 - 510.772; Order 18 - 965.1295; Order 35 - 1088.5239 Order 1 - 510.772; Order 9 - 831.8731; Order 18 - 965.1295 Order 1 - 510.772; Order 5 - 719.3918; Order 9 - 831.8731 Order 1 - 510.772; Order 3 - 632.8999; Order 5 - 719.3918 Order 1 - 510.772; Order 2 - 576.5735; Order 3 - 632.8999 Warning message: In es(BJsales, h = 12, holdout = TRUE, interval = "parametric", : Parameter "interval" is no longer supported in es(). Please use forecast() method to produce prediction interval.

smoothCombine(BJsales,models=models, h=12, holdout=TRUE, interval="parametric", silent=FALSE) Error in match.arg(interval[1], c("none", "simulated", "approximate", : 'arg' must be NULL or a character vector

config-i1 commented 1 year ago

Thanks! I'll have a look when I have free time and try to fix it. Apologies for inconvenience.