# Predict binary outcome with R

I have a table includes the following data:

Status     | Age | Tenure | Function | Gender | Race | Grade Level
-----------------------------------------------------------------
Active     |  34 |    1.2 | PSO      | Female | White| 26
Terminated |  24 |    0.2 | Finance  | Male   | Asian| 32
Active     |  50 |    4.0 | HR       | Female | Black| 28
Terminated |  23 |    2.9 | Sales    | Male   | Hispa| 20
:
:
:


I want find out how are the different variables have impact on the binary outcome - Status, and possibly create a predictive modeling to predict the outcome of Status based on the other variables.

Where do I start? I am thinking of doing a factor analysis to find the P-value for each factor. Is that a right path?

## migrated from stackoverflow.comJan 6 '14 at 12:05

This question came from our site for professional and enthusiast programmers.

The most obvious thing that comes in mind would be binary response models. In your case I would probably recommend applying logistic regression. It can be done using glm function (for Generalized Linear Models) in R. In this case
glm(formula = Status ~ Age + Tenure + Function + Gender + Race + Grade Level ,

• I used this statement glm(formula = status ~ age + sex + race + function + grade + tenure, family = binomial(logit), data = data), it is giving me an error msg: Error: unexpected '+' in "glm(formula = status ~ age + sex + race + function +". What did I do wrong? :( – PMa Jan 6 '14 at 5:54
• Problem is that column Function corresponds to one of R language keywords and it thinks that you want to start writing function. Simplest solution to rename that column. You can retrieve your column name vector aux<-colnames(yourdata) then change the appropriate value in aux[4]="func" and then update column names by colnames(yourdata)<-aux . – user974514 Jan 6 '14 at 6:14
• I would just add that using link=logit is not the only option, the other two commonly used ones being probit and cloglog. For a discussion on how to choose the link function and in general on binomail models you may also want to have a look at chapter 2 of "Extending the linear model with R" by Julian Faraway. – nico Jan 6 '14 at 7:30
This is a logistic regression question. You can fit a model like fit <- (status ~ age + tenure + function...). This can be done with a variety of techniques, I recommend the package rms. You may also want to review Frank Harrell's book. You can validate, calibrate, plot, derive a formula, etc using the functions in the package.