for (variable in independent_variables) {
formula <- as.formula(paste("Medikament ~ ", variable))
model <- glm(formula, data = Data_dep, family = binomial(link = "logit"))
coef_value <- coef(model)[2]
odds_ratio_value <- exp(coef_value)
n <- length(model$residuals)
R2cs <- 1 - exp((model$deviance - model$null.deviance) / n)
R2n <- R2cs / (1 - exp(-(model$null.deviance / n)))
cat("Variable:", variable, "\n")
cat("p-value:", summary(model)$coefficients[2, 4], "\n")
cat("Odds Ratio:", odds_ratio_value, "\n\n")
cat("R2:", R2n, "\n\n")
formula_additional <- as.formula(paste("meds~ ", variable, " + sex + age_at_survey + PC1 + PC2 + PC3 +
PC4 + PC5 + PC6 + PC7 + PC8 + PC9 + PC10 + PC11 + PC12 + PC13 + PC14 + PC15 + PC16 + PC17 + PC18 + PC19 +
PC20"))
model_additional <- glm(formula_additional, data = Data_dep, family = binomial(link = "logit"))
p_value_additional <- summary(model_additional)$coefficients[2, 4]
p_value_additional_corrected <- p.adjust(p_value_additional, method = "fdr")
cat("additional co-var- Raw p-value:", p_value_additional, "\n")
cat("additional co-var - Fdr-corrected p-value:", p_value_additional_corrected, "\n\n")
}
This is the loop I wrote. The problem is that the p-value from the logistig regression with additional covariances is the same as the fdr-corrected p-value for this glm. When I calculate it by hand, the values differ.
Can someone tell where the problem is?