{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# US Military & Veteran Analysis - Interactive Demo\n", "\n", "Explore **state-level data** on veteran demographics, firearm ownership, mental health indicators, and VA healthcare.\n", "\n", "**Dataset Highlights:**\n", "- 6 authoritative sources integrated\n", "- Veteran vs civilian suicide rates\n", "- PTSD prevalence estimates\n", "- VA healthcare utilization" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import seaborn as sns\n", "import warnings\n", "warnings.filterwarnings('ignore')\n", "\n", "plt.style.use('seaborn-v0_8-darkgrid')\n", "sns.set_palette('husl')\n", "\n", "print('Libraries loaded')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. Load Dataset" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = pd.read_csv('military_firearm_merged_analysis.csv')\n", "print(f'Total states: {len(df)}')\n", "df.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2. Dataset Overview" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print('Dataset Statistics:')\n", "print('=' * 60)\n", "print(f\"States: {len(df)}\")\n", "print(f\"\\nVeteran Statistics:\")\n", "print(f\" Total veteran population: {df['veteran_population'].sum():,.0f}\")\n", "print(f\" Avg veteran %: {df['veteran_percentage'].mean():.1f}%\")\n", "print(f\"\\nMental Health:\")\n", "print(f\" Avg veteran suicide rate: {df['veteran_suicide_rate'].mean():.1f} per 100K\")\n", "print(f\" Avg civilian suicide rate: {df['civilian_suicide_rate'].mean():.1f} per 100K\")\n", "print(f\" Avg veteran risk ratio: {df['veteran_risk_ratio'].mean():.2f}x\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3. Veteran Risk Analysis" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Top 10 states by veteran risk ratio\n", "high_risk = df.nlargest(10, 'veteran_risk_ratio')[['NAME', 'veteran_risk_ratio', 'veteran_suicide_rate', 'civilian_suicide_rate']]\n", "print('States with Highest Veteran Risk Ratio:')\n", "print(high_risk.to_string(index=False))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Compare veteran vs civilian suicide rates\n", "fig, ax = plt.subplots(figsize=(12, 8))\n", "\n", "sorted_df = df.sort_values('veteran_suicide_rate', ascending=True).tail(20)\n", "y_pos = range(len(sorted_df))\n", "\n", "ax.barh(y_pos, sorted_df['veteran_suicide_rate'], height=0.4, label='Veteran', color='steelblue', alpha=0.8)\n", "ax.barh([y + 0.4 for y in y_pos], sorted_df['civilian_suicide_rate'], height=0.4, label='Civilian', color='coral', alpha=0.8)\n", "\n", "ax.set_yticks([y + 0.2 for y in y_pos])\n", "ax.set_yticklabels(sorted_df['NAME'])\n", "ax.set_xlabel('Suicide Rate per 100,000', fontsize=12)\n", "ax.set_title('Veteran vs Civilian Suicide Rates by State', fontsize=14, fontweight='bold')\n", "ax.legend()\n", "\n", "plt.tight_layout()\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 4. Firearm Ownership Analysis" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print('Firearm Ownership Statistics:')\n", "print('=' * 50)\n", "print(f\"Mean ownership rate: {df['ownership_percentage'].mean():.1f}%\")\n", "print(f\"Highest: {df.loc[df['ownership_percentage'].idxmax(), 'NAME']} ({df['ownership_percentage'].max():.1f}%)\")\n", "print(f\"Lowest: {df.loc[df['ownership_percentage'].idxmin(), 'NAME']} ({df['ownership_percentage'].min():.1f}%)\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Correlation between firearm ownership and veteran suicide\n", "fig, ax = plt.subplots(figsize=(10, 8))\n", "\n", "ax.scatter(df['ownership_percentage'], df['veteran_suicide_rate'], alpha=0.7, s=100)\n", "\n", "# Add correlation line\n", "z = np.polyfit(df['ownership_percentage'], df['veteran_suicide_rate'], 1)\n", "p = np.poly1d(z)\n", "ax.plot(df['ownership_percentage'].sort_values(), p(df['ownership_percentage'].sort_values()), \n", " 'r--', alpha=0.8, label=f'r = {df[\"ownership_percentage\"].corr(df[\"veteran_suicide_rate\"]):.3f}')\n", "\n", "ax.set_xlabel('Firearm Ownership Rate (%)', fontsize=12)\n", "ax.set_ylabel('Veteran Suicide Rate (per 100K)', fontsize=12)\n", "ax.set_title('Firearm Ownership vs Veteran Suicide Rate', fontsize=14, fontweight='bold')\n", "ax.legend()\n", "\n", "plt.tight_layout()\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 5. VA Healthcare Utilization" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print('VA Healthcare Utilization:')\n", "print('=' * 50)\n", "print(f\"Mean utilization: {df['va_utilization_pct'].mean():.1f}%\")\n", "print(f\"\\nTop 5 States (highest VA use):\")\n", "top_va = df.nlargest(5, 'va_utilization_pct')[['NAME', 'va_utilization_pct', 'veteran_population']]\n", "print(top_va.to_string(index=False))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# PTSD prevalence by state\n", "if 'ptsd_prevalence_pct' in df.columns:\n", " fig, ax = plt.subplots(figsize=(14, 6))\n", " sorted_ptsd = df.sort_values('ptsd_prevalence_pct')\n", " ax.barh(sorted_ptsd['NAME'], sorted_ptsd['ptsd_prevalence_pct'], color='teal')\n", " ax.set_xlabel('PTSD Prevalence (%)', fontsize=12)\n", " ax.set_title('PTSD Prevalence Among Veterans by State', fontsize=14, fontweight='bold')\n", " plt.tight_layout()\n", " plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 6. Correlation Analysis" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Key correlations\n", "metrics = ['veteran_suicide_rate', 'ownership_percentage', 'ptsd_prevalence_pct', 'va_utilization_pct', 'veteran_percentage']\n", "corr_matrix = df[metrics].corr()\n", "\n", "fig, ax = plt.subplots(figsize=(10, 8))\n", "sns.heatmap(corr_matrix, annot=True, cmap='RdBu_r', center=0, ax=ax, fmt='.2f')\n", "ax.set_title('Correlation Matrix', fontsize=14, fontweight='bold')\n", "plt.tight_layout()\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Conclusion\n", "\n", "This notebook demonstrated:\n", "- Loading and exploring veteran analysis data\n", "- Comparing veteran vs civilian suicide rates\n", "- Analyzing firearm ownership correlations\n", "- VA healthcare utilization patterns\n", "\n", "**Important Note**: RAND firearm data is from 2016 (most recent publicly available). Use findings as exploratory, not causal.\n", "\n", "**Author**: Luke Steuber | luke@lukesteuber.com | @lukesteuber.com (Bluesky)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.10.0" } }, "nbformat": 4, "nbformat_minor": 4 }