Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 209819

Error using predict() on a bsts object in R: incompatible covariates in GlmCoefs::predict

$
0
0

I'm training a forecasting model using the bsts package in R. No matter what number of covariates I include in the model, I'm getting the following error:

I'm not having any other problems with my bsts object. Here is how I'm training the model:

# BSTS
train = train_all[1:train_length,]
y = train[,outcome]
X = train[,!(names(train) %in% c("Date", outcome))]

# remove input columns with NA
has_na <- colSums(is.na(X)) > 0
X <- X[,!has_na]
feats <- colnames(X)

ss = AddStudentLocalLinearTrend(list(), y)
b = bsts(y ~ .,
         state.specification = ss,
         data = X,
         niter = 1000,
         family = "student",
         expected.model.size = 8)


burn <- SuggestBurn(0.1, b)
newdata = as.data.frame(train_all[(train_length+1),feats])
predict(b, newdata = newdata, burn = burn, na.action = na.exclude)

In the predict call, I'm using the next row of the exogenous variables (analogously the first row of the 'test' set) to make a one-step ahead prediction. This is where I'm getting the following error:

>   predict(b, newdata = newdata, burn = burn, na.action = na.exclude)
Error in predict.bsts(b, newdata = newdata, burn = burn, na.action = na.exclude) : 
  Caught exception with the following error message: 
incompatible covariates in GlmCoefs::predict
beta = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6.18227 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1.22078 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.611854 0 0 0 0 0 0 0
x = 1 

I've been googling everything I can think of to find some information on what this error is, but I can't find anything. Does anyone know what this error means or how I can fix it?


Viewing all articles
Browse latest Browse all 209819

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>