[R] Testing year effects in lm()

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Fri Jul 31 00:54:54 CEST 2009


On Thu, 30 Jul 2009, Mark Na wrote:

> Dear R-helpers,
>
> I have a linear model with a year effect (year is coded as a factor), i.e.
> the parameter estimates for each level of my year variable have significant
> P values (see some output below) and I am interested in testing:
>
> a) the overall effect of year;

Fit the model without the "year" effect and compare both fits with 
anova().

> b) the significance of each year vis-a-vis every other year (the model
> output only tests each year against the baseline year).

If you want to compare every year with the next year, you can use 
successive difference contrasts for year. These are available as 
contr.sdif() in MASS.

If you want to perform all possible pairwise comparisons, i.e., Tukey 
contrasts, you can use glht() from package "multcomp". See the package 
documentation and vignette for further examples.

hth,
Z

> I'd appreciate any help with how to perform these post-hoc tests in R.
>
> Many thanks,
>
> Mark Na
>
>
>
>
> Call:
>
> lm(formula = data$SR.obs ~ log(data$AREA, 10) + data$YEAR,
>
>    subset = (data$AREA >= 14.5))
>
>
>
> Residuals:
>
>    Min      1Q  Median      3Q     Max
>
> -5.3412 -1.3140  0.1108  1.1972  4.3126
>
>
>
> Coefficients:
>
>                   Estimate Std. Error t value Pr(>|t|)
>
> (Intercept)         -9.4606     0.6144 -15.399  < 2e-16 ***
>
> log(data$AREA, 10)   3.9261     0.1734  22.644  < 2e-16 ***
>
> data$YEAR2008        1.0750     0.2854   3.767 0.000211 ***
>
> data$YEAR2009        1.5884     0.3073   5.169 5.18e-07 ***
>
> ---
>
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
>
>
> Residual standard error: 1.822 on 226 degrees of freedom
>
> Multiple R-squared: 0.6945, Adjusted R-squared: 0.6905
>
> F-statistic: 171.3 on 3 and 226 DF,  p-value: < 2.2e-16
>
>
>
> [1] "AIC=  934.557"
>
> 	[[alternative HTML version deleted]]
>
>


More information about the R-help mailing list