Re: [R] Predict Function

From: hadley wickham <h.wickham_at_gmail.com>
Date: Sat, 12 Apr 2008 16:27:43 -0500

On Sat, Apr 12, 2008 at 1:06 PM, Biago <sgrlfskbm_at_gmail.com> wrote:
>
> Hi all - my first time here and am having an issue with the Predict function.
>
> I am using a tutorial as a guide, locate here:
> http://www.ats.ucla.edu/STAT/R/dae/mlogit.htm
>
> My code gives this error
>
> > newdata1$predicted <- predict(mlogit,newdata=newdata1,type="response")
> Error in `$<-.data.frame`(`*tmp*`, "predicted", value = c(0.332822934960197,
> :
> replacement has 810 rows, data has 6
>
> How can I resolve this problem so I can just predict values for the supplied
> matrix(newdata1) instead of it trying to use my full dataset?
>
> Here is the full code up to this point.
>
>
> library(VGAM)
> mlogit<- vglm(bcsse$Active~bcsse$Impinteg+bcsse$Hsgradyr,
> family=multinomial(), na.action=na.pass)

You probably want:

mlogit<- vglm(Active~Impinteg+Hsgradyr, data = bcsse, family=multinomial(), na.action=na.pass)

Otherwise predict doesn't know how to match up the column names in newdata to the variables used in the model.

Hadley

-- 
http://had.co.nz/

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sat 12 Apr 2008 - 21:30:17 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 12 Apr 2008 - 22:30:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive