Walkthrough Tutorial: Divorce and Crime Analysis Package

Author

Brendan Behunin

Introduction

This tutorial walks through how to install, use, and explore the Stat386 Divorce–Crime Analysis Package.

By the end of this tutorial, you will be able to:

  • Install the package from PyPI
  • Load and clean the crime and divorce datasets
  • Understand the structure of the data
  • Run and interact with the Streamlit application
  • Explore trends in crime and divorce over time

Package Overview

The package provides tools for:

  • Loading and wrangling FBI crime and divorce data
  • Aggregating monthly crime data to yearly summaries
  • Visualizing trends by state and crime type
  • Exploring relationships between crime and divorce rates

The primary user interface is an interactive Streamlit app.


Installation

Prerequisites

  • Python 3.9 or newer
  • pip installed

Install from PyPI

pip install Stat386-FinalProject-Divorce-Crime==0.1.5

Project Structure

After installation, the project contains:

Stat386-FinalProject-Divorce-Crime
├─ docs
|  ├─ documentation.qmd
|  └─ tutorial.qmd
├─ src
│  ├─ stat386_finalproject_divorce_crime
│  │  ├─ __init__.py
│  │  ├─ app.py                         # streamlit app
│  │  ├─ wrangling.py                   # loading and managing data
│  │  └─ clean_data.py                  # merges and cleans data
│  ├─ data
│  │  ├─ Combined_df.csv                # merged data
|  |  ├─ Marriage_Divorce_rates.csv     # marriage and divorce data
|  |  └─ summarized_fbi_data.parquet    # FBI Crime data
│  └─ json
│     └─ crime_abbr.json
├─ pyproject.toml
└─ README.md

Running the Streamlit App

The easiest way to explore the data is through the Streamlit app. You can access it by navigating to this Link


See the affect of Rape on Marriage Statistics in Kansas

Make sure the following are selected

  • State
  • Line
  • Marriage
  • Actual
  • Rape
  • Kansas

Note the peaks and valleys of each. Do they align? Or do they seem to be inversely related?

See the affect of Motor Vehicle Theft Rates on Divorce Rates at the national level

Make sure the following are selected - National - Line - Divorce - Rate - Motor Vehicle Theft

You should see that as motor vehicle theft has increased from year to year, divorce rate has decreased over the same time period.

See the summary stats of linear regression models

  • Check the box for “Show Regression Model”
  • Select a crime
  • Select a metric
  • Select Divorce
  • Select a model
    • Crime as a function of marriage and divorce
    • Marriage as a function of crime
    • Divorce as a function of crime

Note the R^2 of the model you chose. Also note the coefficients for all variables. Which are positively correlated and which are negatively correlated?

Explore on your own

Try playing with all the parameters in the left sidebar on your own. Try to find any correlation (positive or negative) between crime and marriage and divorce.