[R] resolving expand.grid & NA errors

Bill.Venables at csiro.au Bill.Venables at csiro.au
Mon Mar 26 00:58:54 CEST 2007


Hi Bob,

Instead of fitting the model as 

> mod.multacute <-multinom(kc$group ~ kc$in.acute.danger * 
>	kc$violent.convictions, na.rm=T)

you might have more success fitting it sa

> mod.multacute <- multinom(group ~ in.acute.danger * 
	violent.convictions, data = kc,  na.action = na.omit)

This separates the variables from the data frame in which they occur.
When you predict with a new data frame, the process will look for
factors "in.acure.danger" and not "kc$in.acute.danger".

Note also that na.rm is not an argument for multinom.  You probably mean
na.action.

I suspect this is the problem, but without the data I can't be sure.

Bill Venables
CSIRO Laboratories
PO Box 120, Cleveland, 4163
AUSTRALIA
Office Phone (email preferred):   +61 7 3826 7251
Fax (if absolutely necessary):      +61 7 3826 7304
Mobile:                                   (I don't have one!)
Home Phone:                            +61 7 3286 7700
mailto:Bill.Venables at csiro.au
http://www.cmis.csiro.au/bill.venables/ 

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Bob Green
Sent: Monday, 26 March 2007 6:30 AM
To: r-help at stat.math.ethz.ch
Subject: [R] resolving expand.grid & NA errors

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.



More information about the R-help mailing list