Reputation: 93
I have created a Logistic regression model and used it to predict attendance:
LogModel <- glm(formula = Attended ~ City + Duration,
family = binomial(logit), data = MyData)
prediction <- predict(LogModel, MyData, type = "response")
What should be the arguments I use in the brierscore()
function in order to obtain the brier score?
Upvotes: 2
Views: 10188
Reputation: 438
Note that for a glm fit, fit$residuals
will return the working residuals, as opposed to the predicted probabilities. Predicted probabilities can be obtained using residuals(fit,type='response')
. See here and here for posts on residual types from a glm fit.
Here is an example of computing the Brier Score using the mtcars
dataset:
fit <- glm(am~hp+wt,data=mtcars,family='binomial')
pred.prob <- predict(fit,type='response')
brierScore <- mean((pred.prob-mtcars$am)^2)
# 0.04659236
Here is another post on how to calculate the Brier Score.
Upvotes: 5
Reputation: 18323
The Brier score is effectively the mean of the squared residuals. The residuals are stored in every glm
model output. So you can just do it by hand:
# Create some data (from ?profile.glm)
ldose <- rep(0:5, 2)
numdead <- c(1, 4, 9, 13, 18, 20, 0, 2, 6, 10, 12, 16)
sex <- factor(rep(c("M", "F"), c(6, 6)))
SF <- cbind(numdead, numalive = 20 - numdead)
# Run a model
budworm.lg0 <- glm(SF ~ sex + ldose - 1, family = binomial)
# Brier score
mean(budworm.lg0$residuals^2)
Upvotes: 2