Error in data.model %*% model$coef : non-conformable arguments

21 Views Asked by At

i hope you are well. I am modelling a logit regression but there is an error in my code. Every time I run the model I get this: Error in data.model %*% model$coef : non-conformable arguments. Could you help me with this? Thanks in advance.

Please see my code:

library(devtools)
library(mlogit)
library(dfidx)# install and add a column with unique question numbers, as needed in mlogit 1.1+
cbc.df$chid <- rep(1:(nrow(cbc.df)/3), each=3)
cbc.mlogit <- dfidx(cbc.df, choice="choice", idx=list(c("chid", "resp.id"), "alt" )) # shape the data for mlogit

m1 <- mlogit(choice ~ 0 + cereal_label + bill + quantity + price, data = cbc.mlogit)
summary(m1) 
m2 <- mlogit(choice ~ cereal_label + bill + quantity + price, data = cbc.mlogit)
summary(m2) 
m3 <- mlogit(choice ~ cereal_label + bill + quantity + as.numeric(as.character(price)), data = cbc.mlogit)
summary(m2)

lrtest(m1, m2, m3)

predict.mnl <- function(model, data) {
  data.model <- model.matrix(update(model$formula, 0 ~ .), data = data) [, -1]
  utility <- data.model %*% model$coef
  share <- exp(utility) / sum(exp(utility))
  cbind(share, data)
}

(new.data <- expand.grid(attrib) [c(8, 1, 3, 41, 49, 26), ])
predict.mnl(m3, new.data)
Error in data.model %*% model$coef : non-conformable arguments

I have to find the solution to this error.

0

There are 0 best solutions below