1
$\begingroup$

I created for the following data set a multiple regression. Now I would like to forecast the next 20 data points.

> dput(datSel)
structure(list(oenb_dependent = c(1.0227039, -5.0683144, 0.6657713, 
3.3161374, -2.1586704, -0.7833623, -0.2203209, 2.416144, -1.7625406, 
-0.1565037, -7.9803936, 9.4594715, -4.8104584, 8.4827107, -6.1895262, 
1.4288595, 1.4896459, -0.4198522, -5.1583964, 5.2502294, 1.0567102, 
-1.0923342, -1.5852298, 0.6061936, -0.3752335, 2.5008664, -1.3999729, 
2.2802166, -2.1468756, -1.4890328, -0.79254376, 3.21804705, -0.94407886, 
-0.27802316, -0.20753079, -1.12610048, 2.0883735, -0.7424854, 
0.44203729, -1.48905938, 1.39644424, -3.8917377, 11.25665848, 
-9.22884035, 3.26856762, -0.00179541, -2.39664325, 4.00455574, 
-5.60891295, 4.6556348, -4.40536951, 6.64234497, -7.34787319, 
7.56303006, -8.23083674, 4.43247855, 1.31090412), carReg = c(0.73435946, 
0.24001161, 16.90532537, -14.60281976, 6.47603166, -8.35815849, 
3.55576685, 7.10705794, -4.6955223, 10.9623709, 5.5801857, -6.4499936, 
-9.46196502, 9.36289122, -8.52630424, 5.45070994, -4.5346405, 
-2.26716538, 2.56870398, 0.013737, 5.7750101, -27.1060826, 1.08977179, 
4.94934712, 17.55391859, -13.91160577, 10.38981128, -11.81349246, 
-0.0831467, 2.79748237, 1.84865463, -1.98736934, -6.24191695, 
13.33602659, -3.86527871, 0.78720993, 4.73360651, -4.1674034, 
9.37426802, -5.90660464, -0.4915792, -5.84811629, 9.67648643, 
-6.96872719, -7.6535767, 0.24847595, 0.18685263, -2.28766949, 
1.1544631, -3.87636933, -2.4731545, 4.33876671, 1.08836339, 5.64525271, 
1.90743854, -3.94709355, -0.84611324), cpi = c(1.16, -3.26, 0.22, 
-3.51, 0.84, -2.81, -0.34, -4.57, -0.12, -3.95, -1.37, -2.73, 
0.35, -5.38, -4.43, -3.08, 0.74, -3.03, -1.09, -2, 0.35, -1.52, 
1.28, 0.2, -0.25, -4.55, -2.49, -4.24, -0.31, -2.96, -2.24, -0.46, 
-0.06, -2.67, -1.27, -1.4, -0.7, -0.96, -2.18, -2.53, -0.52, 
-1.74, -2.18, -1.4, -0.34, -0.09, -1.65, -1.15, -0.17, -2.01, 
-1.38, -1.24, 0.09, -2.44, -1.92, -2.61, -0.34), primConstTot = c(-0.33334, 
-0.93333, -0.16667, -0.33333, -0.16667, -0.86666, -0.3, -0.4, 
-0.26667, -1.56667, -0.73333, 0.1, -0.23333, -0.26667, -1.5774, 
-0.19284, 0.38568, -2.42423, -0.93663, 0.08265, -0.63361, 0.0551, 
-0.49587, 2.39668, -1.70798, -3.36085, -2.56196, 0.16529, 0, 
-1.84572, -1.3774, -0.49586, -1.70798, -1.90081, -0.55096, -0.77134, 
-0.16529, -0.30303, -0.17066, -0.23853, -0.64401, -1.52657, -1.57426, 
-0.28623, -0.54861, -1.07336, -0.71558, 0.02385, -0.38164, -1.09721, 
0, 0.14311, -0.38164, -1.02566, -0.42934, -0.35779, -0.4532), 
    resProp.Dwell = c(0.8, -4, -3.2, 2.7, -1.6, -1, -2.4, -0.4, 
    -0.8, 1, -12.1, 0.2, -5.2, 3.7, -2.7, -1.7, 1.5, 0.7, -7.9, 
    0.3, 0.3, 1.4, -3.3, -1, -1.6, 1.5, 0.5, 1.5, -1, -2.2, -3.5, 
    0.5, 0.5, -0.9, -0.4, -3.4, 0.9, 0.1, -0.2, -2.8, -0.8, -6.2, 
    11.3, -4.6, 1, 1.1, -1.7, 4.1, -5, 2.3, -2.3, 4.6, -6.3, 
    6.3, -6.9, 0, 2.4), cbre.office.primeYield = c(0, 0, 0.15, 
    0.15, 0.2, 0.2, 0.2, 0.25, 0.25, 0.25, 0.25, 0.2, 0.15, 0.1, 
    0.05, 0.15, 0.3, 0.35, 0.4, 0.3, 0.2, 0, -0.15, -0.85, -1, 
    -0.85, -0.75, -0.1, 0, 0, 0, 0.05, 0.05, 0.05, 0.05, 0, 0, 
    0, 0.2, 0.2, 0.2, 0.2, 0, 0, 0, 0, 0.25, 0.25, 0.25, 0.25, 
    0, 0, 0, 0, 0, 0, 0), cbre.retail.capitalValue = c(-1882.35294, 
    230.76923, -230.76923, -226.41509, -670.78117, -436.13707, 
    -222.22223, 0, -205.91233, -202.16847, 0, -393.5065, -403.91909, 
    -186.30647, -539.81107, -748.11463, -764.70588, -311.47541, 
    -301.42782, -627.09677, -480, 720, 782.6087, 645.96273, 251.42857, 
    1386.66667, -533.33334, -533.33333, -533.33333, 0, 0, -1024.56141, 
    -192.10526, 0, -730, 0, 0, 0, 0, 0, -834.28571, 0, -1450.93168, 
    0, 0, 0, -700.78261, 0, 0, 0, 0, 0, 0, 0, -1452, 0, 0)), .Names = c("oenb_dependent", 
"carReg", "cpi", "primConstTot", "resProp.Dwell", "cbre.office.primeYield", 
"cbre.retail.capitalValue"), row.names = c(NA, -57L), class = "data.frame")
> 
> fit <- lm(oenb_dependent ~ carReg + cpi + primConstTot + 
+             resProp.Dwell + cbre.office.primeYield + cbre.retail.capitalValue , data = datSel)
> summary(fit) # show results

