在Arima中使用三个动态回归器构造一个xreg参数 [英] Structure an xreg parameter with three dynamic regressors in Arima

查看:1064
本文介绍了在Arima中使用三个动态回归器构造一个xreg参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢您查看我的问题.....



我正在使用以下文件: https://www.dropbox.com/s/i1a6y2ak4qkcix0/xregs1.csv



这段代码读入csv文件


ads1< - read.table(csvfile,header = TRUE,sep =,)



ts1< - ts(ads1,start = c(2012,1),频率= 49)



ts1 < - ts(ads1 [,4:5],start = c(2012,1),frequency = 49)


ts1对象允许我在Arima函数中选择单位或销售作为时间序列变量。
由于这是一个动态回归模型,我试图遵循Hyndman教授的建议,使用以下格式:


xreg< - cbind(Weekday = model.matrix(〜as.factor(modelfitsample $ Weekday)),
Day = modelfitsample $ Day,
Christmas = modelfitsample $ Christmas)


我正在尝试使用WK_PRICE作为连续回归器和两组虚拟变量,用于创建将被使用的矩阵的季节性和促销活动在xreg参数(即wk_2:wk_49为每周季节性和wk_p_2:wk_p_49促销活动)。



我正在努力正确设置xreg参数感谢您的关注和时间。



Steve


div class =h2_lin>解决方案

这将做你所要求的:

  ads1< ;  - ts(ads1,start = c(2012,1),frequency = 49)
qty< - ads1 [,4]
sls< - ads1 [,5]
price& - ads1 [,6]
week< - ads1 [,7:54]
promo< - ts(rowSums(ads1 [,55:ncol(ads1)]),start = c ,1),frequency = 49)

库(预测)
fit< - auto.arima(qty,xreg = cbind(price,promo,week))

请注意,您不希望为每种类型的每周类型提供单独的促销变量(基本上建模促销*周互动) 。所以我把它折叠成一个单一的虚拟变量,表示每个星期是否涉及促销活动。



我不建议用虚拟变量建模周季节,太多的自由度一个更好的解决方案是使用傅立叶项,如下所示:

  fw < -  fourier(qty,K = 3)
fit3< - auto.arima(qty,xreg = cbind(price,promo,fw))

使用K = 3傅里叶级数给出最小的AICc值。


Thanks for viewing my question.....

I am working with the following file: https://www.dropbox.com/s/i1a6y2ak4qkcix0/xregs1.csv

This code reads in the csv file

ads1 <- read.table(csvfile, header=TRUE, sep = ",")

ts1 <- ts(ads1, start=c(2012,1), frequency=49)

ts1 <- ts(ads1[,4:5], start=c(2012,1), frequency=49)

The ts1 object allows me to choose either Units or Sales as the time series variable in an Arima function. Since this is a Dynamic Regression model, I'm attempting to follow Professor Hyndman's suggestion in a previous post to use a format like:

xreg <- cbind(Weekday=model.matrix(~as.factor(modelfitsample$Weekday)), Day=modelfitsample$Day, Christmas=modelfitsample$Christmas)

I am attempting to use WK_PRICE as a continuous regressor and two sets of dummy variables for seasonality and promotional events in the creation of a matrix that will be used in the xreg parameter (i.e., wk_2:wk_49 for weekly seasonality and wk_p_2:wk_p_49 for promotional events).

I'm struggling to correctly set up the xreg parameter following the example above.

Thanks for your time and attention.

Steve

解决方案

This will do what you are asking:

ads1 <- ts(ads1, start=c(2012,1),frequency=49)
qty <- ads1[,4]
sls <- ads1[,5]
price <- ads1[,6]
week <- ads1[,7:54]
promo <- ts(rowSums(ads1[,55:ncol(ads1)]), start=c(2012,1), frequency=49)

library(forecast)
fit <- auto.arima(qty, xreg=cbind(price,promo,week))

Note that you do not want to have a separate promo variable for every type of week (essentially modelling the promo*week interaction). So I have collapsed this to a single dummy variable indicating if each week involved a promotion or not.

I would not recommend modelling weekly seasonality with dummy variables as it will take far too many degrees of freedom. A much better solution is to use Fourier terms, like this:

fw <- fourier(qty, K=3)
fit3 <- auto.arima(qty, xreg=cbind(price,promo,fw))

Using K=3 Fourier terms gave the smallest AICc value.

这篇关于在Arima中使用三个动态回归器构造一个xreg参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