Here are two examples of binomial model fitting where in. In the second example with have, the independent variable is modeled asusing poly()
as a second order polynomial.
How todo I interpret these 2 results? Why someone would want to use the poly(2)
, this? This would be rather overfitting in the context of logistic regression, right?
I understand that for the linear models, like lm(y ~ x + I(x^2))
with, the second order we wouldis used to check whether the more complex model fitsprovides better fits to our data, minimize the residuals
vis-a-vis minimizing the residuals, but logistic regression has no residuals (error terms). Many thanks.
The poly(,2) depicts completely different picture about survival of M/F across age.
library(vcdExtra)
library(ggplot2)
require(gridExtra)
data(Donner, package="vcdExtra")
head(Donner)
# separate linear fits on age for M/F
g1 <- ggplot(Donner, aes(age, survived, color = sex)) + geom_point(position = position_jitter(height = 0.02, width = 0)) +
stat_smooth(method = "glm", method.args = list(family = binomial), formula = y ~ x, alpha = 0.2, size=2, aes(fill = sex))
# separate quadratics
g2 <- ggplot(Donner, aes(age, survived, color = sex)) + geom_point(position = position_jitter(height = 0.02, width = 0)) +
stat_smooth(method = "glm", method.args = list(family = binomial), formula = y ~ poly(x,2), alpha = 0.2, size=2, aes(fill = sex))
grid.arrange(g1, g2, ncol=2)