2
$\begingroup$

If I execute the following code I have no problem:

require(foreign)
require(nnet)
require(ggplot2)
require(reshape2)

ml <- read.dta("https://stats.idre.ucla.edu/stat/data/hsbdemo.dta")
ml$prog2 <- relevel(ml$prog, ref = "academic")
test <- multinom(prog2 ~ ses + write, data = ml)
predict(test, newdata = dses, "probs")

but if I try:

require(caret)
ml <- read.dta("http://www.ats.ucla.edu/stat/data/hsbdemo.dta")
ml$prog2 <- relevel(ml$prog, ref = "academic")
test <- train(prog2 ~ ses + write,method="multinom" ,data = ml)
predict(test$finalModel, newdata = dses, "probs")

it returns Error in eval(expr, envir, enclos) : object 'sesmiddle' not found, why?

$\endgroup$
2
$\begingroup$

That's not the error I get and I'm thinking that you left out some code. I get:

predict(test$finalModel, newdata = dses, "probs")
Error in as.data.frame(newdata) : object 'dses' not found

I don't know why I see this so much, but you should avoid using the finalModel object for prediction. train is doing some things that the model from multinom sin't aware of (such as expanding dummy variables). Try using

predict(test, newdata = dses, "probs")

and never use predict(test$finalModel) again...

Max

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ @RobertoDotti, then mark the question as answered (and post your answer if topepo's wasn't what you did)? $\endgroup$ – TheGrimmScientist Jan 9 '15 at 1:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.