[R] effect function in the effects package

Xu Jun junxu.r at gmail.com
Thu Oct 20 20:41:30 CEST 2011


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)
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))))

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



More information about the R-help mailing list