User Tools

Site Tools


cs:lm_glm

Česká verze stránek není od roku 2013 aktualizována.

LM & GLM

vltava.env <- read.csv2 ('http://www.davidzeleny.net/anadat-r/data-download/vltava-env.csv', dec = '.')
 
lm.1 <- lm (SPEC.NO ~ pH.H, data = vltava.env)
summary (lm.1)
 
plot (SPEC.NO ~ pH.H, data = vltava.env)
abline (lm.1) 
legend ('bottomright', legend = 'R2 = 0.25, F = 31.6, p < 0.001', bty = 'n')
 
 
glm.1 <- glm (SPEC.NO ~ pH.H, data = vltava.env, family = poisson)
summary (glm.1)
anova (glm.1, test = 'Chisq')
 
glm.2 <- glm (SPEC.NO ~ poly (pH.H, 2), data = vltava.env, family = poisson)
summary (glm.2)
 
anova (glm.1, glm.2, test = 'Chisq')
 
newdata.ph <- seq (min (vltava.env$pH.H), max (vltava.env$pH.H), length = 20)
 
predict.glm.1 <- predict (glm.1, newdata = list (pH.H = newdata.ph), type = 'response')
predict.glm.2 <- predict (glm.2, newdata = list (pH.H = newdata.ph), type = 'response')
 
plot (SPEC.NO ~ pH.H, data = vltava.env)
lines (predict.glm.1 ~ newdata.ph, col = 'blue')
lines (predict.glm.2 ~ newdata.ph, col = 'red')
cs/lm_glm.txt · Last modified: 2017/10/11 20:36 (external edit)