[R] effect function in the effects package

Xu Jun junxu.r at gmail.com
Thu Oct 20 20:09:28 CEST 2011


Dear Professor Fox,

I didn't include codes in between these two commands (polr and
plot(effect()). I am still trying to work it out. Maybe it's related
to how I coded some of the factor variables as I got some successful
runs after I changed the coding for some factor variables. I will keep
working on the codes and see if I can figure out. Again, your effects
package, I have to say, is awesome!

Jun

On Thu, Oct 20, 2011 at 1:26 PM, Xu Jun <junxu.r at gmail.com> wrote:
> Dear Professor Fox,
>
> Thanks a lot! That is an embarrassing error. After I cleaned up and
> simplified my codes, and ran the following two lines:
>
> myologit <- polr(factor(warm) ~ yr89 + male + white + age + ed + prst,
> +               data=ordwarm2, method=c("logistic"))
>
> plot(effect("age", myologit, xlevels=list(age=seq(20, 80, 5))))
>
> I am still having trouble. See below:
>
>> 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, xlevels=list(age=seq(20, 80, 5))))
> Error in plot(effect("age", myologit, xlevels = 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')
>
> 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