Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upIncorrect definition of glm.nb model #688
Comments
|
You are correct! The new code gives: > tr_out <- train(Days ~ Sex/(Age + Eth*Lrn), data = quine, trControl = train_control, method = modelInfo, tuneLength = 1)
pred obs rowIndex
137 1 0 89
23 43 11 20
142 5 19 127
51 19 6 46
91 8 81 94
103 41 0 110
pred obs rowIndex
1 17.125190 2 1
4 13.649380 5 4
6 13.649380 13 6
7 13.649380 20 7
12 5.210164 7 12
13 5.210164 14 13
pred obs rowIndex
2 15.44885 11 2
3 15.44885 14 3
5 10.59268 5 5
8 10.59268 22 8
9 13.85107 6 9
10 13.85107 6 10(the first set is a random check that |
The glm.nb model fails to produce suitable output for the default cross validation cost function when fitting count data because it is missing type = 'response' in the definition of predict. Compare with the glm model.
Minimal, reproducible example:
require('caret')
require('MASS')
cost <- function(data, lev = NULL, model = NULL) {
print(head(data))
defaultSummary(data)
}
train_control <- trainControl(method = 'cv', number = 2, summaryFunction = cost)
tr_out <- train(Days ~ Sex/(Age + Eth*Lrn), data = quine, trControl = train_control, method = 'glm.nb', tuneLength = 1)
Session Info: