简体   繁体   English

使用时间滞后预测变量(自变量)进行预测的线性回归

[英]Linear regression using time lagged predictors (independent variables) for forecasting purpose

I'm working on forecasting the Monthly Average Precipitation of a geographical region in India (Assam and Meghalaya subdivision).我正在预测印度某个地理区域(阿萨姆邦和梅加拉亚邦细分)的月平均降水量。 For this purpose, I'm using the Monthly Average Air Temperature data and Monthly Averaged Relative Humidity data (which I extracted and averaged it spatially from the netCDF4 file for this geographical region present on the NOAA website) as the independent variables(predictors).为此,我使用每月平均气温数据和每月平均相对湿度数据(我从 NOAA 网站上的该地理区域的 netCDF4 文件中提取并在空间上对其进行平均)作为自变量(预测变量)。

For the forecasting purpose, I want to model a linear regression with Precipitation as the dependent variable and "Air Temperature" and "Relative Humidity" data as the independent variables such that they're having a time-lagged effect in the regression.出于预测目的,我想以降水为因变量,将“气温”和“相对湿度”数据作为自变量对线性回归进行建模,以便它们在回归中具有时滞效应。

The Linear regression equation should look like:线性回归方程应如下所示:

Please follow this link for the equation请按照此链接获取等式

Here, "Y" is Precipitation, "X" is Air Temperature and "Z" is Relative Humidity.这里,“Y”是降水量,“X”是气温,“Z”是相对湿度。

The sample "Training data" is as follows:样本“训练数据”如下:

   ID       Time Precipitation Air_Temperature Relative_Humidity
1   1 1948-01-01           105        20.31194          81.64137
2   2 1948-02-01           397        21.21052          80.20120
3   3 1948-03-01           594        22.14363          81.94274
4   4 1948-04-01          2653        20.79417          78.89908
5   5 1948-05-01          7058        20.43589          82.99959
6   6 1948-06-01          5328        18.10059          77.91983
7   7 1948-07-01          4882        16.63936          76.25758
8   8 1948-08-01          3979        16.56065          76.89210
9   9 1948-09-01          2625        16.95542          76.80116
10 10 1948-10-01          2578        17.13323          75.62411

And a segment of "Test data" is as follows:而一段“测试数据”如下:

        ID       Time Precipitation Air_Temperature Relative_Humidity
    1  663 2003-03-01           862        21.27210          79.77419
    2  664 2003-04-01          1812        20.44042          79.42500
    3  665 2003-05-01          1941        19.24267          79.57057
    4  666 2003-06-01          4981        18.53784          80.67292
    5  667 2003-07-01          4263        17.21581          79.97178
    6  668 2003-08-01          2436        16.88686          81.37097
    7  669 2003-09-01          2322        16.23134          77.63333
    8  670 2003-10-01          2220        17.40589          81.14516
    9  671 2003-11-01           131        19.01159          79.15000
    10 672 2003-12-01           241        20.86234          79.05847

Any help would be highly appreciated.任何帮助将不胜感激。 Thanks!谢谢!

Reacting to your clarification in the comments, here is one of many ways to produce lagged variables, using the lag function within dplyr (I am also adding a new row here for later forecasting):根据您在评论中的澄清,这里是使用dplyrlag函数生成滞后变量的众多方法dplyr (我还在此处添加了一个新行以供以后预测):

df %>%
   add_row(ID = 11, Time = "1948-11-01") %>%
   mutate(Air_Temperature_lagged = dplyr::lag(Air_Temperature, 1),
          Relative_Humidity_lagged = dplyr::lag(Relative_Humidity, 1)) -> df.withlags

You can then fit a straightforward linear regression using lm , with Precipitation as your dependent variable and the lagged versions of the two other variables as the predictor:然后,您可以使用lm拟合简单的线性回归,将Precipitation作为您的因变量,并将其他两个变量的滞后版本作为预测变量:

precip.model <- lm(data = df.withlags, Precipitation ~ Air_Temperature_lagged + Relative_Humidity_lagged)

You could then apply your coefficients to your most recent values in Air_Temperature and Relative_Humidity to forecast the precipitation for November of 1948 using the predict function.然后,您可以将系数应用于Air_TemperatureRelative_Humidity最新值,以使用predict函数predict 1948 年 11 月的降水。

predict(precip.model, newdata = df.withlags)
  1        2        3        4        5        6        7        8        9       10       11 
  NA 2929.566 3512.551 3236.421 3778.742 2586.012 3473.482 3615.884 3426.378 3534.965 3893.255 

The model's prediction is 3893.255 .模型的预测是3893.255

Note that this model will only allow you to forecast one time period into the future, since you don't have more information in your predictors.请注意,此模型仅允许您预测未来的一个时间段,因为您的预测变量中没有更多信息。

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

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