Glm

Logistic Regression

logistic regression is the method that seems only ever to be used for classification yet insists on calling itself regression. the resolution: it is regression — of the log-odds of a bernoulli success probability onto a linear predictor. 𐃏 this page develops it the honest way, as a generalised linear model: bernoulli response, canonical logit link, likelihood fitted by fisher scoring, inference through the deviance. the machine-learning reading (cross-entropy loss, linear decision boundaries) falls out at the end as a corollary.

Read more >

An Introduction to Generalized Linear Models

install.packages("glmnet")
install.packages("dobson")
library(glmnet)
library(dobson)
data(carbohydrate)
y = carbohydrate$carbohydrate
x = as.matrix(carbohydrate[,c('age', 'weight', 'protein')])
fit = glmnet(x, y)
plot(fit, xvar='lambda')
cvfit = cv.glmnet(x,y)
coef(cvfit, s = "lambda.1se")

Exercise 4.2

Each \(y_i\) is ’time to death’ for a particular leukemia patient (in weeks from diagnosis).

The \(x_i\) are \(\log_{10}\) initial white blood cell counts.

a.

x = c(3.36,2.88,3.63,3.41,3.78,4.02,4.00,4.23,3.73,3.85,3.97,4.51,4.54,5.00,5.00,4.72,5.00)
y = c(65,156,100,134,16,108,121,4,39,143,56,26,22,1,1,5,65)
plot(x,y)

The data shows a negative trend – as WBC increase, TTL decreases.

length(x) # 17 patients
[1] 17

b. \[ E(Y_i) = \exp(\beta_1 + \beta_2 x_i)\]

Read more >