Skip to content

R Statistics III: Logistic Regression

Bioinformatics Core Facility Gothenburg edited this page Sep 5, 2017 · 6 revisions

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.

  1. Load the data into a variable using the following command:

    mydata <- read.csv("https://stats.idre.ucla.edu/stat/data/binary.csv")
    
  2. View the first rows of the data using the head() function. You will notice that the gre and gpa variables are continuous and that rank is 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 in rank and use it as a reference).

  3. Do a logistic regression using the glm() function with admit as response and the other variables as predictors (dont forget to use factor(rank) instead of rank in 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 the summary() function.

  4. 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`.


Clone this wiki locally