1.Starting Session/Loading Data
rm(list = ls())
library(AER)
data(Rossi)
Tidy Data
library(dplyr)
Rossi <- select(Rossi, arrest, race, mar, wexp, fin) #Subset Variables
Rossi <- rename(Rossi, Rearrested = "arrest", Race = "race", Marriage = "mar", Work.Experience = "wexp", Financial.Assistance = "fin") #Rename Variables
Structure of the Data
glimpse(Rossi)
## Rows: 432
## Columns: 5
## $ Rearrested <int> 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1…
## $ Race <fct> black, black, other, black, other, black, black, …
## $ Marriage <fct> not married, not married, not married, married, n…
## $ Work.Experience <fct> no, no, yes, yes, yes, yes, yes, yes, no, yes, no…
## $ Financial.Assistance <fct> no, no, no, yes, no, no, no, yes, no, no, yes, no…
Rossi Data Table
DT::datatable(Rossi)
2. Logit Regression (glm)
Research Questions
Does race influence the likelihood of being re-arrested?
Does marriage status impact the likelihood of being re-arrested?
Does having work experience reduce the likelihood of re-arrest?
Does financial assistance reduce the likelihood of re-arrest?
Model <- glm(Rearrested ~ Race + Marriage + Work.Experience + Financial.Assistance, family = binomial, data = Rossi)
summary(Model)
##
## Call:
## glm(formula = Rearrested ~ Race + Marriage + Work.Experience +
## Financial.Assistance, family = binomial, data = Rossi)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -1.0114 0.4460 -2.268 0.0233 *
## Raceother -0.2205 0.3547 -0.622 0.5341
## Marriagenot married 0.5841 0.4140 1.411 0.1583
## Work.Experienceyes -0.5511 0.2280 -2.417 0.0156 *
## Financial.Assistanceyes -0.4598 0.2239 -2.054 0.0400 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 498.60 on 431 degrees of freedom
## Residual deviance: 483.65 on 427 degrees of freedom
## AIC: 493.65
##
## Number of Fisher Scoring iterations: 4
Interpretation
- There is no significant relationship between race and the likelihood of being rearrested.
- There is no significant relationship between marriage status and the likelihood of being rearrested.
- There is a significant relationship between work experience and the likelihood of being rearrested. As Work Experience increases, the likelihood of being rearrested decreases.
- There is a significant relationship between financial assistance and
the likelihood of being rearrested. As Financial Assistance increases,
the likelihood of being rearrested decreases.
3. Average Marginal Effects
Average Marginal Effects Description
- The average marginal effect is the average of the marginal effects across all observations in the sample.
- The marginal effect of a variable is the change in the expected value of the dependent variable for a one-unit change in the independent variable.
library(clarify) #Using clarify to interpret results
set.seed(123) #Set random seed to obtain repeatable results
sim_coefs <- sim(Model) #Simulate model parameters from the fitted model using sim() function
Use the sim_ame() function to calculate the average marginal effect of “Work.Experience” on the probability of being rearrested.
sim_est <- sim_ame(sim_coefs, var = "Work.Experience",
contrast = "rd", verbose = F)
summary(sim_est)
## Estimate 2.5 % 97.5 %
## E[Y(no)] 0.323 0.259 0.397
## E[Y(yes)] 0.217 0.173 0.275
## RD -0.106 -0.190 -0.016
Interpretation
- Former convicts with no prior work experience have a 32% chance of being rearrested.
- Former convicts with prior work experience have a 22% chance of being rearrested.
- So it can said that having work experience reduces the probability
of being rearrested by 10%.
Use the sim_ame() function to calculate the average marginal effects of “Financial Assistance” on the probability of being rearrested.
options(scipen=999) # To avoid scientific notation
sim_est1 <- sim_ame(sim_coefs, var = "Financial.Assistance",
contrast = "rd", verbose = F)
summary(sim_est1)
## Estimate 2.5 % 97.5 %
## E[Y(no)] 0.3073709 0.2548734 0.3754478
## E[Y(yes)] 0.2208248 0.1712448 0.2827665
## RD -0.0865461 -0.1666826 0.0000329
Interpretation
- Former convicts who do not receive financial assistance have a 30% chance of being rearrested.
- Former convicts that do receive financial assistance have a 22% chance of being rearrested.
- So it can be said that receiving financial assistance reduces the
probability of being rearrested by 8%.
4. Sim_Setx Function
Sim_Setx Function Description
- The sim_setx() function is used to compute predictions and first
differences at set values.
Research Questions
- How does having work experience and receiving financial assistance influence the likelihood of rearrest?
- How does having no work experience and receiving no financial assistance influence the likelihood of rearrest?
est <- sim_setx(sim_coefs, x = list(Work.Experience = "yes", Financial.Assistance = "yes"),
x1 = list(Work.Experience = "no", Financial.Assistance = "no"), verbose = FALSE)
summary(est)
## Estimate 2.5 % 97.5 %
## Work.Experience = "yes", Financial.Assistance = "yes" 0.1918 0.1371 0.2659
## Work.Experience = "no", Financial.Assistance = "no" 0.3947 0.3114 0.4928
## FD 0.2029 0.0737 0.3256
Interpretation
- Ex convicts who have prior work experience and receive financial assistance have a 19% chance of being rearrested.
- Ex convicts who have no prior work experience and do not receive financial assistance have a 39% chance of being rearrested.
- The first difference depicts that convicts with no prior work
experience and no financial assistance have a 20% higher probability of
being rearrested compared to ex convicts with prior work experience and
financial assistance.