[R] problem with effects : 'subscript out of bounds'

John Fox jfox at mcmaster.ca
Sat Mar 10 14:35:46 CET 2012


Dear Nicole,

Sorry, I didn't notice the earlier messages in this thread.

Please see below.

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Nicole Marie Ford
> Sent: March-10-12 1:20 AM
> To: r-help
> Subject: Re: [R] problem with effects : 'subscript out of bounds'
> 
> if that is  not specific (or not general) enough:
> 
> newDV <- dat$DV  ## newDV is my DV & it is continuous.
> newDV <- as.numeric(newDV)-5
> str(newDV)
> 
> 
> (i had to do a great deal of coding here so i am snipping down to the
> end)
> 
> 
> tmp[which(dat$v1 == "stuff" & dat$v2 == "more stuff")] <- "lots of
> stuff"
> tmp <- factor(tmp, levels=c("la", "la la", "fa la la"))
> dat$v3 <- tmp
> newIV <- as.factor(dat$v3)  ####  newIV is my IV, a factor as you can
> see.
> 
> n.var4 <- dat$v4 ## control
> 
> n.var5 <- dat$v5  ##control  (there are others but they were coded the
> same)
> 
> 
> n.mod1 <- lm(newDV ~ newIV + v4 + v5 + v6 + v7 + v8 + v9, data=dat)
> ### linear model.  all of these variables already are specific to the
> dataset which i called 'norway' so there is no need to specify in the
> model.
> 
> summary(n.mod1)
> 
> > plot(effect("newIV", n.mod1), multiline=T)
> Error in plot(effect("nor.trust", n.mod1), multiline = T) :
>   error in evaluating the argument 'x' in selecting a method for
> function 'plot': Error in apply(mod.matrix[, components], 1, prod) :
>   subscript out of bounds

This seems very odd: The command given is

  plot(effect("newIV", n.mod1), multiline=T)

but the error message is apparently for 

  plot(effect("nor.trust", n.mod1), multiline = T)

and nor.trust isn't a variable in the model. What command did you execute?

Although it's not relevant to the error, there's no point in setting
multiline=TRUE for a model without interactions.

Best,
 John

--------------------------------
John Fox
Senator William McMaster
  Professor of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox


> 
> 
> ~~this ran perfectly on my previous dataset so i am unsure of the
> issue.  thanks in advance.
> 
> ______________________________________________
> 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.
> 
> ______________________________________________
> 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.



More information about the R-help mailing list