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!
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$predict.lm
function. $\endgroup$