Created
October 26, 2011 01:45
-
-
Save smc77/1315162 to your computer and use it in GitHub Desktop.
Logistic Regression
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
# Plot the sigmoid function | |
library(ggplot2) | |
qplot(-10:10, 1/(1 + exp(-(-10:10))), geom="line", xlab="z", ylab="sigmoid function") | |
# Download South African heart disease data | |
sa.heart <- read.table("http://www-stat.stanford.edu/~tibs/ElemStatLearn/datasets/SAheart.data", sep=",",head=T,row.names=1) | |
# Pretty plot | |
pairs(sa.heart[1:9],pch=21,bg=c("red","green")[factor(sa.heart$chd)]) | |
# Apply logistic regression to South African heart data from ESL | |
sa.heart.fit <- glm(chd ~ ., family = binomial, data=sa.heart) | |
summary(sa.heart.fit) | |
# Use stepwise logistic regression to reduce the dimensions | |
library(MASS) | |
sa.heart.step <- stepAIC(glm(chd ~ ., data=sa.heart)) | |
summary(sa.heart.step) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment