简体   繁体   English

协变量在tslm中不起作用

[英]Covariates not working in tslm

I have seasonal time series data for weekly retail sales and am trying to use the tslm function of Hyndman's forecast package to fit a model with regressors in addition to trend and season. 我具有每周零售量的季节性时间序列数据,并且正在尝试使用Hyndman预测软件包的tslm函数来拟合除趋势和季节之外还具有回归变量的模型。

The issue I'm running into is that when I build the tslm, before adding any regressors (only trend + season), I get a perfect fit (R^2 =1) on the training data! 我遇到的问题是,在构建tslm时,在添加任何回归变量(仅趋势+季节)之前,我会在训练数据上获得完美拟合(R ^ 2 = 1)!

A prefect fit is problematic because any additional covariate I add to the model (# of items being sold, distribution, etc.) have no impact on predictions (insignificant). 完美拟合是有问题的,因为我添加到模型的任何其他协变量(所售商品的数量,分配等)对预测没有影响(微不足道)。 Just looking at the data, I know these other regressors matter so I'm not exactly sure where I'm going wrong. 仅查看数据,我就知道这些其他回归指标很重要,因此我不确定自己要去哪里。 Hoping somebody in the community can help me out. 希望社区中有人可以帮助我。

Some information about the data I am using: 有关我正在使用的数据的一些信息:

  1. Dataset contains weekly data from 2014 - 2017 数据集包含2014年至2017年的每周数据
  2. Training data contains 156 weekly observations (2014 - 2016) 培训数据包含156个每周观察值(2014-2016)
  3. Test data contains 48 observations in 2017 测试数据包含2017年的48个观察结果

I am using weekly seasonality to build the time series: 我使用每周的季节性来建立时间序列:

ts.train <- ts(df.train$sales, freq=365.25/7)
m.lm <- tslm(ts.train ~ trend + season + items, data=df.train)
p.lm <- forecast(m.lm, 
               h=48,
               newdata=data.frame(items=df.test$items))

If I leave "items" out of the formula, the predictions do not change at all. 如果我将“项目”放在公式之外,则预测完全不会改变。

I appreciate any input and guidance! 感谢您的投入和指导!

Items probably has too many variables (if they are dummy variables), since you get a perfect fit. 项目可能有太多的变量(如果它们是虚拟变量),因为您可以很好地适应。 See: https://www.otexts.org/fpp2/useful-predictors.html 参见: https : //www.otexts.org/fpp2/useful-predictors.html

For example, you need only 6 dummy variables to account for 7 week days. 例如,您只需要6个虚拟变量即可说明7个工作日。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM