Yves
2003-Dec-18 21:16 UTC
[R] Help with predict.Arima with external regressor values [Repalced]
Hi all there I am enjoying R since 2 weeks and I come to my first deadlock, il am trying to use predict.Arima in the ts package. I get a "Error in cbind(...) : cannot create a matrix from these types" -- Start R session -----------------------------------------------------> fitdiv <- arima(data, c(2, 0, 3), xreg = y ) ; print(fitdiv)Call: arima(x = data, order = c(2, 0, 3), xreg = y) Coefficients: ar1 ar2 ma1 ma2 ma3 intercept EUSA1 EUSA10 EUSA15 EUSA20 EUSA5 H15T10Y H15T1Y H15T20Y H15T3M H15T5Y USSW10 -0.001 0.6502 0.3328 -0.5021 -0.1135 -0.0535 0.0469 0.0075 -0.0263 0.0299 -0.0344 0.1012 -0.0382 0.0092 0.0385 -0.0757 -0.1577 s.e. 0.523 0.4002 0.5262 0.2711 0.0828 0.1027 0.0308 0.0802 0.0931 0.0743 0.0414 0.0469 0.0215 0.0360 0.0276 0.0344 0.0477 USSW15 USSW20 USSW30 USSW5 CAC.INDEX DAX.INDEX MIB30.INDEX OMX.INDEX SX5P.INDEX UKX.INDEX VDAX.INDEX VIX.INDEX 0.0254 -0.0141 0.0133 0.1186 -0.1816 0.0652 0.0848 -0.1836 0.1134 -0.1742 0.0236 -0.0482 s.e. 0.0588 0.0251 0.0363 0.0278 0.0907 0.0528 0.0860 0.0516 0.1518 0.1025 0.0591 0.0470 sigma^2 estimated as 1.258: log likelihood = -762.3, aic = 1584.59> > fordiv <- predict(fitdiv, n.ahead = 1, newxreg = newregy , se.fit = TRUE)Error in cbind(...) : cannot create a matrix from these types> > > str(data)num [1:497] -0.34 -1.36 -0.5 -0.46 0.01 0.1 0.68 0.06 0.16 0.48 ...> > str(newregy)num [1, 1:23] -0.6 -0.3 0.15 1.08 -1.8 3 2 3 0 5 ... - attr(*, "dimnames")=List of 2 ..$ : chr "498" ..$ : chr [1:23] "EUSA1" "EUSA10" "EUSA15" "EUSA20" ...> > str(y)`data.frame': 497 obs. of 23 variables: $ EUSA1 : num 0.7 5.9 -0.6 1.8 5.7 1.9 0.5 -6.6 2.5 2.3 ... $ EUSA10 : num -4.5 3.8 -11.7 3.2 4.2 -5.4 -2.2 -6.5 0.8 2 ... $ EUSA15 : num -5.4 3.6 -11 3.7 3.4 -4.3 -3.9 -4.7 0.3 2.6 ... $ EUSA20 : num -5 3.6 -10.8 4.3 2.3 -4.1 -3.5 -5 0 3.1 ... $ EUSA5 : num -4.3 5.4 -10.8 2.5 6.3 -2.4 -1.3 -6.6 2.3 -0.2 ... $ H15T10Y : num -4 2 -9 1 0 -10 -8 -1 -3 0 ... $ H15T1Y : num -4 1 -6 0 -2 -7 -12 2 -1 2 ... $ H15T20Y : num -3 4 -11 1 -1 -12 -4 2 -6 2 ... $ H15T3M : num -1 -1 -4 0 0 0 -10 0 2 1 ... $ H15T5Y : num -4 2 -11 0 -1 -11 -13 1 -1 2 ... $ USSW10 : num -8.6 0.6 -10.5 2.4 -2.9 -5.8 -15 0.4 -3.5 1 ... $ USSW15 : num -7.9 1.1 -9.8 2 -3.1 -5.8 -13.2 2 -4.4 2.1 ... $ USSW20 : num -6.7 1.4 -9.5 1.3 -3 -6 -11 1.2 -4.2 2.9 ... $ USSW30 : num -6.2 1.3 -8.4 1.6 -2.6 -6.9 -8.5 -0.9 -2.8 2.2 ... $ USSW5 : num -7.7 -0.4 -12.7 0.9 -4 -7.4 -17.5 0.9 0.3 1.6 ... $ CAC.INDEX : num 2.18 0.03 -1.45 -1.03 0.41 -1.57 0.86 -2.24 1.44 -2.08 ... $ DAX.INDEX : num 1.96 0.91 -1.64 0.08 0.99 -1.14 -0.35 -2.81 -0.08 -1.55 ... $ MIB30.INDEX: num 2.08 -0.48 -0.94 0.82 0.22 -2.22 0.8 -2.5 1.34 -1.35 ... $ OMX.INDEX : num 4.07 0.28 -0.56 -2.47 -0.16 -1.58 1.13 -3.5 -1.15 -1.85 ... $ SX5P.INDEX : num 1.95 0.1 -1.22 -1.01 -0.31 -0.96 0.84 -2.71 1.18 -1.05 ... $ UKX.INDEX : num 1.91 0.09 -0.57 -0.82 -0.42 -0.73 0.15 -1.65 1.02 -0.75 ... $ VDAX.INDEX : num -1.59 -0.74 0.73 -0.36 -0.36 0.87 -0.51 1.64 -0.02 0.85 ... $ VIX.INDEX : num -1.37 -0.89 1.22 0.16 0.3 -0.1 0.57 0.98 -0.88 0.75 ...> > fordiv <- predict(fitdiv, n.ahead = 1, newxreg = matrix(0,1,23) , se.fit= TRUE) Error in cbind(...) : cannot create a matrix from these types>-- End R session ----------------------------------------------------- I also tried to replace newregy by a matrix of zeros matrix(0,1,23) Please tell if I am doing something wrong ... I did not see any example in the help about external regressor so I had to start from scratch. Best regards Yves Oloui.
Prof Brian Ripley
2003-Dec-19 03:47 UTC
[R] Help with predict.Arima with external regressor values [Repalced]
First, xreg is documented as a vector or matrix, not a data frame. Second, there may be a scoping problem, so try a more informative name than `y' when you do the fit. Third, R has debugging facilities, so please use them to find out precisely what is wrong. On Thu, 18 Dec 2003, Yves wrote:> > Hi all there > > I am enjoying R since 2 weeks and I come to my first deadlock, il am trying > to use predict.Arima in the ts package. > I get a "Error in cbind(...) : cannot create a matrix from these types" > > -- Start R session ----------------------------------------------------- > > > fitdiv <- arima(data, c(2, 0, 3), xreg = y ) ; print(fitdiv) > > Call: > arima(x = data, order = c(2, 0, 3), xreg = y) > > Coefficients: > ar1 ar2 ma1 ma2 ma3 intercept EUSA1 EUSA10 > EUSA15 EUSA20 EUSA5 H15T10Y H15T1Y H15T20Y H15T3M H15T5Y USSW10 > -0.001 0.6502 0.3328 -0.5021 -0.1135 -0.0535 0.0469 > 0.0075 -0.0263 0.0299 -0.0344 0.1012 -0.0382 0.0092 > 0.0385 -0.0757 -0.1577 > s.e. 0.523 0.4002 0.5262 0.2711 0.0828 0.1027 0.0308 0.0802 > 0.0931 0.0743 0.0414 0.0469 0.0215 0.0360 0.0276 0.0344 0.0477 > USSW15 USSW20 USSW30 USSW5 CAC.INDEX DAX.INDEX MIB30.INDEX > OMX.INDEX SX5P.INDEX UKX.INDEX VDAX.INDEX VIX.INDEX > 0.0254 -0.0141 0.0133 0.1186 -0.1816 0.0652 > 0.0848 -0.1836 0.1134 -0.1742 0.0236 -0.0482 > s.e. 0.0588 0.0251 0.0363 0.0278 0.0907 0.0528 0.0860 > 0.0516 0.1518 0.1025 0.0591 0.0470 > > sigma^2 estimated as 1.258: log likelihood = -762.3, aic = 1584.59 > > > > fordiv <- predict(fitdiv, n.ahead = 1, newxreg = newregy , se.fit = TRUE) > Error in cbind(...) : cannot create a matrix from these types > > > > > > str(data) > num [1:497] -0.34 -1.36 -0.5 -0.46 0.01 0.1 0.68 0.06 0.16 0.48 ... > > > > str(newregy) > num [1, 1:23] -0.6 -0.3 0.15 1.08 -1.8 3 2 3 0 5 ... > - attr(*, "dimnames")=List of 2 > ..$ : chr "498" > ..$ : chr [1:23] "EUSA1" "EUSA10" "EUSA15" "EUSA20" ... > > > > str(y) > `data.frame': 497 obs. of 23 variables: > $ EUSA1 : num 0.7 5.9 -0.6 1.8 5.7 1.9 0.5 -6.6 2.5 2.3 ... > $ EUSA10 : num -4.5 3.8 -11.7 3.2 4.2 -5.4 -2.2 -6.5 0.8 2 ... > $ EUSA15 : num -5.4 3.6 -11 3.7 3.4 -4.3 -3.9 -4.7 0.3 2.6 ... > $ EUSA20 : num -5 3.6 -10.8 4.3 2.3 -4.1 -3.5 -5 0 3.1 ... > $ EUSA5 : num -4.3 5.4 -10.8 2.5 6.3 -2.4 -1.3 -6.6 2.3 -0.2 ... > $ H15T10Y : num -4 2 -9 1 0 -10 -8 -1 -3 0 ... > $ H15T1Y : num -4 1 -6 0 -2 -7 -12 2 -1 2 ... > $ H15T20Y : num -3 4 -11 1 -1 -12 -4 2 -6 2 ... > $ H15T3M : num -1 -1 -4 0 0 0 -10 0 2 1 ... > $ H15T5Y : num -4 2 -11 0 -1 -11 -13 1 -1 2 ... > $ USSW10 : num -8.6 0.6 -10.5 2.4 -2.9 -5.8 -15 0.4 -3.5 1 ... > $ USSW15 : num -7.9 1.1 -9.8 2 -3.1 -5.8 -13.2 2 -4.4 2.1 ... > $ USSW20 : num -6.7 1.4 -9.5 1.3 -3 -6 -11 1.2 -4.2 2.9 ... > $ USSW30 : num -6.2 1.3 -8.4 1.6 -2.6 -6.9 -8.5 -0.9 -2.8 2.2 ... > $ USSW5 : num -7.7 -0.4 -12.7 0.9 -4 -7.4 -17.5 0.9 0.3 1.6 ... > $ CAC.INDEX : num 2.18 0.03 -1.45 -1.03 0.41 -1.57 0.86 -2.24 1.44 -2.08 > ... > $ DAX.INDEX : num 1.96 0.91 -1.64 0.08 0.99 -1.14 -0.35 -2.81 -0.08 -1.55 > ... > $ MIB30.INDEX: num 2.08 -0.48 -0.94 0.82 0.22 -2.22 0.8 -2.5 1.34 -1.35 > ... > $ OMX.INDEX : num 4.07 0.28 -0.56 -2.47 -0.16 -1.58 1.13 -3.5 -1.15 -1.85 > ... > $ SX5P.INDEX : num 1.95 0.1 -1.22 -1.01 -0.31 -0.96 0.84 -2.71 1.18 -1.05 > ... > $ UKX.INDEX : num 1.91 0.09 -0.57 -0.82 -0.42 -0.73 0.15 -1.65 1.02 -0.75 > ... > $ VDAX.INDEX : num -1.59 -0.74 0.73 -0.36 -0.36 0.87 -0.51 1.64 -0.02 0.85 > ... > $ VIX.INDEX : num -1.37 -0.89 1.22 0.16 0.3 -0.1 0.57 0.98 -0.88 0.75 ... > > > > fordiv <- predict(fitdiv, n.ahead = 1, newxreg = matrix(0,1,23) , se.fit > = TRUE) > Error in cbind(...) : cannot create a matrix from these types > > > > -- End R session ----------------------------------------------------- > > I also tried to replace newregy by a matrix of zeros matrix(0,1,23) > > Please tell if I am doing something wrong ... I did not see any example in > the help about external regressor so I had to start from scratch. > > Best regards > > Yves Oloui. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595