> souvenir <- scan("http://robjhyndman.com/tsdldata/data/fancy.dat")
Read 84 items
> souvenirtimeseries <- ts(souvenir, frequency=12, start=c(1987,1))
> logsouvenirtimeseries <- log(souvenirtimeseries)
> plot.ts(logsouvenirtimeseries)
> souvenirtimeseriesforecasts <- HoltWinters(logsouvenirtimeseries)
> plot(souvenirtimeseriesforecasts)
> library("forecast")
> souvenirtimeseriesforecasts2 <- forecast(souvenirtimeseriesforecasts, h=48)
> plot(souvenirtimeseriesforecasts2)
> plotForecastErrors <- function(forecasterrors)
+ {
+ # make a red histogram of the forecast errors:
+ mysd <- sd(forecasterrors)
+ hist(forecasterrors, col="red", freq=FALSE)
+ # freq=FALSE ensures the area under the histogram = 1
+ # generate normally distributed data with mean 0 and standard deviation mysd
+ mynorm <- rnorm(10000, mean=0, sd=mysd)
+ myhist <- hist(mynorm, plot=FALSE)
+ # plot the normal curve as a blue line on top of the histogram of forecast errors:
+ points(myhist$mids, myhist$density, type="l", col="blue", lwd=2)
+ }
> source("plotForecastErrors.R")
Error in file(filename, "r", encoding = encoding) : 无法打开链结
此外: Warning message:
In file(filename, "r", encoding = encoding) :
无法打开文件'plotForecastErrors.R': No such file or directory
> plotForecastErrors(souvenirtimeseriesforecasts2$residuals)
Error in hist.default(mynorm, plot = FALSE) : invalid number of 'breaks
此外: Warning message:
In rnorm(10000, mean = 0, sd = mysd) : 产生了NA