Skip to contents

Running FrEDI’s Social Vulnerability Module

This vignette provides a simple example of how to run and analyze data from FrEDI’s SV module, under a default scenario, for a specific sector.

This example script:

  1. Installs the FrEDI R package from GitHub
  2. Sets FrEDI_SV input and run parameters.
  3. Runs FrEDI_SV with inputs specified in Step 2
  4. Shows example types of analyses using FrEDI_SV output data.

For more information about FrEDI or FrEDI_SV, see the About page and FrEDI Technical Documentation


Step 1. Install FrEDI R package

When installing for the first time, see Installing & Running FrEDI page.

Load package

## Warning: package 'tidyverse' was built under R version 4.4.1
## Warning: package 'ggplot2' was built under R version 4.4.1
## Warning: package 'tibble' was built under R version 4.4.1
## Warning: package 'tidyr' was built under R version 4.4.1
## Warning: package 'readr' was built under R version 4.4.1
## Warning: package 'purrr' was built under R version 4.4.1
## Warning: package 'dplyr' was built under R version 4.4.1
## Warning: package 'stringr' was built under R version 4.4.1
## Warning: package 'forcats' was built under R version 4.4.1
## Warning: package 'lubridate' was built under R version 4.4.1

After successfully installing FrEDI, documentation for FrEDI functions can be accessed in the same way as for other R packages.

For an overview of FrEDI’s user-defined functions, type library(help="FrEDI") into an R console (this command will show documentation for FrEDI even if the package is not installed).

For documentation for a specific function, type help("*functionName*", package="FrEDI") into an R console, where functionName is the name of one of the functions in FrEDI (e.g., help("aggregate_impacts", package="FrEDI")).

If FrEDI has been installed, users can also search for function-specific documentation in RStudio through the Help window. Move the focus to the Help window using the keyboard shortcut Ctrl+3 or toggle the search field in Help using Ctrl+Alt+F1. Documentation for each function includes examples.


Step 2. Set FrEDI_SV Runtime parameters

First, use this chunk to specify & format input projections. Either provide paths to specific files, or set to NULL to use default projections for each variable

Use this chunk to specify the input trajectories (temperature, population, GDP) and runtime parameters for FrEDI_SV.

# To run FrEDI_SV for more than one scenario, the code below can be
# adapted into a loop to format the inputs for each scenario. 

#***********************************************
#1. Specify & Format Input Trajectories (temperature, population, U.S. GDP)

## Input Files
tempInputFile <- NULL
# Description: csv file with time series of temperature relative to 1986-2005 average 
# (units: degC, values: >=0)
# data must start in 2000 or earlier and can be global or CONUS
# If global --> must convert to CONUS temperature using the import_inputs() helper function
# column 1 = 'year', column 2 = 'temp_C'

temptypeflag <- 'global' 
# Description: Use this to specify whether the input temperature is global or CONUS
# import_inputs() will convert to global to CONUS temperature
# Options: global (input is global T), conus (input is CONUS T)


## Use the import_inputs() helper function to format the input trajectories for use in FrEDI
inputs_list <- import_inputs(tempfile = tempInputFile)

If no input files are specified, run_fredi_sv() will use default temperature and U.S. regional population projections. In this case, run_fredi_sv() will calculate annual projected sea level rise based on the default temperature change.

Default population scenarios are based on UN Median Population projection (United Nations, 2015) and EPA’s ICLUSv2 model (Bierwagen et al., 2010; EPA 2017). Default temperature projections are from the GCAM reference scenario. Current default projections of U.S. national population and U.S. temperature in the year 2090 are 438 million, and 3.4°C respectively.


Next, set FrEDI_SV runtime parameters

# Calculate the run_fredi_sv() results for a single impact sector

# NOTE: the run_fredi_sv() module takes a few minutes to run because
# the damages are calculated at the Census tract level and then 
# aggregated to the regional level

# take formatted temperature vector from the output of the
# import_inputs() helper function
 temp_input <- inputs_list$tempInput 

# To see all available sectors, run:
# FrEDI::get_sv_sectorInfo()

# Specify a specific sector
sectorFlag = "Air Quality - Premature Mortality"
  # Purpose:
  #   Specify the SV sector to calculate (can only run one sector at once)
  # Options: run FrEDI::get_sv_sectorInfo() to get a list of the 
  #   possible sectors
driverFlag <- temp_input
  # Purpose:
  #   Specify the temperature trajectory (up to 4) to use as an input. 
  #   Temperature needs to be in degrees C, *CONUS* temperature, relative
  #   to the 1986-2005 average baseline
  #   column 1 = 'year','column 2 = 'scenario', column 3 = 'temp_C'
  #   NOTE: if temperature is in global degrees, use the 
  #   FrEDI::convertTemps() helper function to convert from global to CONUS
popFlag <- NULL
  # Purpose:
  #   Specify the population trajectory to use as an input.
  # column 1 = 'year', column 2 = 'region', column 3 = 'state', column 4 = 'postal', column 5 = 'state_pop'
  # default = if null, uses default population trajectory
silentFlag = TRUE
  # Purpose:
  #   Specify the level of messaging desired
  # Options: TRUE/FALSE

Step 3. Run FrEDI_SV

Run FrEDI_SV using the main run_fredi_sv() function

Default parameter options are used for any parameters that are not specified in run_fredi_sv().

Note: run_fredi_sv() takes longer to run than the main module, run_fredi(), as SV damage calculations are conducted at finer spatial scales (e.g., U.S. Census tract vs. regional level).

#Run FrEDI using inputs and parameters set in Step #2

output_df <- run_fredi_sv(sector      = sectorFlag, 
                          driverInput = driverFlag, 
                          popInput    = popFlag,
                          silent      = silentFlag) 

# Option: write output
## Write Full Dataframe to CSV (or feather)
# write.csv(output_df, './output/example_output.csv')

#First five lines of output dataframe
#output_df[1:5,]

Step 4. Analyze FrEDI_SV

Results from the FrEDI::run_fredi_sv() module can be analyzed directly in R

Disclaimer: These results only provide an illustrative example and should NOT be used for further analysis.

Example analyses coming soon

Please contact the FrEDI developers with additional questions.