Open Source GIScience

Joseph Holler's Open Source GIScience Resources at Middlebury College

Malawi Preliminary Analysis

: In this lesson, we will study and execute R code for the analysis.

Build on the shoulders of your predecessors

Your starting point for this lab analysis will be the code developed over the spring and summer of 2020. In the spring, we solved the problem using spatial SQL queries in PostGIS for the vector analysis, and then we completed the raster analysis using graphic modeler to run GDAL tools in QGIS. Over the summer, Kufre Udoh worked on translating all of the SQL queries and QGIS graphic models into R. At the time, we still did not have the final 20% of data from FEWSnet, and thus also could not truly assess our results with expectations of success.

But pay attention…

As you execute the R code, thoroughly compare the code to your analysis plan, and work on integrating the two such that by the end of lab, the analysis plan is identical to the code. Use your best judgement to decide whether to revise the code or to revise your plan.

Prepare a Repository for the Reproduction Attempt

  1. Prior to class, each group should have one complete workflow in a markdown .md text document.
  2. Fork the RP-Malcomb repository. (Wait to do this until Wednesday LAB time!)
  3. Clone the repository to your computer.
  4. Copy your groups workflow markdown content into the report.md document in the repository.
  5. Commit and push this change.
  6. Create a new release of the repository online, titled RP-Malcomb-Preanalysis-Plan and note in the description that this preanalysis was formulated without accessing any data for the study.

Save Livelihood Sensitivity data

Please download the FEWSnet Livelihood zone profile here (for Middlebury students only) and save and extract the data into the data\raw\private folder.

A Draft R Script for the Study

Let’s set the 2004 Traditional Authorities Resilience Score piece of the study aside for our purposes, and focus on the complete analysis for 2010.

This version of the R script is contained in the procedure\code\RP-Malcomb-jh.Rmd markdown file. It is divided into chunks so that you can focus on understanding what happens in each chunk, one at a time.

As you learn, please:

Here are some tips for investigating data outputs as you go

  1. Any data object can be loaded and viewed as an attribute table by clicking on the object in the Environment panel
  2. str(data_name) outputs the structure / metadata of a data frame where data_name should be the name of the data frame
  3. To get a preview of any vector SF objects, plot(st_geometry(data_name)) where data_name is the name of the SF vector data frame
  4. To get a preview of any raster Stars objects, plot(data_name) where data_name is the name of the Stars raster data frame
  5. To save an SF layer to a geopackage for mapping in QGIS, use write_sf() as shown in the final block of code in the R markdown for lab with three parameters: data name, output file ending in .gpkg for geopackage, and output layer name. For example, write_sf(dhsclusters_2010, here("data","scratch","scratch_output.gpkg"), "scratch1") would write the DHS cluster points to a geopackage in the scatch folder, with the layer name scratch1

Further Investigate Data Sources

Now, it’s time to investigate the data sources for the Malcomb et al (2014) study!

I suggest you divide up the task of investigating and describing the data sources and, based on what you find, revising the preanalysis plan. One way to slice it would be to use Table 2 to divide the task by:

  1. Make amendments to your preanalysis plan markdown document.
  2. When you are finished, commit and push the changes, and create a second release titled RP-Malcomb-Preanalysis-Plan-Data and note in the description that this preanalysis plan was amended after investigating all data sources for the study, but prior to starting any analysis.

Revise Workflow

Now that you have seen one draft of the code and you have access to all of the data, please revise your workflow plan. You are most welcome to do this in collaboration with the same group: just share the same common markdown file with one another when you’re finished.

Research Poster of Reproduction Progress

AAG 2021 Poster

The Magic Empty Bracket

What does [] mean? See here

Main Page