Локальная регрессия для вероятности.
my.seed <- 1
data(Boston)
attach(Boston)
fit_logit <- glm(I(crim > 30) ~ poly(nox, 3), data = Boston, family="gaussian")
fit_logit
##
## Call: glm(formula = I(crim > 30) ~ poly(nox, 3), family = "gaussian",
## data = Boston)
##
## Coefficients:
## (Intercept) poly(nox, 3)1 poly(nox, 3)2 poly(nox, 3)3
## 0.01581 0.36883 -0.18344 -0.35363
##
## Degrees of Freedom: 505 Total (i.e. Null); 502 Residual
## Null Deviance: 7.874
## Residual Deviance: 7.579 AIC: -679.8
gam.lr <- gam(I(crim > 30) ~ s(nox, df = 5) ,
family = 'binomial', data = Boston)
gam.lr
## Call:
## gam(formula = I(crim > 30) ~ s(nox, df = 5), family = "binomial",
## data = Boston)
##
## Degrees of Freedom: 505 total; 500.0002 Residual
## Residual Deviance: 40.825
plot(gam.lr, se = T, col = 'green')
summary(gam.lr)
##
## Call: gam(formula = I(crim > 30) ~ s(nox, df = 5), family = "binomial",
## data = Boston)
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -8.176e-01 -5.027e-02 -2.790e-05 -2.107e-08 2.382e+00
##
## (Dispersion Parameter for binomial family taken to be 1)
##
## Null Deviance: 82.2264 on 505 degrees of freedom
## Residual Deviance: 40.825 on 500.0002 degrees of freedom
## AIC: 52.8245
##
## Number of Local Scoring Iterations: 30
##
## Anova for Parametric Effects
## Df Sum Sq Mean Sq F value Pr(>F)
## s(nox, df = 5) 1 4.626 4.6258 45.534 4.164e-11 ***
## Residuals 500 50.795 0.1016
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Anova for Nonparametric Effects
## Npar Df Npar Chisq P(Chi)
## (Intercept)
## s(nox, df = 5) 4 9.2476 0.05519 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1