Dean
Dean

Reputation: 73

Binomial GLM using caret train

I would like to fit a Binomial GLM on a certain dataset. Using glm(...,family=binomial) everything works fine however I would like to do it with the caret train() function. Unfortunately I get an unexpected error which I cannot get rid of.

library("marginalmodelplots")
library("caret")

MissUSA <- MissAmerica08[,c(2,4,6,7,8,10)]
formula <- cbind(Top10, 9-Top10)~.
glmfit <- glm(formula=formula, data=MissUSA, family=binomial())

trainfit <-train(form=formula,data=MissUSA,trControl=trainControl(method = "none"),   method="glm", family=binomial()) 

The error I get is:

"Error : nrow(x) == length(y) is not TRUE"

Upvotes: 6

Views: 10011

Answers (1)

topepo
topepo

Reputation: 14316

caret doesn't support grouped data for a binomial outcome. You can expand the data into a factor variable that is binary (Bernoulli) data. Also, if you do that, you do not need to use family=binomial() in the call to train.

Max

Upvotes: 5

Related Questions