具有先知或线性回归的销售预测和效应量回归

问题描述 投票:0回答:1

我使用先知和线性回归是为了:

  1. 预测当日/商店级别的销售;
  2. 了解我的阻遏器的效果大小(x个变量)。

我不一定要坚持使用这些建模技术。

现在,我面临的问题是,如果我分别为每个商店建模,则观察次数将会减少(因此,我失去了自由度)。但是,如果我汇总所有商店-并立即对它们进行建模-我希望该模型不太适合。此外,如果将这些商店的销售额进行汇总,则最大的商店将在该组中具有更大的权重系数。

最终,我需要对商店级别进行预测。但是,我想使用所有存储来确定我的外部抑制器的效果大小。

我的数据是来自100家商店的每天4年的销售数据。额外的回归因子是折扣深度(百分比)。参见以下示例,了解我的数据的样子:

> head(data)
        Date Sales_EUR Store_ID Discount_depth
1 2017-01-01       101        1           0.10
2 2017-01-01       105        2           0.12
3 2017-01-01       104        3           0.11
4 2017-01-01       200        4           0.09
5 2017-01-01       170        5           0.10
6 2017-01-01       150        6           0.12

有人对此问题有解决方案或最佳做法吗?

非常感谢。

r forecasting lm facebook-prophet
1个回答
0
投票

我不熟悉先知,但我认为,根据您的发言,您似乎希望执行线性混合效应(随机效应)模型,该模型可以解释商店之间和商店内部的差异。这将有助于总体销售预测,也有助于单个商店的销售。我已经根据您的数据创建了一些示例数据,并提供了一个非常基本的RE模型,其中Store_id作为RE。

library(dplyr) 
library(zoo) #create season variable
library(nlme) #random effects

set.seed(10)
df<-data.frame(Date = rep(seq.Date(from =as.Date("01/01/2016", "%d/%m/%Y"), 
                               to=as.Date("01/01/2020", "%d/%m/%Y"), by="day"), times = 100), 
               Sales_EUR = rnorm(146200, 150, 25),
               Store_ID = rep(1:100, each = 1462),
               Discount_depth = rnorm(146200, 0.10, 0.01))
df <- df %>% 
  dplyr::arrange(Store_ID, Date)

#create season variable to try to capture seasonality, month as factor might suffice?
yq <- as.yearqtr(as.yearmon(df$Date, "%d/%m/%Y") + 1/12)
df$Season <- factor(format(yq, "%q"), levels = 1:4, 
                    labels = c("winter", "spring", "summer", "fall"))
head(df)  
        Date Sales_EUR Store_ID Discount_depth Season
1 2016-01-01  150.4687        1     0.08615730 winter
2 2016-01-02  145.3937        1     0.10361614 winter
3 2016-01-03  115.7167        1     0.09962170 winter
4 2016-01-04  135.0208        1     0.08624449 winter
5 2016-01-05  157.3636        1     0.10553382 winter
6 2016-01-06  159.7449        1     0.08965313 winter

然后从这个数据集中,运行一个简单的RE模型:

#i presume from your question you want to predict "Sales_EUR"?
#basic random-effects model using library(nlme)
m1 <- lme(Sales_EUR ~  Discount_depth + Season,
          random = ~ 1 | Store_ID,
          data = df,
          na.action = "na.omit") 
summary(m1)

Linear mixed-effects model fit by REML
 Data: df 
      AIC     BIC    logLik
  1355776 1355845 -677880.8

Random effects:
 Formula: ~1 | Store_ID
        (Intercept) Residual
StdDev:   0.2288529 24.97051

Fixed effects: Sales_EUR ~ Discount_depth + Season 
                   Value Std.Error     DF   t-value p-value
(Intercept)    151.22885  0.666889 146096 226.76767  0.0000
Discount_depth -13.77271  6.532148 146096  -2.10845  0.0350
Seasonspring     0.02474  0.184847 146096   0.13382  0.8935
Seasonsummer    -0.01271  0.184847 146096  -0.06875  0.9452
Seasonfall       0.20315  0.185349 146096   1.09603  0.2731
 Correlation: 
               (Intr) Dscnt_ Ssnspr Ssnsmm
Discount_depth -0.980                     
Seasonspring   -0.143  0.003              
Seasonsummer   -0.142  0.002  0.504       
Seasonfall     -0.140  0.001  0.503  0.503

Standardized Within-Group Residuals:
         Min           Q1          Med           Q3          Max 
-4.530496999 -0.674513460  0.000275551  0.676791346  4.162294311 

Number of Observations: 146200
Number of Groups: 100 

您将需要试用模型,但这是使您前进的基本想法。然后您就可以开始尝试进行预测了,请参见此处help

© www.soinside.com 2019 - 2024. All rights reserved.