Repository navigation
R Statistics III: Logistic Regression
A researcher is interested in how variables, such as GRE (Graduate Record Exam scores), GPA (grade point average) and prestige of the undergraduate institution, effect admission into graduate school. The response variable, admit/don’t admit, is a binary variable.
-
Load the data into a variable using the following command:
mydata <- read.csv("https://stats.idre.ucla.edu/stat/data/binary.csv") -
View the first rows of the data using the
head()function. You will notice that thegreandgpavariables are continuous and thatrankis an ordered categorical variable (1-4). We use the function ´factor´ to tell R to treat it like that (i.e. R will select one of the categories inrankand use it as a reference). -
Do a logistic regression using the
glm()function with admit as response and the other variables as predictors (dont forget to usefactor(rank)instead ofrankin the formula). Remember that to make R understand that it is a logistic model you want you need to say that your response is a binomial variable with the family argument. Look at the results with thesummary()function. -
Compute the odds ratios and confidence intervals for all significant predictors. TIP: Save the summary() in a variable called (for ex)
sfit = summary(...). Then you can get the effects (betas) and the standard errors from ´sfit$coefficients`.