Call:
lm(formula = oenb_dependent ~ carReg + cpi + primConstTot + resProp.Dwell + 
    cbre.office.primeYield + cbre.retail.capitalValue, data = datSel)

Residuals:
   Min     1Q Median     3Q    Max 
-5.166 -1.447 -0.162  1.448  7.903 

Coefficients:
                          Estimate Std. Error t value Pr(>|t|)    
(Intercept)               0.831630   0.492297    1.69    0.097 .  
carReg                    0.085208   0.039600    2.15    0.036 *  
cpi                      -0.349192   0.212044   -1.65    0.106    
primConstTot              0.752772   0.383810    1.96    0.055 .  
resProp.Dwell             0.994356   0.086812   11.45  1.4e-15 ***
cbre.office.primeYield    1.274734   1.212782    1.05    0.298    
cbre.retail.capitalValue  0.000528   0.000643    0.82    0.416    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2.24 on 50 degrees of freedom
Multiple R-squared:  0.754, Adjusted R-squared:  0.725 
F-statistic: 25.6 on 6 and 50 DF,  p-value: 1.2e-13

I tried the following:

vals.multipleRegr <- forecast(fit, h = 20)
Error: could not find function "forecast"

However, this does not work as the function forecast cannot be found. I am using the following packages in my code, library(bootstrap), library(DAAG) and library(relaimpo).

Any suggestion how to forecasting using multiple regression?

I appreciate your replies!

$\endgroup$
4
  • 2
    $\begingroup$ You can use the function predict instead, no calls for a new library are needed. But you need to supply new values of the independent variables to be able to predict the values of the dependent variable. If the dep. and indep. variables in the model are contemporaneous, you will not be able to forecast the future. You need a model where lagged values of indep. variables would match contemporaneous values of the dep. variable; then you can forecast the future. $\endgroup$ Commented Aug 10, 2015 at 14:25
  • $\begingroup$ @RichardHardy Thx for your answer! Is it also possible to see the period of the forecast for each point forecasted value? Atm I am only get the values back.... $\endgroup$
    – Carol.Kar
    Commented Aug 10, 2015 at 14:29
  • $\begingroup$ @RichardHardy Thx for updating your answer! From my data atm, which variables would you choose for a multiple regression. It is hard for me to see this out of my data? Or: which tests should I be looking for to check for a lag? $\endgroup$
    – Carol.Kar
    Commented Aug 10, 2015 at 14:31
  • 1
    $\begingroup$ I figured my comment qualifies as an aswer to the original question, so I posted it as such. Regarding your questions in the comments, the second one qualifies as a separate question. The first one should be "yes", I suppose. Try reading the documentation for the predict.lm function. $\endgroup$ Commented Aug 10, 2015 at 16:36

1 Answer 1

1
$\begingroup$

You can use the function predict instead, no calls for a new library are needed. But you need to supply new values of the independent variables to be able to predict the values of the dependent variable.

If the dep. and indep. variables in the model are contemporaneous, you will not be able to forecast the future. You need a model where lagged values of indep. variables are used to model contemporaneous values of the dep. variable. You can then forecast the future by using the latest available values of the indep. variables to obtain a prediction for the future value of the dep. variable.

For example, if

$$y_t= X_t\beta+\varepsilon_t$$

you have a contemporaneous model. The "predictions" of $y_t$ are $\hat y_t=X_t \beta$. Obviously, without having $X_{t+h}$ (as of time $t$) you are not able to get the prediction $\hat y_{t+h}$ for any $h>0$.

On the other hand, if

$$y_t= X_{t-k}\beta+\varepsilon_t$$

you have a model where lagged values of $X_t$ are used to model contemporaneous values of $y_t$. Given such a model, "predictions" of $y_t$ are available $k$ periods ahead: $\hat y_{t+h}=X_{t-k+h} \beta$, and $X_{t-k+h}$ is available (as of time $t$) for all $k \leqslant h$.

$\endgroup$
2
  • $\begingroup$ Thx for this great reply! However, I was wondering, how to find such lagged variables, which are ahead of the dependent variable? Any good statistical tests/methods etc. you could recommend? I would also appreciate paper suggestions!!! $\endgroup$
    – Carol.Kar
    Commented Aug 10, 2015 at 18:22
  • $\begingroup$ See the answer here. $\endgroup$ Commented Aug 10, 2015 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.