SAS:用所有数据绘制预测数据
Posted
技术标签:
【中文标题】SAS:用所有数据绘制预测数据【英文标题】:SAS: Plotting forecast data with all the data 【发布时间】:2021-12-30 17:10:13 【问题描述】:我使用 proc ARIMA 来获取我的数据集下一年的预测,并有一个包含这些预测值的输出数据集。
我将原始数据的对数用于预测,因此我需要通过对预测值取指数来获得真实值。
我想要一个图表来显示数据的预测方式以及与原始数据相比的外观,但我不知道如何执行此操作。
代码:
* Open the file;
data intel_stock;
infile 'path' dlm=',' firstobs=2;
input Date anydtdte10. Volume;
format Date date10.;
Timeref=_n_;
logvolume = log(Volume);
run;
* Plot the data ;
proc sgplot data=intel_stock;
series x=Timeref y=Volume/markers;
xaxis values=(1 to 5000 by 1);
run;
* Variation seems to increase greatly over time, hence we take the log of volume ;
proc sgplot data=intel_stock;
series x=Timeref y=logvolume/markers;
xaxis values=(1 to 5000 by 1);
run;
* Plot shows a good amount of variance removed ;
* selecting an ARIMA model ;
proc arima data=intel_stock;
identify var= logvolume(1); * first difference was taken to make the data stationary ;
estimate p = 2 q = 2 ;
forecast lead=12 interval=month id=Date out=forecast;
run;
* ARIMA(2,1,2) model was used;
【问题讨论】:
【参考方案1】:使用Proc ARIMA
选项PLOTS=ALL
。
例子:
%if not %sysfunc(cexist(work.sasmacr.yahoo_stock_quotes.macro)) %then %do;
filename source url "https://www.devenezia.com/downloads/sas/macros/download.php?file=stock_quotes.sas";
%include source;
filename source;
%end;
%if not %sysfunc(exist(work.intc)) %then %do;
%yahoo_stock_quotes(symbol=INTC,start=11/01/2016)
data INTC;
set INTC;
Timeref=_n_;
logvolume = log(Volume);
run;
%end;
ods html file='intc.html';
proc sgplot data=INTC;
scatter x=Timeref y=Volume ;
run;
proc sgplot data=INTC;
scatter x=Timeref y=logvolume ;
run;
proc arima data=INTC plots=all;
title "INTC - ARIMA(2,1,2)";
identify var=logvolume(1); * first difference was taken to make the data stationary ;
estimate p = 2 q = 2 ;
forecast lead=12 interval=month id=Date out=forecast;
run;
quit;
ods html close;
【讨论】:
谢谢,但是我如何将其作为一个图,其中交易量或预测都不是实际值的对数? 您可以对输出数据集forecast
中的结果使用exp
函数并绘制它。不知道这与ARIMA
的假设有多大的冲突
我添加了我得到的答案,你怎么看?【参考方案2】:
* Removes logarithm from volume, forecast, upper and lower 95% CIs;
data intel_forecast;
set forecast;
Volume = exp(logvolume);
l95 = exp(l95);
u95 = exp(u95);
forecast = exp(forecast + std*std/2);
run;
* plots forecast with the rest of the data ;
proc sgplot data=intel_forecast;
where date >= '1JAN18'D;
band Upper=u95 Lower=l95 x=Date
/ legendLabel="95% Confidence Limits" ;
scatter x=Date y=Volume;
series x=Date y=forecast
/ legendlabel="Forecast of Volume for the next 5 years";
run;
【讨论】:
您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center。以上是关于SAS:用所有数据绘制预测数据的主要内容,如果未能解决你的问题,请参考以下文章