library(Lock5withR)
gf_point(AvgMercury ~ Alkalinity, data = FloridaLakes)
model1 <- lm(AvgMercury ~ Alkalinity, data = FloridaLakes)
Let us inspect for linearity, independence, and equal standard deviation.
Can do
The most commonly used is residuals vs fits because it generalizes to models with multiple predictors. Whether order is meaningful depends on how the data were collected and stored.
gf_point(AvgMercury ~ Alkalinity, data = FloridaLakes) %>% gf_lm()
gf_point(resid(model1) ~ Alkalinity, data = FloridaLakes)
gf_point(resid(model1) ~ fitted(model1), data = FloridaLakes)
mplot(model1, which = 1)
## `geom_smooth()` using formula 'y ~ x'
We can check normality using a normal-quatile plot
gf_qq( ~ resid(model1)) %>% gf_qqline()
mplot(model1, which = 2)
The first thing to try is a transformation of one or both variables. Comonly useful transformations include:
model2 <- lm(AvgMercury ~ log(Alkalinity), data = FloridaLakes)
model3 <- lm(log(AvgMercury) ~ Alkalinity, data = FloridaLakes)
model4 <- lm(log(AvgMercury) ~ log(Alkalinity), data = FloridaLakes)
gf_point(AvgMercury ~ log(Alkalinity), data = FloridaLakes) %>% gf_lm()
mplot(model2, which = 1:2)
## [[1]]
## `geom_smooth()` using formula 'y ~ x'
##
## [[2]]
gf_point(log(AvgMercury) ~ Alkalinity, data = FloridaLakes) %>% gf_lm()
mplot(model3, which = 1:2)
## [[1]]
## `geom_smooth()` using formula 'y ~ x'
##
## [[2]]
gf_point(log(AvgMercury) ~ log(Alkalinity), data = FloridaLakes) %>% gf_lm()
mplot(model4, which = 1:2)
## [[1]]
## `geom_smooth()` using formula 'y ~ x'
##
## [[2]]