[R] Problem with effects package
John Fox
jfox at mcmaster.ca
Sat Jul 30 23:33:04 CEST 2011
Dear Lars,
The problem is the ":" in the levels of var2, which confuses effect() about
the structure of the model, since a colon indicates interaction. Try, e.g.,
removing the colons:
var2 <- as.factor(c("B=500", "B=500", "B=500", "B=500", "B=500", "B=500",
"B=500", "B=500",
"B=500", "C750-1000", "C750-1000", "B=500", "B=500",
"B=500", "B=500"))
Then,
> effect("var2", glm1)
var2 effect
var2
B=500 C750-1000
7947.932 13453.841
(See how helpful it can be to furnish a reproducible example?)
I agree, BTW, that this is a deficiency in effect(); I'll look into it when
I have a chance.
Finally, there really is no advantage to making an effect display for a
model with a single predictor, though perhaps this isn't what you were doing
in your actual application.
Best,
John
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Lars Bishop
> Sent: July-30-11 4:30 PM
> To: jim holtman; r-help at r-project.org
> Subject: Re: [R] Problem with effects package
>
> ok. Here's an example:
>
> R version 2.11.1
> effects_2.0-10
>
> var1 <- c(25631.9392, 2521.2590, 6656.6516, 1362.5997, 6369.9818,
> 27253.4223, 2073.1909, 9959.3792,
> 3318.2500, 15323.8103, 11583.8717, 3054.5558, 625.6597,
> 2500.0000, 11996.2271)
> var2 <- as.factor(c("B:=500", "B:=500", "B:=500", "B:=500", "B:=500",
> "B:=500", "B:=500", "B:=500",
> "B:=500", "C:750-1000", "C:750-1000", "B:=500",
> "B:=500", "B:=500", "B:=500"))
>
> glm1 <- glm(var1 ~ var2, family = Gamma(link = "log"))
> summary(glm1)
> library(effects)
> plot(effect("var2", glm1))
>
> Error in apply(mod.matrix[, components], 1, prod) :
> subscript out of bounds
> Error in plot(effect("var2", glm1)) :
> error in evaluating the argument 'x' in selecting a method for
> function 'plot'
> >
>
>
> On Sat, Jul 30, 2011 at 3:10 PM, jim holtman <jholtman at gmail.com> wrote:
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> > We can not help unless we at least have the data that you are using.
> >
> > On Sat, Jul 30, 2011 at 3:01 PM, Lars Bishop <lars52r at gmail.com>
> wrote:
> >> Dear List,
> >>
> >> Several times I use this package I get the error message shown below.
> >> When I work out simple examples, it turns out to be fine, but when
> >> working with real and moderate size data sets I always get the same
> >> error.
> >>
> >> Do you know what could be the cause of the problem?
> >>
> >>
> >> Error in apply(mod.matrix[, components], 1, prod) :
> >> subscript out of bounds
> >> Error in plot(effect("myvariable", glm.sev1)) :
> >> error in evaluating the argument 'x' in selecting a method for
> >> function 'plot'
> >>
> >> Thanks,
> >> Lars/
> >>
> >> ______________________________________________
> >> 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.
> >>
> >
> >
> >
> > --
> > Jim Holtman
> > Data Munger Guru
> >
> > What is the problem that you are trying to solve?
> >
>
> ______________________________________________
> 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