Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binomial GLM using caret train

Tags:

r

glm

r-caret

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"

like image 762
Dean Avatar asked Sep 12 '14 08:09

Dean


1 Answers

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

like image 191
topepo Avatar answered Sep 20 '22 13:09

topepo