You are on page 1of 1

decomair=decompose(co2)

plot(decomair)
# determining the contents of the object decomair
names(decomair)
decomair$trend
decomair$seasonal
# manual computations for trend and seasonality
trenddecomair=decomair$x-decomair$seasonal
plot(trenddecomair)
seasondecomair=decomair$x-decomair$trend
plot(seasondecomair)
# using Holt Winters exponential smoothing program
m=HoltWinters(co2)
m
#determining the contents of Holt Winters object
names(m)
#displaying the estimates of the Holt Winters exponential model which is the first
column.
m$fitted[,1]
# plotting the co2 together with the holt winters exponential model
plot(co2)
lines(fitted(m)[,1], col = 3)
#forecasting up to 8 months
library(forecast)
mp=forecast.HoltWinters(m,h=8,level=c(95))
mp
#plotting the forecast together with the original co2 line graph
plot.forecast(mp)

You might also like