Public
Edited
Jul 2, 2024
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
petty_theft_input_comparison_data.sort((a, b) => a.close - b.close).slice(0, 1)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
estimate_drug_data = tidy(
drug_arrests,
mutate({
estimate: (d) =>
d.year > 2014 ? d.misd_drug_offenses : d.total_drug * 0.85,
close: (d) => Math.abs(d.estimate - arrests)
})
)
Insert cell
number_impacted = arrests * pct_affected * pct_in_system
Insert cell
cost_of_intervention_programs = marginal_cost_of_treatment * number_impacted
Insert cell
number_receiving_custodial_sentence = number_impacted * failure_rate
Insert cell
county_cost_of_jail_pretrial = number_impacted * alos_jail * marginal_cost_jail
Insert cell
state_cost_of_prison_program_failure = number_receiving_custodial_sentence *
fail_to_prison_rate *
marginal_cost_prison
Insert cell
county_cost_of_jail_program_failure = number_receiving_custodial_sentence *
(1 - fail_to_prison_rate) *
marginal_cost_jail *
365
Insert cell
county_costs_tmf = county_cost_of_jail_pretrial +
county_cost_of_jail_program_failure
Insert cell
total_costs_tmf = county_costs_tmf + state_cost_of_prison_program_failure
Insert cell
Insert cell
table1 = tidy(
drug_arrests,
(items) => items.filter((d) => d.year == 2019),
select(["narcotics", "dangerous_drugs", "other_felony_drug"]),
pivotLonger({
cols: ["narcotics", "dangerous_drugs", "other_felony_drug"],
namesTo: "type",
valuesTo: "arrests"
}),
mutate({
"fraction containing fentanyl": (d) =>
d.type == "narcotics"
? fentanyl_contam_narcotics
: d.type == "dangerous_drugs"
? fentanyl_contam_dd
: fentanyl_contam_other,
"felony fentanyl arrests": (d) =>
Math.round(d.arrests * d["fraction containing fentanyl"])
})
)
Insert cell
total_drug_arrests_for_chart = tidy(
drug_arrests,
mutate({
close: (d) => Math.abs(d.total_drug - total_drug_arrests)
})
)
Insert cell
number_of_arrests_fentanyl = Object.values(
tidy(table1, summarize({ total: sum("felony fentanyl arrests") }))[0]
)[0]
Insert cell
number_of_people_fentanyl = number_of_arrests_fentanyl * 0.9
Insert cell
number_of_people_affected_annually_fentanyl_enhancement = number_of_people_fentanyl * more_than_28g +
number_of_people_fentanyl * more_than_100g +
number_of_people_fentanyl * more_than_500g
Insert cell
increase_in_prison_population = number_of_people_fentanyl * more_than_28g * 3 +
number_of_people_fentanyl * more_than_100g * 5 +
number_of_people_fentanyl * more_than_500g * 5
Insert cell
prison_costs_due_to_fentanyl = (increase_in_prison_population *
marginal_cost_prison) /
2
Insert cell
Insert cell
fentanyl_arrests_table = Inputs.table(table2)
Insert cell
table2 = tidy(
drug_arrests,
(items) => items.filter((d) => d.year == 2012),
select([
"narcotics",
"dangerous_drugs",
"other_felony_drug",
"total_drug",
"marijuana"
]),
mutate({
narcotics: (d) => d.narcotics / d.total_drug,
dangerous_drugs: (d) => d.dangerous_drugs / d.total_drug,
other_felony_drug: (d) => (d.other_felony_drug + d.marijuana) / d.total_drug
}),
pivotLonger({
cols: ["narcotics", "dangerous_drugs", "other_felony_drug"],
namesTo: "type",
valuesTo: "fraction of drug arrests"
}),
select(["type", "fraction of drug arrests"]),
mutate({
"fraction containing fentanyl": (d) =>
d.type == "narcotics"
? fentanyl_contam_narcotics
: d.type == "dangerous_drugs"
? fentanyl_contam_dd
: fentanyl_contam_other,
"fentanyl arrests": (d) =>
Math.round(
total_drug_arrests *
d["fraction containing fentanyl"] *
d["fraction of drug arrests"]
)
})
)
Insert cell
number_of_total_arrests_fentanyl = Object.values(
tidy(table2, summarize({ total: sum("fentanyl arrests") }))[0]
)[0]
Insert cell
armed_fentanyl_annual = number_of_total_arrests_fentanyl * fraction_armed
Insert cell
armed_fentanyl_increase_in_prison_pop = armed_fentanyl_annual * 3
Insert cell
state_costs_prison_armed_fentanyl = armed_fentanyl_annual * marginal_cost_prison
Insert cell
Insert cell
petty_theft_input_comparison_data = tidy(
theft_arrests,
mutate({
close: (d) => Math.abs(d.petty_theft - misdemeanor_theft_arrests)
})
)
Insert cell
annual_jail_admissions_pretrial = misdemeanor_theft_arrests * pct_2priors
Insert cell
county_costs_pretrial_theft = annual_jail_admissions_pretrial *
alos_jail_theft *
marginal_cost_jail
Insert cell
people_sentenced_to_jail = annual_jail_admissions_pretrial *
pct_misd_theft_in_system * pct_custodial_sentence *
(1 - pct_sentenced_to_prison)
Insert cell
county_cost_jail_sentence = people_sentenced_to_jail * 365 * marginal_cost_jail
Insert cell
people_sentenced_to_prison = annual_jail_admissions_pretrial *
pct_misd_theft_in_system *
pct_sentenced_to_prison *
pct_custodial_sentence
Insert cell
state_cost_prison_petty_theft_2priors = people_sentenced_to_prison *
marginal_cost_prison
Insert cell
Insert cell
state_costs = state_cost_of_prison_program_failure +
state_cost_prison_petty_theft_2priors +
state_costs_prison_armed_fentanyl +
prison_costs_due_to_fentanyl
Insert cell
county_costs = county_cost_jail_sentence +
county_cost_of_jail_pretrial +
county_cost_of_jail_program_failure +
county_costs_pretrial_theft
Insert cell
cost_of_intervention_programs
Insert cell
county_cost_of_jail_pretrial
Insert cell
estimated_total_cost = cost_of_intervention_programs + county_costs + state_costs
Insert cell
total_increase_people_incarcerated = number_impacted *
failure_rate *
fail_to_prison_rate *
2 + // tmf prison sentence population
(1 - fail_to_prison_rate) * number_impacted * failure_rate + // tmf jail sentence population
(number_impacted * alos_jail) / 365 + // tmf jail pretrial population
increase_in_prison_population + // fentanyl sentencing enhancements prison population
armed_fentanyl_increase_in_prison_pop + // armed fentanyl sentence prison population
(annual_jail_admissions_pretrial * alos_jail_theft) / 365 + //theft pretrial population
people_sentenced_to_jail + // theft jail sentence population
people_sentenced_to_prison * 2 // theft prison sentence population
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
sud_spending_data = FileAttachment(
"average outpatient service rate -- all counties@3.csv"
).csv({ typed: true })
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more