Table with ETS and HW values

Hello
I am trying to get values like ETS forecast , alpha , beta and gamma values, based on previous 20 observations. All in a simple table.Thats all. I ve been using lots of examples on this forum ,but none worked.
Is there anyone who can advise me on the code?
I ve been busy now for 3 months ,but so far unsuccessful ;-(

reprex:

# load needed packages
library(readr)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(readxl)
library(forecast) # necessary to use forecasting methods
#>   as.zoo.data.frame zoo
#> Loading required package: smooth

library (ggplot2)

# import data
sales <-  read_excel("C:/Users/jenny/Desktop/R Studio/MonthlySales1.xls")
#> New names:
#> * `` -> ...7
#> * `` -> ...8
fit <- Arima(sales,c(3,1,0))
#> Error in stats::arima(x = x, order = order, seasonal = seasonal, include.mean = include.mean, : only implemented for univariate time series
plot(forecast(fit))
#> Error in forecast(fit): object 'fit' not found
sales
#> # A tibble: 95 x 8
#>    Month     sales `ETS Forecast` `Hw -alpha` `Hw-beta` `Hw-gamma`  ...7  ...8
#>    <chr>     <dbl>          <dbl>       <dbl>     <dbl>      <dbl> <dbl> <dbl>
#>  1 january      43             NA          NA        NA         NA    NA    NA
#>  2 february     48             NA          NA        NA         NA    NA    NA
#>  3 march        47             NA          NA        NA         NA    NA    NA
#>  4 april        48             NA          NA        NA         NA    NA    NA
#>  5 may          48             NA          NA        NA         NA    NA    NA
#>  6 june         49             NA          NA        NA         NA    NA    NA
#>  7 july         38             NA          NA        NA         NA    NA    NA
#>  8 august       25             NA          NA        NA         NA    NA    NA
#>  9 september    48             NA          NA        NA         NA    NA    NA
#> 10 october      48             NA          NA        NA         NA    NA    NA
#> # ... with 85 more rows

Created on 2020-05-15 by the reprex package (v0.3.0)

the excel file looks like this:
MonthlySales1.xls")

Month sales ETS Forecast Hw -alpha Hw-beta Hw-gamma
january 43
february 48
march 47
april 48
may 48
june 49
july 38
august 25
september 48
october 48
november 39
december 49
january 41
february 35
march 43
april 47
may 39
june 49
july 37
august 46
september 31
october 45
november 26
december 24
january 48
february 32
march 47
april 49
may 48
june 45
july 43
august 47
september 43
october 27
november 43
december 49
january 48
february 46
march 47
april 34
may 35
june 49
july 42
august 49
september 49
october 43
november 48
december 49
january 47
february 44
march 33
april 46
may 39
june 43
july 49
august 45

I think the arima function wants the sales column of the sales tibble - sales$sales

You're square rooting values inside of a dataframe that your code hasnt made until two lines further down...

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

Good morning Phil. Thank you for your answer.
For some reason I dont see the values appearing in my table.I probably have still something wrong? How do i get to see the ETS and the Alpha,beta and Gamma in my table?

My renewed reprex:

# load needed packages
library(readr)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(readxl)
library(forecast) # necessary to use forecasting methods
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo
library(tsintermittent) # TSB (Teunter-Syntetos-Babai) method
#> Loading required package: MAPA
#> Loading required package: parallel
#> Loading required package: RColorBrewer
#> Loading required package: smooth
#> Loading required package: greybox
#> Error: package or namespace load failed for 'greybox' in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
#>  there is no package called 'RcppParallel'
#> Error: package 'greybox' could not be loaded
library (ggplot2)

# import data
sales <-
  read_excel("C:/Users/jenny/Desktop/R Studio/MonthlySales1.xls")
#> New names:
#> * `` -> ...7
#> * `` -> ...8
sales <- sqrt(salesLogHW$dispersion)
#> Error in eval(expr, envir, enclos): object 'salesLogHW' not found
dnorm(7, mean = coef(m1), sd = sdest)
#> Error in coef(m1): object 'm1' not found

salesLogHW <- HoltWinters(salesLog)
#> Error in as.ts(x): object 'salesLog' not found
salesLogHW
#> Error in eval(expr, envir, enclos): object 'salesLogHW' not found
HoltWinters(x = salesLog)
#> Error in as.ts(x): object 'salesLog' not found
findfrequency(nextYearSales)
#> Error in findfrequency(nextYearSales): object 'nextYearSales' not found

fit <- Arima(sales$sales)
cbind('sales', rowMeans(forecast.ets)[3:8])
#> Error in rowMeans(forecast.ets): 'x' must be an array of at least two dimensions
      autoplot(forecast(fit))

      sales
#> # A tibble: 95 x 8
#>    Month     sales `ETS Forecast` `Hw -alpha` `Hw-beta` `Hw-gamma`  ...7  ...8
#>    <chr>     <dbl>          <dbl>       <dbl>     <dbl>      <dbl> <dbl> <dbl>
#>  1 january      43             NA          NA        NA         NA    NA    NA
#>  2 february     48             NA          NA        NA         NA    NA    NA
#>  3 march        47             NA          NA        NA         NA    NA    NA
#>  4 april        48             NA          NA        NA         NA    NA    NA
#>  5 may          48             NA          NA        NA         NA    NA    NA
#>  6 june         49             NA          NA        NA         NA    NA    NA
#>  7 july         38             NA          NA        NA         NA    NA    NA
#>  8 august       25             NA          NA        NA         NA    NA    NA
#>  9 september    48             NA          NA        NA         NA    NA    NA
#> 10 october      48             NA          NA        NA         NA    NA    NA
#> # ... with 85 more rows

Created on 2020-05-16 by the reprex package (v0.3.0)

Ok, if i understand it correct;
code should look like this ?
How do i get the values like forecast and alpha,beta ,gamma in the sales-table ?
As you can see my code generates the values for the whole time series ,but i would need them row wise moving for 20 observations.(so the first 19 lines are blank and the values would start at observation 20)

btw; what do you mean with sales <- r ?
Can you amend my reprex so i can understand ?
cheers

reprex:

# load needed packages
library(readr)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(readxl)
library(forecast) # necessary to use forecasting methods
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo
library(tsintermittent) # TSB (Teunter-Syntetos-Babai) method
#> Loading required package: MAPA
#> Loading required package: parallel
#> Loading required package: RColorBrewer
#> Loading required package: smooth
#> Loading required package: greybox
#> Error: package or namespace load failed for 'greybox' in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
#>  there is no package called 'RcppParallel'
#> Error: package 'greybox' could not be loaded
library (ggplot2)

# import data

sales <-  read_excel("C:/Users/jenny/Desktop/R Studio/MonthlySales1.xls")
#> New names:
#> * `` -> ...7
#> * `` -> ...8

salesLogHW <- HoltWinters(salesLog)
#> Error in as.ts(x): object 'salesLog' not found
sales <- r
#> Error in eval(expr, envir, enclos): object 'r' not found
HoltWinters(x= salesLog)
#> Error in as.ts(x): object 'salesLog' not found
findfrequency(nextYearSales)
#> Error in findfrequency(nextYearSales): object 'nextYearSales' not found

cbind('sales', rowMeans(forecast.ets)[3:1])
#> Error in rowMeans(forecast.ets): 'x' must be an array of at least two dimensions
sales <- sqrt(salesLogHW$dispersion)
#> Error in eval(expr, envir, enclos): object 'salesLogHW' not found
dnorm(7, mean = coef(m1), sd = sdest)
#> Error in coef(m1): object 'm1' not found
autoplot(forecast(fit))
#> Error in forecast(fit): object 'fit' not found
fit <- Arima(sales$sales)
salesLogHW
#> Error in eval(expr, envir, enclos): object 'salesLogHW' not found
nextYearSales
#> Error in eval(expr, envir, enclos): object 'nextYearSales' not found
sales
#> # A tibble: 95 x 8
#>    Month     sales `ETS Forecast` `Hw -alpha` `Hw-beta` `Hw-gamma`  ...7  ...8
#>    <chr>     <dbl>          <dbl>       <dbl>     <dbl>      <dbl> <dbl> <dbl>
#>  1 january      43             NA          NA        NA         NA    NA    NA
#>  2 february     48             NA          NA        NA         NA    NA    NA
#>  3 march        47             NA          NA        NA         NA    NA    NA
#>  4 april        48             NA          NA        NA         NA    NA    NA
#>  5 may          48             NA          NA        NA         NA    NA    NA
#>  6 june         49             NA          NA        NA         NA    NA    NA
#>  7 july         38             NA          NA        NA         NA    NA    NA
#>  8 august       25             NA          NA        NA         NA    NA    NA
#>  9 september    48             NA          NA        NA         NA    NA    NA
#> 10 october      48             NA          NA        NA         NA    NA    NA
#> # ... with 85 more rows

Created on 2020-05-16 by the reprex package (v0.3.0)