{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Geographically Weighted Regression (Part II): COVID 19 Mortality\n",
"\n",
"Author: Naomi W. Lazarus, PhD
\n",
"Date Created: 6-15-21\n",
"\n",
"This notebook provides the code for running a Geographically Weighted Regression (GWR) using COVID-19 death-case ratios as the dependent variable and independent variables representing age and underlying conditions. It is an exploratory analysis of spatial relationships between COVID-19, age demographics, and comorbidities. It is not recommended for predictive purposes."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Notebook Outline\n",
"\n",
"- [Introduction](#Intro)\n",
" - [Install MGWR package](#Install)\n",
" - [Load required packages](#Load)\n",
"- [Load and preview data for deat-case ratios for peak period 1](#Peak1)\n",
" - [Preprocess data for GWR](#Data1)\n",
" - [Review GWR Results](#Results1)\n",
"- [Load and preview data for death-case ratios for peak period 2](#Peak2)\n",
" - [Preprocess data for GWR](#Data2)\n",
" - [Review GWR Results](#Results2)\n",
"- [References](#Ref)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"# Introduction\n",
"\n",
"The notebooks consists of two sections. The first uses covid-19 death-case ratios for peak period 1 (03/01/20 - 04/30/20). The second uses covid-19 death-case ratios for peak period 2 (06/01/20 - 07/31/20). The following links provide information on file descriptions and metadata. \n",
"\n",
"[Link to Metadata](Data_Files2/Metadata.txt)
\n",
"[Link to file descriptions](Data_Files2/Files.txt)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"## Install MGWR package"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"try:\n",
" from mgwr.gwr import GWR\n",
"except:\n",
" print('Installing MGWR')\n",
" ! pip install -U mgwr\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"## Load required packages"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import libpysal as ps\n",
"from spreg import OLS\n",
"from mgwr.gwr import GWR, MGWR\n",
"from mgwr.sel_bw import Sel_BW\n",
"from mgwr.utils import compare_surfaces, truncate_colormap\n",
"import geopandas as gp\n",
"import matplotlib.pyplot as plt\n",
"import matplotlib as mpl"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"# Load and preview data for death-case ratios for peak period 1"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"covid_DR1 = gp.read_file('/home/jovyan/shared_data/data/geospatialfellows21/lazarus_data/Data_Files2/Layer_DR1_1.shp')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n", " | STATEFP | \n", "COUNTYFP | \n", "COUNTYNS | \n", "GEOID | \n", "NAME | \n", "NAMELSAD | \n", "LSAD | \n", "CLASSFP | \n", "MTFCC | \n", "CSAFP | \n", "... | \n", "PCT_over75 | \n", "DIAB_PCT | \n", "CARDIO_MR | \n", "OBESE_PCT | \n", "DR1_log | \n", "Shape_Leng | \n", "Shape_Area | \n", "X | \n", "Y | \n", "geometry | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "31 | \n", "109 | \n", "00835876 | \n", "31109 | \n", "Lancaster | \n", "Lancaster County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "339 | \n", "... | \n", "5.4 | \n", "8.1 | \n", "186.9 | \n", "29.9 | \n", "-0.380211 | \n", "191498.450302 | \n", "2.181031e+09 | \n", "-5.775873e+04 | \n", "198290.895484 | \n", "POLYGON ((-76484.353 198568.818, -76478.478 19... | \n", "
1 | \n", "46 | \n", "099 | \n", "01265772 | \n", "46099 | \n", "Minnehaha | \n", "Minnehaha County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "None | \n", "... | \n", "5.1 | \n", "8.2 | \n", "229.2 | \n", "31.1 | \n", "-0.230023 | \n", "186372.852811 | \n", "2.103144e+09 | \n", "-6.367993e+04 | \n", "519393.038636 | \n", "POLYGON ((-71439.032 538818.414, -71405.569 53... | \n", "
2 | \n", "39 | \n", "063 | \n", "01074044 | \n", "39063 | \n", "Hancock | \n", "Hancock County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "534 | \n", "... | \n", "7.1 | \n", "9.8 | \n", "296.3 | \n", "35.9 | \n", "0.431798 | \n", "154277.000259 | \n", "1.375313e+09 | \n", "1.029369e+06 | \n", "291980.881448 | \n", "POLYGON ((1010444.794 298225.136, 1010431.187 ... | \n", "
3 | \n", "48 | \n", "189 | \n", "01383880 | \n", "48189 | \n", "Hale | \n", "Hale County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "352 | \n", "... | \n", "6.0 | \n", "13.7 | \n", "266.0 | \n", "31.5 | \n", "1.204120 | \n", "204211.504278 | \n", "2.597938e+09 | \n", "-5.365911e+05 | \n", "-529891.392654 | \n", "POLYGON ((-561065.818 -536037.871, -560987.294... | \n", "
4 | \n", "01 | \n", "027 | \n", "00161539 | \n", "01027 | \n", "Clay | \n", "Clay County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "None | \n", "... | \n", "8.3 | \n", "14.2 | \n", "452.0 | \n", "37.1 | \n", "0.677781 | \n", "203930.129612 | \n", "1.568824e+09 | \n", "9.422905e+05 | \n", "-583488.845178 | \n", "POLYGON ((930647.181 -578247.838, 930643.004 -... | \n", "
5 rows × 39 columns
\n", "\n", " | STATEFP | \n", "COUNTYFP | \n", "COUNTYNS | \n", "GEOID | \n", "NAME | \n", "NAMELSAD | \n", "LSAD | \n", "CLASSFP | \n", "MTFCC | \n", "CSAFP | \n", "... | \n", "DIAB_PCT | \n", "CARDIO_MR | \n", "OBESE_PCT | \n", "DR1_log | \n", "Shape_Leng | \n", "Shape_Area | \n", "X | \n", "Y | \n", "geometry | \n", "R2 | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "31 | \n", "109 | \n", "00835876 | \n", "31109 | \n", "Lancaster | \n", "Lancaster County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "339 | \n", "... | \n", "8.1 | \n", "186.9 | \n", "29.9 | \n", "-0.380211 | \n", "191498.450302 | \n", "2.181031e+09 | \n", "-5.775873e+04 | \n", "198290.895484 | \n", "POLYGON ((-76484.353 198568.818, -76478.478 19... | \n", "0.215712 | \n", "
1 | \n", "46 | \n", "099 | \n", "01265772 | \n", "46099 | \n", "Minnehaha | \n", "Minnehaha County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "None | \n", "... | \n", "8.2 | \n", "229.2 | \n", "31.1 | \n", "-0.230023 | \n", "186372.852811 | \n", "2.103144e+09 | \n", "-6.367993e+04 | \n", "519393.038636 | \n", "POLYGON ((-71439.032 538818.414, -71405.569 53... | \n", "0.215420 | \n", "
2 | \n", "39 | \n", "063 | \n", "01074044 | \n", "39063 | \n", "Hancock | \n", "Hancock County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "534 | \n", "... | \n", "9.8 | \n", "296.3 | \n", "35.9 | \n", "0.431798 | \n", "154277.000259 | \n", "1.375313e+09 | \n", "1.029369e+06 | \n", "291980.881448 | \n", "POLYGON ((1010444.794 298225.136, 1010431.187 ... | \n", "0.103319 | \n", "
3 | \n", "48 | \n", "189 | \n", "01383880 | \n", "48189 | \n", "Hale | \n", "Hale County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "352 | \n", "... | \n", "13.7 | \n", "266.0 | \n", "31.5 | \n", "1.204120 | \n", "204211.504278 | \n", "2.597938e+09 | \n", "-5.365911e+05 | \n", "-529891.392654 | \n", "POLYGON ((-561065.818 -536037.871, -560987.294... | \n", "0.240960 | \n", "
4 | \n", "01 | \n", "027 | \n", "00161539 | \n", "01027 | \n", "Clay | \n", "Clay County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "None | \n", "... | \n", "14.2 | \n", "452.0 | \n", "37.1 | \n", "0.677781 | \n", "203930.129612 | \n", "1.568824e+09 | \n", "9.422905e+05 | \n", "-583488.845178 | \n", "POLYGON ((930647.181 -578247.838, 930643.004 -... | \n", "0.089116 | \n", "
5 rows × 40 columns
\n", "\n", " | STATEFP | \n", "COUNTYFP | \n", "COUNTYNS | \n", "GEOID | \n", "NAME | \n", "NAMELSAD | \n", "LSAD | \n", "CLASSFP | \n", "MTFCC | \n", "CSAFP | \n", "... | \n", "CARDIO_MR | \n", "OBESE_PCT | \n", "DR1_log | \n", "Shape_Leng | \n", "Shape_Area | \n", "X | \n", "Y | \n", "geometry | \n", "R2 | \n", "SR | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "31 | \n", "109 | \n", "00835876 | \n", "31109 | \n", "Lancaster | \n", "Lancaster County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "339 | \n", "... | \n", "186.9 | \n", "29.9 | \n", "-0.380211 | \n", "191498.450302 | \n", "2.181031e+09 | \n", "-5.775873e+04 | \n", "198290.895484 | \n", "POLYGON ((-76484.353 198568.818, -76478.478 19... | \n", "0.215712 | \n", "-2.678272 | \n", "
1 | \n", "46 | \n", "099 | \n", "01265772 | \n", "46099 | \n", "Minnehaha | \n", "Minnehaha County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "None | \n", "... | \n", "229.2 | \n", "31.1 | \n", "-0.230023 | \n", "186372.852811 | \n", "2.103144e+09 | \n", "-6.367993e+04 | \n", "519393.038636 | \n", "POLYGON ((-71439.032 538818.414, -71405.569 53... | \n", "0.215420 | \n", "-2.302788 | \n", "
2 | \n", "39 | \n", "063 | \n", "01074044 | \n", "39063 | \n", "Hancock | \n", "Hancock County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "534 | \n", "... | \n", "296.3 | \n", "35.9 | \n", "0.431798 | \n", "154277.000259 | \n", "1.375313e+09 | \n", "1.029369e+06 | \n", "291980.881448 | \n", "POLYGON ((1010444.794 298225.136, 1010431.187 ... | \n", "0.103319 | \n", "-0.732327 | \n", "
3 | \n", "48 | \n", "189 | \n", "01383880 | \n", "48189 | \n", "Hale | \n", "Hale County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "352 | \n", "... | \n", "266.0 | \n", "31.5 | \n", "1.204120 | \n", "204211.504278 | \n", "2.597938e+09 | \n", "-5.365911e+05 | \n", "-529891.392654 | \n", "POLYGON ((-561065.818 -536037.871, -560987.294... | \n", "0.240960 | \n", "1.929299 | \n", "
4 | \n", "01 | \n", "027 | \n", "00161539 | \n", "01027 | \n", "Clay | \n", "Clay County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "None | \n", "... | \n", "452.0 | \n", "37.1 | \n", "0.677781 | \n", "203930.129612 | \n", "1.568824e+09 | \n", "9.422905e+05 | \n", "-583488.845178 | \n", "POLYGON ((930647.181 -578247.838, 930643.004 -... | \n", "0.089116 | \n", "-0.208833 | \n", "
5 rows × 41 columns
\n", "\n", " | STATEFP | \n", "COUNTYFP | \n", "COUNTYNS | \n", "GEOID | \n", "NAME | \n", "NAMELSAD | \n", "LSAD | \n", "CLASSFP | \n", "MTFCC | \n", "CSAFP | \n", "... | \n", "PCT_over75 | \n", "DIAB_PCT | \n", "CARDIO_MR | \n", "OBESE_PCT | \n", "DR2_log | \n", "Shape_Leng | \n", "Shape_Area | \n", "X | \n", "Y | \n", "geometry | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "31 | \n", "109 | \n", "00835876 | \n", "31109 | \n", "Lancaster | \n", "Lancaster County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "339 | \n", "... | \n", "5.4 | \n", "8.1 | \n", "186.9 | \n", "29.9 | \n", "-0.411620 | \n", "191498.450302 | \n", "2.181031e+09 | \n", "-5.775873e+04 | \n", "198290.895484 | \n", "POLYGON ((-76484.353 198568.818, -76478.478 19... | \n", "
1 | \n", "46 | \n", "099 | \n", "01265772 | \n", "46099 | \n", "Minnehaha | \n", "Minnehaha County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "None | \n", "... | \n", "5.1 | \n", "8.2 | \n", "229.2 | \n", "31.1 | \n", "0.245761 | \n", "186372.852811 | \n", "2.103144e+09 | \n", "-6.367993e+04 | \n", "519393.038636 | \n", "POLYGON ((-71439.032 538818.414, -71405.569 53... | \n", "
2 | \n", "39 | \n", "063 | \n", "01074044 | \n", "39063 | \n", "Hancock | \n", "Hancock County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "534 | \n", "... | \n", "7.1 | \n", "9.8 | \n", "296.3 | \n", "35.9 | \n", "-0.403121 | \n", "154277.000259 | \n", "1.375313e+09 | \n", "1.029369e+06 | \n", "291980.881448 | \n", "POLYGON ((1010444.794 298225.136, 1010431.187 ... | \n", "
3 | \n", "48 | \n", "189 | \n", "01383880 | \n", "48189 | \n", "Hale | \n", "Hale County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "352 | \n", "... | \n", "6.0 | \n", "13.7 | \n", "266.0 | \n", "31.5 | \n", "0.207998 | \n", "204211.504278 | \n", "2.597938e+09 | \n", "-5.365911e+05 | \n", "-529891.392654 | \n", "POLYGON ((-561065.818 -536037.871, -560987.294... | \n", "
4 | \n", "01 | \n", "027 | \n", "00161539 | \n", "01027 | \n", "Clay | \n", "Clay County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "None | \n", "... | \n", "8.3 | \n", "14.2 | \n", "452.0 | \n", "37.1 | \n", "0.246672 | \n", "203930.129612 | \n", "1.568824e+09 | \n", "9.422905e+05 | \n", "-583488.845178 | \n", "POLYGON ((930647.181 -578247.838, 930643.004 -... | \n", "
5 rows × 39 columns
\n", "\n", " | STATEFP | \n", "COUNTYFP | \n", "COUNTYNS | \n", "GEOID | \n", "NAME | \n", "NAMELSAD | \n", "LSAD | \n", "CLASSFP | \n", "MTFCC | \n", "CSAFP | \n", "... | \n", "DIAB_PCT | \n", "CARDIO_MR | \n", "OBESE_PCT | \n", "DR2_log | \n", "Shape_Leng | \n", "Shape_Area | \n", "X | \n", "Y | \n", "geometry | \n", "R2 | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "31 | \n", "109 | \n", "00835876 | \n", "31109 | \n", "Lancaster | \n", "Lancaster County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "339 | \n", "... | \n", "8.1 | \n", "186.9 | \n", "29.9 | \n", "-0.411620 | \n", "191498.450302 | \n", "2.181031e+09 | \n", "-5.775873e+04 | \n", "198290.895484 | \n", "POLYGON ((-76484.353 198568.818, -76478.478 19... | \n", "0.198936 | \n", "
1 | \n", "46 | \n", "099 | \n", "01265772 | \n", "46099 | \n", "Minnehaha | \n", "Minnehaha County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "None | \n", "... | \n", "8.2 | \n", "229.2 | \n", "31.1 | \n", "0.245761 | \n", "186372.852811 | \n", "2.103144e+09 | \n", "-6.367993e+04 | \n", "519393.038636 | \n", "POLYGON ((-71439.032 538818.414, -71405.569 53... | \n", "0.178228 | \n", "
2 | \n", "39 | \n", "063 | \n", "01074044 | \n", "39063 | \n", "Hancock | \n", "Hancock County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "534 | \n", "... | \n", "9.8 | \n", "296.3 | \n", "35.9 | \n", "-0.403121 | \n", "154277.000259 | \n", "1.375313e+09 | \n", "1.029369e+06 | \n", "291980.881448 | \n", "POLYGON ((1010444.794 298225.136, 1010431.187 ... | \n", "0.122082 | \n", "
3 | \n", "48 | \n", "189 | \n", "01383880 | \n", "48189 | \n", "Hale | \n", "Hale County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "352 | \n", "... | \n", "13.7 | \n", "266.0 | \n", "31.5 | \n", "0.207998 | \n", "204211.504278 | \n", "2.597938e+09 | \n", "-5.365911e+05 | \n", "-529891.392654 | \n", "POLYGON ((-561065.818 -536037.871, -560987.294... | \n", "0.195827 | \n", "
4 | \n", "01 | \n", "027 | \n", "00161539 | \n", "01027 | \n", "Clay | \n", "Clay County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "None | \n", "... | \n", "14.2 | \n", "452.0 | \n", "37.1 | \n", "0.246672 | \n", "203930.129612 | \n", "1.568824e+09 | \n", "9.422905e+05 | \n", "-583488.845178 | \n", "POLYGON ((930647.181 -578247.838, 930643.004 -... | \n", "0.118513 | \n", "
5 rows × 40 columns
\n", "\n", " | STATEFP | \n", "COUNTYFP | \n", "COUNTYNS | \n", "GEOID | \n", "NAME | \n", "NAMELSAD | \n", "LSAD | \n", "CLASSFP | \n", "MTFCC | \n", "CSAFP | \n", "... | \n", "CARDIO_MR | \n", "OBESE_PCT | \n", "DR2_log | \n", "Shape_Leng | \n", "Shape_Area | \n", "X | \n", "Y | \n", "geometry | \n", "R2 | \n", "SR | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "31 | \n", "109 | \n", "00835876 | \n", "31109 | \n", "Lancaster | \n", "Lancaster County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "339 | \n", "... | \n", "186.9 | \n", "29.9 | \n", "-0.411620 | \n", "191498.450302 | \n", "2.181031e+09 | \n", "-5.775873e+04 | \n", "198290.895484 | \n", "POLYGON ((-76484.353 198568.818, -76478.478 19... | \n", "0.198936 | \n", "-1.306488 | \n", "
1 | \n", "46 | \n", "099 | \n", "01265772 | \n", "46099 | \n", "Minnehaha | \n", "Minnehaha County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "None | \n", "... | \n", "229.2 | \n", "31.1 | \n", "0.245761 | \n", "186372.852811 | \n", "2.103144e+09 | \n", "-6.367993e+04 | \n", "519393.038636 | \n", "POLYGON ((-71439.032 538818.414, -71405.569 53... | \n", "0.178228 | \n", "0.591529 | \n", "
2 | \n", "39 | \n", "063 | \n", "01074044 | \n", "39063 | \n", "Hancock | \n", "Hancock County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "534 | \n", "... | \n", "296.3 | \n", "35.9 | \n", "-0.403121 | \n", "154277.000259 | \n", "1.375313e+09 | \n", "1.029369e+06 | \n", "291980.881448 | \n", "POLYGON ((1010444.794 298225.136, 1010431.187 ... | \n", "0.122082 | \n", "-1.881861 | \n", "
3 | \n", "48 | \n", "189 | \n", "01383880 | \n", "48189 | \n", "Hale | \n", "Hale County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "352 | \n", "... | \n", "266.0 | \n", "31.5 | \n", "0.207998 | \n", "204211.504278 | \n", "2.597938e+09 | \n", "-5.365911e+05 | \n", "-529891.392654 | \n", "POLYGON ((-561065.818 -536037.871, -560987.294... | \n", "0.195827 | \n", "0.179054 | \n", "
4 | \n", "01 | \n", "027 | \n", "00161539 | \n", "01027 | \n", "Clay | \n", "Clay County | \n", "06 | \n", "H1 | \n", "G4020 | \n", "None | \n", "... | \n", "452.0 | \n", "37.1 | \n", "0.246672 | \n", "203930.129612 | \n", "1.568824e+09 | \n", "9.422905e+05 | \n", "-583488.845178 | \n", "POLYGON ((930647.181 -578247.838, 930643.004 -... | \n", "0.118513 | \n", "0.036173 | \n", "
5 rows × 41 columns
\n", "