Created
May 2, 2016 00:53
-
-
Save primaryobjects/c4a42f49601058645ff20d7582214cbe to your computer and use it in GitHub Desktop.
Framingham heart study logistic regression model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(caTools) | |
| library(ROCR) | |
| framingham <- read.csv('framingham.csv') | |
| set.seed(1000) | |
| split <- sample.split(framingham$TenYearCHD, SplitRatio = 0.65) | |
| train <- subset(framingham, split == TRUE) | |
| test <- subset(framingham, split == FALSE) | |
| framinghamLog <- glm(TenYearCHD ~ ., data=train, family=binomial) | |
| predictTest <- predict(framinghamLog, type='response', newdata=test) | |
| table(test$TenYearCHD, predictTest > 0.5) | |
| # FALSE TRUE | |
| # 0 1069 6 | |
| # 1 187 11 | |
| # Accuracy: 0.848 | |
| (1069+11) / (1069 + 6 + 187 + 11) | |
| # Baseline accuracy, always predict 0 (no CHD): 0.844 | |
| (1069+6)/(1069+6+187+11) | |
| ROCRpred <- prediction(predictTest, test$TenYearCHD) | |
| as.numeric(performance(ROCRpred, 'auc')@y.values) | |
| # AUC on test set: 0.742 | |
| # Sensitivity (true positive rate) = TP / (TP+FN): 0.05555556 | |
| 11 / (11 + 187) | |
| # Specificity (true negative rate) = TN / (TN+FP): 0.9944186 | |
| 1069 / (1069 + 6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment