Showing posts with label health insurance. Show all posts
Showing posts with label health insurance. Show all posts

Monday, September 8, 2014

An Introduction to Leaflet, Part II: Adding GeoJSON from an External File

Last time, I wrote about adding data from a spreadsheet.  In today's post, I will show how to load GeoJSON data from an external file and create a legend with mutually exclusive categories.

In many tutorials, GeoJSON data is incorporated as part of the code.  However, with a large number of features comes a large block of code that can make writing and debugging difficult. So, reading in the data straight from an external file is valuable.  (One method that is not recommended is creating a JavaScript variable in the GeoJSON file.)

I will be condensing a longer blog post by Lyzi Diamond but feel free to head over to her page for the full explanation and the complete details.  I will also be using code from the Leaflet chloropleth map tutorial, and give its legend a needed update.

The Data
For this post, I will be creating a map of health insurance rates  (2012) in Texas based on data gathered for a post earlier this year on health insurance rates.

What You Will Need
You will need jQuery, a JavaScript library that makes life easier.

Loading the GeoJSON file
In the head of the document, in between style tags, load the jQuery script and reference the GeoJSON file using a link relation.  Here, the file is texas2.geojson.

<script src="./jquery.min.js"></script>
<link rel="polygon" type="application/json" href="/leaflet/healthinsurance/texas2.geojson">    

...and in the body...

$.getJSON($('link[rel="polygon"]').attr("href"), function(data){
var geojson = L.geoJson(data,{...
                .,,with additional code for styling and the popup.

Styling
The Leaflet chloropleth tutorial has nice code for styling by creating two JavaScript functions and using ColorBrewer for getting colors in hexadecimal.

The Legend
The legend code from the Leaflet tutorial is really neat but it needs a little updating.  The legend's categories are not mutually exclusive.  So, I created two arrays (one for the lower bound, the other for upper bound of the categories for percent uninsured) instead of just one for the lower bound in the tutorial.

  var div = L.DomUtil.create('div', 'info legend'),
        lower = [2,12.6,16.9,21,26],
        upper = [12.5,16.8,20.9,25.9,"plus"],
        labels = [];

    // loop through our density intervals and generate a label with a colored square for each interval
    for (var i = 0; i < lower.length; i++) {
        div.innerHTML +=
            '<i style="background:' + getColor(lower[i] + 1) + '"></i> ' +
            lower[i] + '&ndash;' + upper[i]+'<br>';
   }
    return div;
};

I've updated Leaflet's code to make a mutually exclusive legend.
The Final Map
The final map can be viewed at: http://webmapexamples.net/leaflet/healthinsurance/Texas.html. Don't forget,on the webpage you can right-click with your mouse and select "view source" to see the final code.


The final map has popups for County Name + Percent Uninsured
I am still deciding on the topic for the next Leaflet post.  If you have any suggestions, please leave them in the comment section below.

Tuesday, April 15, 2014

Exploring Health Insurance Estimates by County Using GeoDA

Health insurance has been an important topic over the last several months, with the opening and closing of open enrollment at HealthCare.gov.  Most recently, the Census released its first estimates of health insurance coverage at the census tract level.  Typically, estimates have been made for county-level data which is what I explore here from the Small Area Health Insurance Estimates (SAHIE) Program.

I used the latest build of GeoDA 1.5/Beta/preview to explore spatial patterns in 2012 estimates for the percent of population that is uninsured under age 65 by county.  I examined a univariate Local Moran's I and a bivariate example using the percent below the poverty level.

If you have not used GeoDA before to conduct exploratory spatial data analysis (ESDA), you need to give it a try.  The latest build features more data import/export and editing options, a significant improvement over earlier versions.
Some of GeoDA's features are either a) not present in ArcGIS and its extensions or b) only found in ArcGIS Advanced, formerly ArcInfo, namely the creation of spatial weights using polygon contiguity/adjacency. (Note: You can create weights in ArcGIS, based on distance for example.)
To help keep all maps uniform, I imported the results into QGIS. Click on any image below to magnify it. You can find definitions for the terms and statistics used here.

Map of Percent Uninsured by County
Regionally, the South and West US have a smaller percent of counties with low rates of uninsured compared to the Midwest and Northeast. Or rather, they have a higher percent of counties with high rates of uninsured.
For the official map, for comparison, visit here.

LISA Map of Percent Uninsured by County
The map below shows clusters of counties with high, low, low-high, and high-low rates of uninsured.  Light grey areas were not statistically significant.  Spatial weights were created for queen contiguity, 1st order/neighbors.

Global (p=0.02) and local autocorrelation are present.  
The Moran scatter plot of percent uninsured vs.
lagged/neighboring counties has a r-squared value of 0.74 

LISA Map of Percent Uninsured and Percent Below the Poverty Line
Lastly, I examined a bivariate LISA of the percent uninsured and percent below the poverty line (all ages). For this map, I also included the outline of states.  Interestingly, there was no across-the-board global association, as one might expect.  However, state policies undoubtedly affect the percent insured.

No global autocorrelation (p=0.51) but local autocorrelation is present in parts of states or throughout most of particular states, for example the low percent uninsured (and low percent in poverty) in Massachusetts which underwent significant healthcare reform in 2006.  What do you think about some of the other states?

Affordable Care Act Implementation
Unfortunately, some of the states that could benefit the most from the Affordable Care Act (ACA) did not move to implement, as evidenced in this map from the Commonwealth Fund.

Those States sprinting ahead with implementation and those sitting it out.
Bottom line: GeoDA and QGIS are a potent combination.  GeoDA's import, export, and data editing features are much improved.   It is a vital tool for learning and conducting spatial analysis.  However, a few other components of GeoDA are worth mentioning including: making cartograms and conditional maps, connectivity histograms, and performing spatial regression.  As implementation of the ACA moves ahead, it will be interesting to see changes or lack of changes in the percent insured.

QGIS Tip:  Save the symbol styles (categorized) for the cluster types (LISA_CL variable) after you make them, since they can be saved, loaded, and used again for any map layer created in GeoDA as long as you don't change the default variable names.  This is a huge time saver.