I have the following code which contains errors
Classes‘tbl_df’, ‘tbl’ and 'data.frame': 341 obs. of 2 variables:
month: Date, format: "1982-06-12" "1982-06-19" ... sales: num 14237 4520 55691 28295 23648 ...
- attr(*, "spec")=
.. cols(
.. month = col_date(format = ""),
.. sales = col_double()
The below quote provides me the Holtwinters forecast
load needed packages
library(readr)
library(dplyr)
library(ggplot2)
library(forecast)
import data
sales <- read_csv("../input/MonthlySales.csv")
explore data
str(sales)
head(sales, n = 5)
Classes‘tbl_df’, ‘tbl’ and 'data.frame': 341 obs. of 2 variables:
month: Date, format: "1982-06-12" "1982-06-19" ...
sales: num 14237 4520 55691 28295 23648 ...
- attr(*, "spec")=
.. cols(
.. month = col_date(format = ""),
.. sales = col_double()
.. )
options(repr.plot.width = 6, repr.plot.height = 3)
ggplot(sales, aes(x = month, y = sales)) + geom_line() + geom_smooth(method = 'lm') +labs(x = "Time", y = "Monthly Sales")
salesTS <- ts(sales$sales, frequency = 4, start = c(1982,1))
class(salesTS)
'ts'
options(repr.plot.width = 6, repr.plot.height = 5)
salesDecomp <- decompose(salesTS)
plot(salesDecomp)
logging transform time series data
salesLog <- log(salesTS)
salesLogHW <- HoltWinters(salesLog)
salesLogHW
Call:
HoltWinters(x = salesLog)
options(repr.plot.width = 6, repr.plot.height = 4)
plot(salesLogHW)
forecast next year's sales
nextYearSales <- forecast(salesLogHW, h=4)
plot
plot(nextYearSales)
nextYearSales
my MonthlySales table has the followingdata ( i will show only the first 40 lines)
Month | sales |
---|---|
1982-06-12 | 1 |
1983-06-19 | 6 |
1983-06-20 | 2 |
1983-06-21 | 4 |
1983-06-22 | 3 |
1983-06-23 | 5 |
1983-06-24 | 8 |
1983-06-25 | 9 |
1983-06-26 | 4 |
1983-06-27 | 5 |
1983-06-28 | 6 |
1983-06-29 | 1 |
1982-09-04 | 5 |
1982-09-05 | 3 |
1982-09-06 | 4 |
1982-09-07 | 6 |
1982-09-08 | 5 |
1982-09-09 | 6 |
1982-09-10 | 4 |
1982-09-11 | 1 |
1982-09-12 | 2 |
1982-09-13 | 2 |
1982-09-14 | 2 |
1983-11-20 | 1 |
1983-11-21 | 3 |
1983-11-22 | 4 |
1983-11-23 | 4 |
1983-11-24 | 7 |
1983-11-25 | 10 |
1983-11-26 | 10 |
1983-11-27 | 9 |
1983-11-28 | 7 |
1983-11-29 | 8 |
1983-11-30 | 2 |
1983-12-01 | 3 |
1983-12-02 | 4 |
1983-12-03 | 1 |
1983-12-04 | 1 |
1983-12-05 | 1 |
is there anyone in R studio community who can correct the incorrect section?