Predict methods for objects with class attribute tvlm
, tvar
,
tvvar
, tvirf
, tvsure
and tvplm
. This function needs new values of
variables y (response), x (regressors), exogen (exogenous variables, when used),
and z (smoothing variable).
# S3 method for tvlm predict(object, newdata, newz, ...) # S3 method for tvar predict(object, newdata, newz, newexogen = NULL, ...) # S3 method for tvvar predict(object, newdata, newz, newexogen = NULL, ...) # S3 method for tvsure predict(object, newdata, newz, ...) # S3 method for tvplm predict(object, newdata, newz, ...)
object | An object used to select a method. |
---|---|
newdata | A pdata.frame with new values of all regressors, with the same name and order as they appear in argument 'data' from the 'tvplm' object |
newz | A vector with new values of the smoothing variable. |
... | Other arguments passed to specific methods. |
newexogen | A matrix or vector with the new value of the exogenous variables. Only for predictions of 'tvar' and 'tvvar' objects. |
An object of class matrix or vector with the prediction.
## Example of TVLM prediction with coefficients as ## functions of the realized quarticity data("RV") RV2 <- head(RV, 2001) z <- RV2$RQ_lag_sqrt TVHARQ <- tvLM (RV ~ RV_lag + RV_week + RV_month, z = z, data = RV2, bw = 0.0062) newdata <- cbind(RV$RV_lag[2002:2004], RV$RV_week[2002:2004], RV$RV_month[2002:2004]) newz <- RV$RQ_lag_sqrt[2002:2004] predict(TVHARQ, newdata, newz)#> [1] 1.781073e-05 1.926774e-05 2.705291e-05## Example of TVAR prediction with coefficients as ## functions of the realized quarticity data("RV") RV2 <- head(RV, 2001) exogen = RV2[, c("RV_week", "RV_month")] TVHARQ2 <- tvAR (RV2$RV, p = 1, exogen = exogen, z = RV2[, "RQ_lag_sqrt"], bw = 0.0062) newylag <- RV$RV[2002:2004] newz <- RV$RQ_lag_sqrt[2002:2004] newexogen <- RV[2002:2004, c("RV_week", "RV_month")] predict(TVHARQ2, newylag, newz, newexogen = newexogen)#> [1] 1.930648e-05 2.597139e-05 2.642790e-05## Example of TVVAR prediction with coefficients as ## functions of a random ARMA (2,2) process data(usmacro, package = "bvarsv") smoothing <- arima.sim(n = NROW(usmacro) + 3, list(ar = c(0.8897, -0.4858), ma = c(-0.2279, 0.2488)), sd = sqrt(0.1796)) smoothing <- as.numeric(smoothing) TVVAR.z <- tvVAR(usmacro, p = 6, type = "const", z = smoothing[1:NROW(usmacro)], bw = c(16.3, 16.3, 16.3)) newdata <- data.frame(inf = c(2, 1, 6), une = c(5, 4, 9), tbi = c(1, 2.5, 3)) newz <- c(0, 1.2, -0.2) predict(TVVAR.z, newdata = newdata, newz = newz)#> inf une tbi #> [1,] 0.3544131 0.3544131 0.3544131 #> [2,] 4.5063953 4.5063953 4.5063953 #> [3,] -2.1858620 -2.1858620 -2.1858620## Example of TVSURE prediction with coefficients as ## functions of an ARMA(2,2) process data("Kmenta", package = "systemfit") nobs <- NROW (Kmenta) eqDemand <- consump ~ price + income eqSupply <- consump ~ price + farmPrice system <- list(demand = eqDemand, supply = eqSupply) smoothing <- arima.sim(n = nobs + 3, list(ar = c(0.8897, -0.4858), ma = c(-0.2279, 0.2488)), sd = sqrt(0.1796)) smoothing <- as.numeric(smoothing) TVOLS.z <- tvSURE(system, data = Kmenta, z = smoothing[1:nobs], bw = c(7, 1.8), est = "ll") newdata <- data.frame(consump = c(95, 100, 102), price = c(90, 100, 103), farmPrice = c(70, 95, 103), income = c(82, 94, 115)) newz <- tail(smoothing, 3) predict(TVOLS.z, newdata = newdata, newz = newz)#> demand supply #> [1,] 99.11459 94.20937 #> [2,] 99.16312 99.40177 #> [3,] 103.60595 100.81371data(OECD) z <- runif(length(levels(OECD$year)), 10, 15) TVPOLS <- tvPLM(lhe~lgdp+pop65+pop14+public, z = z, index = c("country", "year"), data = OECD, method ="pooling", bw = 2) newdata <- cbind(lgdp = c(10, 13), pop65 = c(9, 12), pop14 = c(17, 30), public = c(13, 20)) newz <- runif(2, 10, 15) predict(TVPOLS, newdata = newdata, newz = newz)#> [1] 7.447127 9.582447