Reputation: 131
I am experiencing the same error as raised and answered here (cv.glm variable lengths differ) and in various other threads. Despite using the "correct" formula structure as suggested in all these threads, the error persists:
mod <- glm(Y ~ Var_1, data = df, family = binomial)
cv.glm(df, mod, K=8)
Error in model.frame.default(formula = Y ~ Var_1, data = list( : variable lengths differ (found for 'Var1')
Are there any other known sources of this issue?
Upvotes: 0
Views: 105
Reputation: 131
My response variable was actually defined as
Y <- cbind(df$Y2, df$Y1-Y2)
, and so whilst the model formula looked like it was in the correct format, the way my response variable was created posed an issue.
If I use the alternative of:
mod <- glm(Y2/Y1 ~ Var1, family = binomial, data = df, weights = Y1)
then running boot::cv.glm(df, mod, K = 8)
works.
Upvotes: 0