Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
library("readr")
data <-read_csv("https://raw.githubusercontent.com/propublica/compas-analysis/master/compas-scores-two-years.csv")
library("dplyr")
data <- filter(data, type_of_assessment=="Risk of Recidivism")
library("ggplot2")
ggplot(data=filter(data, race =="African-American"), aes(ordered(decile_score))) + geom_bar()
ggplot(data=filter(data, race =="Caucasian"), aes(ordered(decile_score))) + geom_bar()
ggplot(data, aes(race, decile_score)) + geom_boxplot(notch=TRUE)
means <- filter(data, race == "Caucasian" | race == "African-American")
means <- mutate(data, white = race == "Caucasian")
t.test(decile_score ~ white, data=means)
model <- lm(decile_score ~ race + age + sex + two_year_recid + priors_count +
c_charge_degree, data = data)
summary(model)
preds <- predict(model, data=data)
ggplot(data, aes(decile_score, predict(model, data=data))) + geom_point() +
geom_smooth() + xlim(0,10) + ylim(0, 10)
model <- lm(decile_score ~ race + age + sex + two_year_recid + priors_count +
c_charge_degree + is_recid, data = data)
summary(model)
model <- glm(I(decile_score > 4) ~ race + age + sex + two_year_recid + priors_count +
c_charge_degree + is_recid, data=data, family="binomial")
summary(model)
control <- exp(2.097299) / (1 + exp(-2.097299))
exp(-0.451861) / (1 - control + (control * exp(-0.451861)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.