36-462/36-662, Spring 2020
4 February 2020
\[ \newcommand{\Expect}[1]{\mathbb{E}\left[ #1 \right]} \newcommand{\Indicator}[1]{\mathbb{1}\left\{ #1 \right\}} \newcommand{\Prob}[1]{\mathbb{P}\left( #1 \right)} \]
linear.classifier = function(x, coefficients, offset) {
# The following is actually a (multiple of) the directed distance
distance.from.plane = function(z) { offset + z %*% coefficients }
directed.distances = apply(x, 1, directed.distance.from.plane)
return(ifelse(directed.distances >= 0, 1, 0))
}
lm
faraway
library implements these as the logit()
and ilogit()
functionsglm(y ~ x1 + x2, data = df, family = "binomial")
## Warning: glm.fit: algorithm did not converge
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
##
## Call: glm(formula = y ~ x1 + x2, family = "binomial", data = df)
##
## Coefficients:
## (Intercept) x1 x2
## 0.07124 1.66586 1.44060
##
## Degrees of Freedom: 199 Total (i.e. Null); 197 Residual
## Null Deviance: 277.3
## Residual Deviance: 1.849e-09 AIC: 6
family="binomial"
option tells glm()
that we’re trying to estimate the probability that y
\(==1\), and the default “link function” is the logistic
glm()
function in RButler, Ronald W. 1986. “Predictive Likelihood Inference with Applications.” Journal of the Royal Statistical Society B 48:1–38. http://www.jstor.org/stable/2345635.