Skip to content

Instantly share code, notes, and snippets.

@smc77
Created October 26, 2011 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smc77/1315162 to your computer and use it in GitHub Desktop.
Save smc77/1315162 to your computer and use it in GitHub Desktop.
Logistic Regression
# 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