1

I am trying to add the fitted values of my multinomial logistic regression to the original data frame (called "ORDERS"). Unfortunately this is not possible, as apparently the predicted probabilities and the data frame don't have the same length - even though I use na.exclude in the regression. Maybe this has something to do with the necessary mlogit.data transformation, so that na.exclude does not work?

mlModel_refPRE_STD <- mlogit(PAYMENT_METHOD ~ 1 | GROSS_RETAIL_TOTAL_STD + SOLVENCY_SCORE_STD + GENDER + EXISTING_CUSTOMER, data=mlORDERS, reflevel="PRE", na.action=na.exclude)

> ORDERS$predicted.probabilities <- fitted(mlModel_refPRE_STD) #
Error in `$<-.data.frame`(`*tmp*`, "predicted.probabilities", value = c(0.0168546281869084,  : 
  replacement has 129159 rows, data has 129372

> length(mlModel_refPRE_STD$fitted.values)
[1] 129159
> length(ORDERS$SOLVENCY_SCORE_STD)
[1] 129372

(All other variables in the regression also have length 129372)

wimpato
  • 11
  • 3
  • 1
    Could it be that you're working in two different datasets? The model is made on `mlORDERS` and you're trying to add the fitted values to `ORDERS` – Niek Apr 25 '17 at 11:50
  • That's right. But adding fitted values to `mlORDERS` isn't useful and wouldn't work either because of different lengths. `mlORDERS` is a transformed data frame into long format so that it can be used as input for multinomial logistic regression with `mlogit` The difference in length spotted above is exactly the number of missing values (NAs) of one independent variable, but I wonder why the fitted values column is shortened even though I used na.exclude... – wimpato Apr 25 '17 at 15:43

0 Answers0