Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mark0100 opened this issue May 2, 2023 · 6 comments
Labels

Comments

@mark0100
Copy link

mark0100 commented May 2, 2023

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
Copy link
Owner

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 d49850c If you want to have the fix, you'll need to install the package from github.

@config-i1
Copy link
Owner

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

@mark0100
Copy link
Author

mark0100 commented May 3, 2023

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
Copy link
Owner

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
Copy link
Author

mark0100 commented May 3, 2023

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
Copy link
Owner

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

@config-i1 config-i1 reopened this May 3, 2023
@config-i1 config-i1 added the bug label May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants