data("heartdisease")
# Real data is messy: missingness is heavy and very uneven across sites
colSums(is.na(heartdisease))
table(heartdisease$dataset)
# The Cleveland site is the most complete; use it for a first model
cleveland <- subset(heartdisease, dataset == "cleveland")
# Binarise the 0-4 angiographic outcome into disease present/absent
cleveland$disease <- as.integer(cleveland$num > 0)
# Logistic regression of disease on age, sex and maximum heart rate
fit <- glm(disease ~ age + sex + thalach, family = binomial, data = cleveland)
summary(fit)
# Chi-square test: is disease associated with sex (all sites)?
heartdisease$disease <- as.integer(heartdisease$num > 0)
chisq.test(table(heartdisease$sex, heartdisease$disease))
Run the code above in your browser using DataLab