[R] resolving expand.grid & NA errors

Andrew Robinson A.Robinson at ms.unimelb.edu.au
Sun Mar 25 22:46:29 CEST 2007


Hi Bob,

I'm not sure that na.rm is a valid action inside multinom.  Try
removing the missing values before fitting, or use
na.action=na.exclude (or na.action=na.omit) inside multinom instead.

If that doesn't help, then please try to send a commented, minimal,
self-contained, reproducible example.

Cheers,

Andrew

On Mon, Mar 26, 2007 at 06:29:43AM +1000, Bob Green wrote:
> I am hoping for some advice regarding resolving error messages I have 
> received when trying to use the expand.grid command.
> 
> library(nnet)
> library(MASS)
> library(car)
> mod.multacute <-multinom(kc$group ~ kc$in.acute.danger * 
> kc$violent.convictions, na.rm=T)
> summary(mod.multacute, cor=F, Wald=T)
> Anova (mod.multacute)
> confint (mod.multacute)
> 
>  > predictors <- expand.grid(group=1:3, in.acute.danger = c("y","n"), 
> violent.convictions = c("y","n"))
>  > p.fit <- predict(mod.multacute, predictors, type='probs')
> Error in predict.multinom(mod.multacute, predictors, type = "probs") :
>          NAs are not allowed in subscripted assignments
> In addition: Warning message:
> 'newdata' had 12 rows but variable(s) found have 160 rows
> 
> There are two errors - the NA error which I thought would have been 
> removed in line 3 above. I also tried ra.omit.
> I know there will be a difference between the raw data and the new 
> data but do not know what I need to change to be able to successfully 
> run the command.
> 
> What I want to do is obtain the fitted probabilities and plot them.
> 
> Any suggestions are appreciated,
> 
> Bob Green
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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.

-- 
Andrew Robinson  
Department of Mathematics and Statistics            Tel: +61-3-8344-9763
University of Melbourne, VIC 3010 Australia         Fax: +61-3-8344-4599
http://www.ms.unimelb.edu.au/~andrewpr
http://blogs.mbs.edu/fishing-in-the-bay/



More information about the R-help mailing list