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
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/
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.