We will use these data to examine the regression of local species
richness against regional species richness just for North America and at
a sampling scale of 10% of the region. Although there was some evidence
that both local and regional species richness were skewed, we will, like
the original authors, analyze untransformed variables. Caley and
Schluter (1997) forced their models through the origin, but because that
can make interpretation more difficult, we will include an intercept in
the models.
This example was used in the first edition; the data file is here
Caley, M. J. & Schluter, D. (1997). The relationship between
local and regional diversity. Ecology, 78, 70-80.
Preliminaries
First, load the required packages (car)
Import caley data file (caley.csv)
caley <- read.csv("../data/caley.csv")
head(caley,10)
NA
Fit polynomial model
Create addtional predictor that is regional richness2 and
fit model with two predictors
caley$rspp10sq <- (caley$rspp10)^2
caley.lm <- lm(lspp10~rspp10 + rspp10sq, data=caley)
tidy(caley.lm, conf.int=TRUE)
Check residuals for quadratic model
plot(caley.lm)
augment(caley.lm)
Check collinearity
vif(lm(lspp10~rspp10 + rspp10sq, data=caley))
rspp10 rspp10sq
15.2 15.2
Fit simpler model
caley.lm1 <- lm(lspp10~rspp10, data=caley)
tidy(caley.lm1)
Compare fit of two models - test of whether quadratic makes a
difference
anova(caley.lm1, caley.lm)
Analysis of Variance Table
Model 1: lspp10 ~ rspp10
Model 2: lspp10 ~ rspp10 + rspp10sq
Res.Df RSS Df Sum of Sq F Pr(>F)
1 6 1299
2 5 377 1 923 12.2 0.017 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Now use centred predictor
caley$rspp10c <- scale(caley$rspp10, center=TRUE, scale=FALSE)
caley$rspp10csq <- (caley$rspp10c)^2
caley.lm3 <- lm(lspp10~rspp10c + rspp10csq, data=caley)
tidy(caley.lm3, conf.int=TRUE)
vif(lm(lspp10~rspp10c + rspp10csq, data=caley))
rspp10c rspp10csq
1.02 1.02
LS0tCnRpdGxlOiAiUUsgQm94IDguMTAiCgpvdXRwdXQ6IAogIGh0bWxfbm90ZWJvb2s6CiAgICB0aGVtZTogZmxhdGx5Ci0tLQoKYGBge3Igc2V0dXAsIGluY2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