Skip to content

Instantly share code, notes, and snippets.

View NightlordTW's full-sized avatar

Thomas Debray NightlordTW

View GitHub Profile
@NightlordTW
NightlordTW / gist:1511193
Created December 22, 2011 17:55
Constrained Logistic Regression
################################################################################
# Calculates the maximum likelihood estimates of a logistic regression model
# Slopes are constrained to non-negative values
#
# fmla : model formula
# x : a [n x p] dataframe with the data. Factors should be coded accordingly
#
# OUTPUT
# beta : the estimated regression coefficients
# vcov : the variane-covariance matrix
@NightlordTW
NightlordTW / gist:1406446
Created November 29, 2011 20:50
Logistic Regression
################################################################################
# Calculates the maximum likelihood estimates of a logistic regression model
#
# fmla : model formula
# x : a [n x p] dataframe with the data. Factors should be coded accordingly
#
# OUTPUT
# beta : the estimated regression coefficients
# vcov : the variane-covariance matrix
# ll : -2ln L (deviance)
@NightlordTW
NightlordTW / gist:1387272
Created November 22, 2011 22:36
Logistic Regression
################################################################################
# Calculates the maximum likelihood estimates of a logistic regression model
#
# fmla : model formula
# x : a [n x p] dataframe with the data. Factors should be coded accordingly
#
# OUTPUT
# beta : the estimated regression coefficients
# vcov : the variane-covariance matrix
# ll : -2ln L (deviance)
@NightlordTW
NightlordTW / gist:1383699
Created November 21, 2011 19:47
Logistic Regression Example (Part 2)
mylogit = glm(admit~gre+gpa+as.factor(rank), family=binomial, data=mydata)
@NightlordTW
NightlordTW / gist:1383673
Created November 21, 2011 19:38
Logistic Regression Example (Part 1)
mydata = read.csv(url('http://www.ats.ucla.edu/stat/r/dae/binary.csv'))
@NightlordTW
NightlordTW / gist:1383665
Created November 21, 2011 19:36
Logistic Regression Example (Part 3)
mydata$rank = factor(mydata$rank) #Treat rank as a categorical variable
fmla = as.formula("admit~gre+gpa+rank") #Create model formula
mylogit = mle.logreg(fmla, mydata) #Estimate coefficients
mylogit