0
$\begingroup$

I have the following data and am trying to fit a glm model. There are six factors. Each factor has $250$ samples and $Y$ accounts for the successes.

X <- seq(1:6); n = rep(250, 6)
Y <- c(28, 53, 93, 126, 172, 197)

I have the following model if I create a vector that follows the success and fail.

y <- cbind(Y, n - Y)
mod <- glm(y ~ X, family = binomial())
summary(mod)

If I build a model in binary classification style, I surely have a different model.

temp_y <- c()
temp_X <- c()
for(i in c(1:6)) {
  temp <- rep(0, 250)
  temp_X <- c(temp_X, rep(i, 250))
  temp[1:Y[i]] <- 1
  temp_y <- c(temp_y, temp)
}

mod2 <- glm(temp_y ~ as.factor(temp_X), family = binomial())
summary(mod2)

Which one is the correct setup?

$\endgroup$
1
  • 1
    $\begingroup$ The only difference between these models is that you provided X as a categorical predictor with 6 levels in one and as a continuous covariate in the other. $\endgroup$
    – PBulls
    Dec 16, 2023 at 22:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.