Line of code won't run on Version 3.5.1 but did on 3.4.0

Since getting the new version of R, I'm getting stuck on a line of code that used to run without error.

MAGAMM <- rwf(ky_data.MAGA[,6],h=41,drift=T,level=c(90,95),fan = FALSE,lambda = NULL)
Error in stats::arima(x = x, order = order, seasonal = seasonal, xreg = xreg, :
lengths of 'x' and 'xreg' do not match

"rwf" is from the forecast library, but I can't find any information online about other people having this issue. I have had a colleague run the exact same step on his machine which is still running 3.4.0 and it worked. Anyone have an idea of how to fix this?

Thanks!

I've not had this exact issue, but I have had weird issues in the past caused by upgrading R and not updating all my packages. Any chance your packages are out of date?

I'm using a new computer which is why I have the updated R Studio version, so all the packages were installed for the first time with the 3.5.1 version.

can you run a simple example rwf script such as this:

library(forecast)
gold.fcast <- rwf(gold[1:60], h=50)
plot(gold.fcast)

Yep that ran, leads me to believe it is a table issue, but that wouldn't corroborate the fact that the exact same code runs on another computer right?

what does ky_data.MAGA[,6] look like? Can you create fake data of the same dimension and run rwf? For example, I don't know anything about your data so I created a 10x60 matrix full of random values then used the same logic you used, and it ran:

library(forecast)

m <- matrix(data=rnorm(60),nrow=10,ncol=6)
m[,6]
#>  [1] -0.9322692  0.3841381  0.4401088 -0.3403564 -0.6407844  0.6065468
#>  [7] -1.1301758  1.4890970 -1.0470580 -0.4042256

rwf(m[,6],h=41,drift=T,level=c(90,95),fan = FALSE,lambda = NULL)
#>    Point Forecast      Lo 90     Hi 90      Lo 95     Hi 95
#> 11   -0.345554131  -3.117825  2.426716  -3.648918  2.957810
#> 12   -0.286882624  -4.379882  3.806117  -5.163992  4.590227
#> 13   -0.228211118  -5.443715  4.987292  -6.442867  5.986445
#> 14   -0.169539612  -6.417098  6.078019  -7.613965  7.274886
#> 15   -0.110868106  -7.338881  7.117145  -8.723577  8.501841
#> 16   -0.052196600  -8.227650  8.123257  -9.793850  9.689457
#> 17    0.006474907  -9.093722  9.106672 -10.837078 10.850028
#> 18    0.065146413  -9.943390 10.073683 -11.860760 11.991053
#> 19    0.123817919 -10.780754 11.028390 -12.869781 13.117417
#> 20    0.182489425 -11.608620 11.973599 -13.867484 14.232463
#> 21    0.241160931 -12.428981 12.911303 -14.856244 15.338566
#> 22    0.299832437 -13.243299 13.842964 -15.837804 16.437469
#> 23    0.358503944 -14.052673 14.769681 -16.813472 17.530480
#> 24    0.417175450 -14.857944 15.692295 -17.784253 18.618603
#> 25    0.475846956 -15.659773 16.611467 -18.750930 19.702624
#> 26    0.534518462 -16.458682 17.527719 -19.714129 20.783166
#> 27    0.593189968 -17.255092 18.441472 -20.674349 21.860729
#> 28    0.651861475 -18.049345 19.353068 -21.632001 22.935724
#> 29    0.710532981 -18.841725 20.262791 -22.587419 24.008485
#> 30    0.769204487 -19.632465 21.170874 -23.540884 25.079293
#> 31    0.827875993 -20.421762 22.077514 -24.492630 26.148382
#> 32    0.886547499 -21.209783 22.982878 -25.442854 27.215949
#> 33    0.945219006 -21.996668 23.887106 -26.391725 28.282163
#> 34    1.003890512 -22.782538 24.790319 -27.339388 29.347169
#> 35    1.062562018 -23.567499 25.692623 -28.285966 30.411090
#> 36    1.121233524 -24.351640 26.594107 -29.231567 31.474034
#> 37    1.179905030 -25.135040 27.494850 -30.176286 32.536096
#> 38    1.238576537 -25.917769 28.394922 -31.120205 33.597358
#> 39    1.297248043 -26.699886 29.294382 -32.063394 34.657891
#> 40    1.355919549 -27.481445 30.193284 -33.005920 35.717759
#> 41    1.414591055 -28.262494 31.091676 -33.947836 36.777019
#> 42    1.473262561 -29.043074 31.989599 -34.889195 37.835720
#> 43    1.531934067 -29.823224 32.887092 -35.830041 38.893909
#> 44    1.590605574 -30.602976 33.784187 -36.770413 39.951624
#> 45    1.649277080 -31.382362 34.680916 -37.710348 41.008903
#> 46    1.707948586 -32.161408 35.577305 -38.649879 42.065776
#> 47    1.766620092 -32.940139 36.473379 -39.589034 43.122275
#> 48    1.825291598 -33.718578 37.369161 -40.527841 44.178424
#> 49    1.883963105 -34.496744 38.264670 -41.466323 45.234249
#> 50    1.942634611 -35.274655 39.159925 -42.404502 46.289771
#> 51    2.001306117 -36.052330 40.054942 -43.342398 47.345010

This is what it looks like with dummy variable and data:

SUM_of_ASDGH_JKL

1 11760.
2 11690.
3 11782.
4 11696.
5 11677.
6 11689.
7 11044.
8 11964.
9 11849.
10 11260.

... with 28 more rows

can you run str(ky_data.MAGA) so we can see what type of object that is?

This is a silly question but what part of that output would indicate the object?

well that depends on what type of object it is. Here's an example with my m matrix above and then converting that to a data.frame:


m <- matrix(data=rnorm(60),nrow=10,ncol=6)

str(m)
#>  num [1:10, 1:6] -1.564 1.939 1.966 -0.388 0.917 ...


m_df <- data.frame(m)

str(m_df)
#> 'data.frame':    10 obs. of  6 variables:
#>  $ X1: num  -1.564 1.939 1.966 -0.388 0.917 ...
#>  $ X2: num  1.131 0.174 1.032 -0.029 1.71 ...
#>  $ X3: num  -0.00509 1.01644 1.01758 -0.29525 -1.43592 ...
#>  $ X4: num  -0.6087 -0.7947 2.0995 -0.0696 -1.9768 ...
#>  $ X5: num  0.744 2.364 -1.113 -0.505 2.144 ...
#>  $ X6: num  1.058 0.714 -0.705 1.037 0.657 ...

for an unlabeled matrix like m the output is num [1:10, 1:6] which tells us it's a matrix of shape 10 x 6. The data.frame reports 'data.frame': 10 obs. of 6 variables: which is a bit more obvious.