Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R GG加强自动批次置信区间水平_R_Ggplot2_Xts_Forecast_Ggfortify - Fatal编程技术网

R GG加强自动批次置信区间水平

R GG加强自动批次置信区间水平,r,ggplot2,xts,forecast,ggfortify,R,Ggplot2,Xts,Forecast,Ggfortify,我试图使用ggfortify的autoplot估计95%的置信区间,但我无法实现。如果我使用forecast软件包,并提前3周预测95%的CI,效果很好。见下文: wt <- structure(list(DOC = c(3, 10, 17, 24, 31, 38, 45, 52, 59, 66, 73, 80, 87, 94, 101), AvgWeight = c(1, 1.66666666666667, 2.06666666666667, 2.275, 3.83333333333

我试图使用ggfortify的autoplot估计95%的置信区间,但我无法实现。如果我使用forecast软件包,并提前3周预测95%的CI,效果很好。见下文:

wt <- structure(list(DOC = c(3, 10, 17, 24, 31, 38, 45, 52, 59, 66, 
73, 80, 87, 94, 101), AvgWeight = c(1, 1.66666666666667, 2.06666666666667, 
2.275, 3.83333333333333, 6.2, 7.4, 8.5, 10.25, 11.1, 13.625, 
15.2, 16.375, 17.8, 21.5), PondName = structure(c(1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "Pond01", class = "factor"), 
    SampleDate = structure(c(1182585600, 1183190400, 1183795200, 
    1184400000, 1185004800, 1185609600, 1186214400, 1186819200, 
    1187424000, 1188028800, 1188633600, 1189238400, 1189843200, 
    1190448000, 1191052800), class = c("POSIXct", "POSIXt"))), .Names = c("DOC", 
"AvgWeight", "PondName", "SampleDate"), row.names = c(NA, 15L
), class = "data.frame")  

wt$SampleDate <- as.Date(wt$SampleDate)  
wt
     DOC AvgWeight PondName SampleDate
1    3  1.000000   Pond01 2007-06-23
2   10  1.666667   Pond01 2007-06-30
3   17  2.066667   Pond01 2007-07-07
4   24  2.275000   Pond01 2007-07-14
5   31  3.833333   Pond01 2007-07-21
6   38  6.200000   Pond01 2007-07-28
7   45  7.400000   Pond01 2007-08-04
8   52  8.500000   Pond01 2007-08-11
9   59 10.250000   Pond01 2007-08-18
10  66 11.100000   Pond01 2007-08-25
11  73 13.625000   Pond01 2007-09-01
12  80 15.200000   Pond01 2007-09-08
13  87 16.375000   Pond01 2007-09-15
14  94 17.800000   Pond01 2007-09-22
15 101 21.500000   Pond01 2007-09-29

    library(forecast)
    library(ggfortify)
    library(ggplot2)
    library(xts) 

pond <- as.xts(wt$AvgWeight,order.by=seq(as.Date("2007-06-23"), by=7, len=15))
pond 
d.arima <- auto.arima(pond)
d.arima;fitted(d.arima)
d.forecast <- forecast(d.arima, level = c(95), h = 3)
d.forecast


 > d.forecast
    Point Forecast    Lo 95    Hi 95
106           25.2 23.14483 27.25517
113           28.9 24.30450 33.49550
120           32.6 24.91026 40.28974

但如果我这样做:

ggfortify::autoplot(d.arima,predict=predict(d.arima,n.ahead=3),conf.int=TRUE,predict.alpha = 
0.05,fitted.colour="green",
predict.colour='red',predict.linetype='solid')

它默认为80%的置信区间。我试图在predict()中设置信心级别,但它被忽略了。我还尝试了autoplot()中的级别,但也没有成功。问题:如何使用ggfortify的autoplot实现不同程度的信心?此处使用predict.alpha是否正确,还是用于预测点估计的alpha颜色?
另外,是否可以将安装的绿线连接到预测的红线?

我很惊讶您没有收到错误,并且看到了显示的图。不幸的是,我不能复制你的情节

  • 当我在
    forecast
    之后加载
    ggfortify
    时,我找不到使用
    forecast
    s
    autoplot
    的方法。这是因为
    ggfortify
    实际上并没有导出
    autoplot
    ;相反,它覆盖了
    forecast
    中的
    autoplot
    方法。因此,
    ggfortify::autoplot(…)
    不应该工作,应该抛出错误 错误:“autoplot”不是从“命名空间:ggfortify”导出的对象

  • 也没有
    autoplot.forecast
    autoplot.ts
    predict
    参数,所以我不确定这是从哪里来的 您想使用
    forecast
    ggfortify
    的原因是什么?为什么不坚持使用
    forecast
    s
    autoplot
    进行绘图?下面是一个基于示例数据和
    d.arima

    autoplot(预测(d.arima))+theme_minimal()
    

    亮区和暗区分别对应于95%和80%的CI


    使用
    forecast_8.10
    ggfortify_0.4.7
    进行测试,我很惊讶您没有收到错误,并且看到了显示的图。不幸的是,我不能复制你的情节

  • 当我在
    forecast
    之后加载
    ggfortify
    时,我找不到使用
    forecast
    s
    autoplot
    的方法。这是因为
    ggfortify
    实际上并没有导出
    autoplot
    ;相反,它覆盖了
    forecast
    中的
    autoplot
    方法。因此,
    ggfortify::autoplot(…)
    不应该工作,应该抛出错误 错误:“autoplot”不是从“命名空间:ggfortify”导出的对象

  • 也没有
    autoplot.forecast
    autoplot.ts
    predict
    参数,所以我不确定这是从哪里来的 您想使用
    forecast
    ggfortify
    的原因是什么?为什么不坚持使用
    forecast
    s
    autoplot
    进行绘图?下面是一个基于示例数据和
    d.arima

    autoplot(预测(d.arima))+theme_minimal()
    

    亮区和暗区分别对应于95%和80%的CI


    使用
    forecast_8.10
    ggfortify_0.4.7
    进行测试,我无法在
    ggfortify_0.4.7
    forecast_8.10
    上复制
    ggfortify::autoplot(…)
    抛出错误,请参见下面我的答案。我无法在
    ggfortify\u 0.4.7
    forecast\u 8.10
    上复制
    ggfortify::autoplot(…)
    抛出错误,请参见下面的答案。是的,您是正确的。我将坚持预测。我之所以想使用ggfortify,是因为autoplot似乎有更多的选项来美化情节。例如,ggfortify将预测值连接到原始值,还允许您围绕置信区间绘制功能区。也许forecast的autoplot也有这些选项?我去看看。谢谢,你是对的。我将坚持预测。我之所以想使用ggfortify,是因为autoplot似乎有更多的选项来美化情节。例如,ggfortify将预测值连接到原始值,还允许您围绕置信区间绘制功能区。也许forecast的autoplot也有这些选项?我去看看。谢谢
    ggfortify::autoplot(d.arima,predict=predict(d.arima,n.ahead=3),conf.int=TRUE,predict.alpha = 
    0.05,fitted.colour="green",
    predict.colour='red',predict.linetype='solid')