[英]Forecasting with ARIMA and xreg in R
I'm having trouble with my first forecasting implementation in R. What I'd like to achieve is to predict the variable Y with 2 exogenous variables X1 and X2. 我在R中的第一个预测实现遇到了麻烦。我想要实现的是用两个外生变量X1和X2预测变量Y。 The 3 datasets are each represented as a single column with 12 rows.
3个数据集分别表示为具有12行的单列。
From another Stackpost I followed a similar approach: 在另一个Stackpost中,我遵循了类似的方法:
DataSample <- data.frame(Y=Y[,1],Month=rep(1:12,1),
X1=X1[,1],X2=X2[,1])
predictor_matrix <- cbind(Month=model.matrix(~as.factor(DataSample$Month)),
X1=DataSample$X1,
X2=DataSample$X2)
# Remove intercept
predictor_matrix <- predictor_matrix[,-1]
# Rename columns
colnames(predictor_matrix) <- c("January","February","March","April","May","June","July","August","September","October","November","X1","X2")
# Variable to be modeled
var <- ts(DataSample$Y, frequency=12)
#Find ARIMA
modArima <- auto.arima(var, xreg = predictor_matrix)
At this line I get the following error: 在这一行,我得到以下错误:
Error in optim(init[mask], armaCSS, method = optim.method, hessian = FALSE, : non-finite value supplied by optim
optim中的错误(init [mask],armaCSS,方法= optim.method,粗麻布= FALSE 、:由optim提供的非限定值)
I presume that my predictor_matrix
is not in the correct format but I can't find the error. 我想我的
predictor_matrix
_矩阵格式不正确,但是找不到错误。
Any help would be appreciated, 任何帮助,将不胜感激,
You have indicated "datasets are ... 12 rows". 您已指示“数据集为... 12行”。 Your predictor matrix has 13 columns (11 months [of dummy variables?] and 2 other variables).
您的预测变量矩阵有13列([11个月[虚拟变量?]和2个其他变量)。 Therefore, you necessarily have a linear dependence among the columns and the optimization procedure fails.
因此,您在列之间必然具有线性相关性,并且优化过程失败。
You need (ideally much) more data to support the number of predictor variables and/or a sparser set of predictors. 您需要(理想情况下)更多的数据来支持预测变量的数量和/或较少的预测变量集。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.