error using holt() function in library(forecast)

Hello. I was trying to run a holt() function in my R code and the following error occured:
Error in ets(x, "AAN", alpha = alpha, beta = beta, phi = phi, damped = damped, :
No model able to be fitted.
I've tried multiple efforts to make this code run, but it never did. This is the code that I am trying:

library(forecast)
input= read.table("6-2.txt", header = TRUE)
attach(input)
holt_model= holt(CalSales, h=4)
summary(holt_model[["model"]])

Input looks like this:
CalSales
1 197
2 211
3 203
4 247
5 239
6 269
7 308
8 262
9 258
10 256
11 261
12 288
13 296
14 276
15 305
16 308
17 356
18 393
19 363
20 386
21 443
22 308
23 358
24 384
I would really appreciate some help.

It worked fine for me, as shown in the reprex (reproducible example) below. Also, two bits of advice. First, if you want help, make it easy for us to try your code on your data. After creating a data set with your numbers, I used the dput( ) function to get it in a format that can be easily shared. Second, avoid the use of attach( ). From the Google R Style Guide, "The possibilities for creating errors when using attach( ) are numerous."

library(forecast)
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo

input <- structure(list(CalSales = c(197L, 211L, 203L, 247L, 239L, 269L, 
308L, 262L, 258L, 256L, 261L, 288L, 296L, 276L, 305L, 308L, 356L, 
393L, 363L, 386L, 443L, 308L, 358L, 384L)), class = "data.frame", row.names = c(NA, 
-24L))

holt_model <- holt(input$CalSales, h=4)

summary(holt_model[["model"]])
#> Holt's method 
#> 
#> Call:
#>  holt(y = input$CalSales, h = 4) 
#> 
#>   Smoothing parameters:
#>     alpha = 1e-04 
#>     beta  = 1e-04 
#> 
#>   Initial states:
#>     l = 199.7736 
#>     b = 7.9699 
#> 
#>   sigma:  33.2374
#> 
#>      AIC     AICc      BIC 
#> 250.0740 253.4073 255.9643 
#> 
#> Training set error measures:
#>                      ME     RMSE      MAE       MPE     MAPE      MASE
#> Training set -0.4254659 30.34144 23.29228 -1.067513 7.490028 0.7730483
#>                   ACF1
#> Training set 0.1562895

Created on 2022-06-13 by the reprex package (v2.0.1)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.