[R] effect function in the effects package
John Fox
jfox at mcmaster.ca
Thu Oct 20 20:47:45 CEST 2011
Dear Xu Jun,
On Thu, 20 Oct 2011 14:41:30 -0400
Xu Jun <junxu.r at gmail.com> wrote:
> Dear Professor Fox,
>
> Now I got it. It all comes from my unfamiliarity with the effect
> function. I forgot the c part in the given.values option, plus it
> looks like plot(effect()) does not like factor(warm) in the polr
> function. So here are the two working lines:
>
> ordwarm2$warm2 <- as.factor(ordwarm2$warm)
Without the data, I have no idea what's going on here; the implication is that warm wasn't a factor.
> myologit <- polr(warm2 ~ yr89 + male + white + age + ed + prst,
> data=ordwarm2, method=c("logistic"))
> plot(effect("age", myologit, xlevels=list(age=seq(20, 80, 5)),
> given.values=(c(male=1, yr89=1))))
given.values is an argument. c() is a standard R function for combining values into a vector (or a list); it is not particular to the effects package. The parentheses around (c(male=1, yr89=1)) are entirely unnecessary, and the call to c() in c("logistic") does nothing.
Best,
John
>
> Again, thanks a lot for your effects package that makes graphing so much easier.
>
> Jun
>
> On Thu, Oct 20, 2011 at 11:55 AM, John Fox <jfox at mcmaster.ca> wrote:
> > Dear Xu Jun,
> >
> > I'm not sure whether this is the source of the error, but it may help to spell the xlevels argument correctly (it is not "xlevles").
> >
> > I hope this helps,
> > John
> >
> > ------------------------------------------------
> > John Fox
> > Sen. William McMaster Prof. of Social Statistics
> > Department of Sociology
> > McMaster University
> > Hamilton, Ontario, Canada
> > http://socserv.mcmaster.ca/jfox/
> >
> > On Thu, 20 Oct 2011 10:34:30 -0400
> > Xu Jun <junxu.r at gmail.com> wrote:
> >> Dear r-help listers,
> >>
> >> I am using effects to produce an effect plot after the proportional
> >> odds logistic regression model. There is no problem for me to estimate
> >> the model, but when it comes to the graphing, I was stuck. see the
> >> codes below:
> >>
> >> ##############################################################################
> >> myologit <- polr(factor(warm) ~ yr89 + male + white + age + ed + prst,
> >> + data=ordwarm2, method=c("logistic"))
> >>
> >> require(effects)
> >> plot(effect("age", myologit, xlevles=list(age=seq(20, 80, 5),
> >> given.values(male=1, yr89=1))))
> >>
> >> ##############################################################################
> >>
> >> I got the following error message:
> >>
> >> Warning message:
> >> package 'effects' was built under R version 2.13.2
> >> Error in plot(effect("age", myologit, xlevles = list(age = seq(20, 80, :
> >> error in evaluating the argument 'x' in selecting a method for
> >> function 'plot': Error in model.frame.default(formula = factor(warm) ~
> >> yr89 + male + white + :
> >> variable lengths differ (found for 'yr89')
> >>
> >>
> >> the full set of codes:
> >>
> >> > myologit <- polr(factor(warm) ~ yr89 + male + white + age + ed + prst,
> >> + data=ordwarm2, method=c("logistic"))
> >>
> >> > summary(myologit)
> >>
> >> Re-fitting to get Hessian
> >>
> >> Call:
> >> polr(formula = factor(warm) ~ yr89 + male + white + age + ed +
> >> prst, data = ordwarm2, method = c("logistic"))
> >>
> >> Coefficients:
> >> Value Std. Error t value
> >> yr89 0.523912 0.079899 6.557
> >> male -0.733309 0.078483 -9.344
> >> white -0.391140 0.118381 -3.304
> >> age -0.021666 0.002469 -8.777
> >> ed 0.067176 0.015975 4.205
> >> prst 0.006072 0.003293 1.844
> >>
> >> Intercepts:
> >> Value Std. Error t value
> >> 1|2 -2.4654 0.2389 -10.3188
> >> 2|3 -0.6309 0.2333 -2.7042
> >> 3|4 1.2618 0.2340 5.3919
> >>
> >> Residual Deviance: 5689.825
> >> AIC: 5707.825
> >>
> >> > plot(effect("age", myologit, xlevles=list(age=seq(20, 80, 5), given.values(male=1, yr89=1))))
> >> Warning message:
> >> package 'effects' was built under R version 2.13.2
> >> Error in plot(effect("age", myologit, xlevles = list(age = seq(20, 80, :
> >> error in evaluating the argument 'x' in selecting a method for
> >> function 'plot': Error in model.frame.default(formula = factor(warm) ~
> >> yr89 + male + white + :
> >> variable lengths differ (found for 'yr89')
> >>
> >> ______________________________________________
> >> 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.
> >
> >
> >
> >
------------------------------------------------
John Fox
Sen. William McMaster Prof. of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/
More information about the R-help
mailing list