image source commons.wikimedia.org
Francis Galton’s illustration of correlation, 1875 image source commons.wikimedia.org
Data from raster
package
getData("worldclim")
and
getData("SRTM")
extract
the raster data values to the points
lm()
in R
model <- lm(t_min_july ~ elevation, data = df)
> model
Call:
lm(formula = t_min_july ~ elevation, data = df)
Coefficients:
(Intercept) elevation
4.449734 -0.004898
> summary(model)
Call:
lm(formula = t_min_july ~ elevation, data = df)
Residuals:
Min 1Q Median 3Q Max
-0.89072 -0.13481 -0.01928 0.12767 0.78203
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 4.450e+00 2.928e-02 151.98 <2e-16 ***
elevation -4.898e-03 5.627e-05 -87.05 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.2139 on 439 degrees of freedom
Multiple R-squared: 0.9452, Adjusted R-squared: 0.9451
F-statistic: 7578 on 1 and 439 DF, p-value: < 2.2e-16
lat
as an additional explanatory variable
> summary(model2)
Call:
lm(formula = t_min_july ~ elevation + lat, data = df)
Residuals:
Min 1Q Median 3Q Max
-0.81647 -0.11906 -0.00257 0.09144 0.72292
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.002e+01 1.432e+00 13.98 <2e-16 ***
elevation -4.466e-03 6.295e-05 -70.95 <2e-16 ***
lat 4.098e-01 3.763e-02 10.89 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.1966 on 438 degrees of freedom
Multiple R-squared: 0.9533, Adjusted R-squared: 0.9531
F-statistic: 4467 on 2 and 438 DF, p-value: < 2.2e-16
id landuse
1 1 urban
2 2 urban
3 3 rural
4 4 commercial
5 5 industrial
id landuse urban rural commercial
1 1 urban 1 0 0
2 2 urban 1 0 0
3 3 rural 0 1 0
4 4 commercial 0 0 1
5 5 industrial 0 0 0
image source geograph.org.uk by Matt Harrop CC2.0 license