楼主: applewang王
2757 1

[问答] R语言中,构建函数plotForecastErrors,出现了错误,图形也少了一条蓝线 [推广有奖]

  • 5关注
  • 1粉丝

已卖:1份资源

本科生

13%

还不是VIP/贵宾

-

威望
0
论坛币
206 个
通用积分
0.1200
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
678 点
帖子
43
精华
0
在线时间
75 小时
注册时间
2014-12-12
最后登录
2018-1-28

楼主
applewang王 发表于 2017-8-22 16:12:32 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
> 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
[E0N}5{})1ZV_8D@])1@RYY.png 这个图片是我做出来的结果
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Forecast forecas Errors terror Error

沙发
erectoo 发表于 2018-5-7 08:24:49
你好,你的问题解决了吗?我也出现了同样的情况

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-31 00:30