dat <- data.frame (
cancer = c (1 , 0 , 1 , 0 , 1 , 0 , 1 , 0 ),
coffee = c (1 , 1 , 0 , 0 , 1 , 1 , 0 , 0 ),
smoke = c (1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 ),
n = c (14 , 266 , 4 , 76 , 1 , 99 , 8 , 792 )
)
fit_logit1 <- glm (
cancer ~ coffee,
family = binomial (link = "logit" ),
weights = n,
data = dat
)
odds_ratio1 <- exp (coef (fit_logit1)[["coffee" ]])
print (odds_ratio1)
fit_logit2 <- glm (
cancer ~ coffee+ smoke,
family = binomial (link = "logit" ),
weights = n,
data = dat
)
odds_ratio2 <- exp (coef (fit_logit2)[["coffee" ]])
print (odds_ratio2)
fit_log1 <- glm (
cancer ~ coffee,
family = binomial (link = "log" ),
weights = n,
data = dat
)
risk_ratio1 <- exp (coef (fit_log1)[["coffee" ]])
print (risk_ratio1)
fit_log2 <- glm (
cancer ~ coffee+ smoke,
family = binomial (link = "log" ),
weights = n,
data = dat
)
risk_ratio2 <- exp (coef (fit_log2)[["coffee" ]])
print (risk_ratio2)