[R] Effects - plot the marginal effect

John Fox jfox at mcmaster.ca
Fri Apr 1 05:03:20 CEST 2011


Dear Tomas,

Write the model as  

  mreg01 = lm(enep1 ~ enpres * proximity1), data=a90)

That is, it's not necessary to index a90 as a list since it's given as the data argument to lm, and doing so confuses the effect() function. Also, enpres*proximity1 will include both the enpres:proximity1 interaction and enpres + proximity1, which are marginal to the interaction.

Next, you must quote the name of the term for which you want to compute effects, thus "enpres:proximity1" in the call to effect().

Finally, effect() doesn't compute what are usually termed marginal effects. If you want more information about what it does, see the references given in ?effect.

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, 31 Mar 2011 22:09:32 +0200
 Tomii <diogenas at gmail.com> wrote:
> Hello,
> 
> I try to plot the marginal effect by using package "effects" (example of the
> graph i want to get is in the attached picture).
> All variables are continuous.
> 
> Here is regression function, results and error effect function gives:
> 
> > mreg01 = lm(a90$enep1 ~ a90$enpres + a90$proximity1 + (a90$enpres * a90$proximity1), data=a90)> summary(mreg01)
> Call:
> lm(formula = a90$enep1 ~ a90$enpres + a90$proximity1 + (a90$enpres *
>     a90$proximity1), data = a90)
> 
> Residuals:
>     Min      1Q  Median      3Q     Max
> -2.3173 -1.3349 -0.5713  0.8938  8.1084
> 
> Coefficients:
>                           Estimate Std. Error t value Pr(>|t|)
> (Intercept)                 4.2273     0.3090  13.683  < 2e-16 ***
> a90$enpres                  0.4225     0.2319   1.822 0.072250 .
> a90$proximity1             -3.8797     1.0984  -3.532 0.000696 ***
> a90$enpres:a90$proximity1   0.8953     0.4101   2.183 0.032025 *
> ---
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> 
> Residual standard error: 2.029 on 78 degrees of freedom
> Multiple R-squared: 0.2128,	Adjusted R-squared: 0.1826
> F-statistic: 7.031 on 3 and 78 DF,  p-value: 0.0003029
> > plot(effect(a90$enpres:a90$proximity1, mreg01))Warning messages:1: In a90$enpres:a90$proximity1 :
>   numerical expression has 82 elements: only the first used2: In
> a90$enpres:a90$proximity1 :
>   numerical expression has 82 elements: only the first used3: In
> analyze.model(term, mod, xlevels, default.levels) :
>   0 does not appear in the modelError in
> plot(effect(a90$enpres:a90$proximity1, mreg01)) :
>   error in evaluating the argument 'x' in selecting a method for function 'plot'
> 
> >
> 
> Thanks in advance.
> Tomas



More information about the R-help mailing list