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

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'


popInputFile <- NULL
  # Description: csv file with time series of annual NCA regional population (values >= 0) 
  # data must start in 2000 or earlier
  # column 1 = 'year', column 2 = region, column 3 = population (long popform)
  #   NCA region names: 'Midwest', 'Northeast', 'Northern.Plains', 'Northwest',
  #   'Southeast', 'Southern.Plains', 'Southwest'
  # If NULL - use default population trajectory (from ICLUS)

## Input Trajectory parameters
popformFlag = 'long'   
  # Description: Use this to specify the format of the regional population data
  # Options: wide/long. 
  # Wide = columns 2-8 correspond to population in each NCA region. 
  # Long = column 2 = NCA region name ('region'), 
  # column 3 = population for that region ('reg_pop'). 
  # NCA region names: 'Midwest', 'Northeast', 'Northern.Plains', 'Northwest',
  #   'Southeast', 'Southern.Plains', 'Southwest'

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,
                        popfile = popInputFile,
                        temptype = temptypeflag,
                        popform = popformFlag)

# print out how many custom input files were loaded 
# should be = 1 if using custom temperature only
if ( length(inputs_list) ==0 ){
  print('CONFIRM: No user-specific input data loaded')
} else {
  print( paste('CONFIRM: Number of user-specified input files loaded:',
               length(inputs_list)))
}
## [1] "CONFIRM: No user-specific input data loaded"

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 fredi_sv() results for a single impact sector
# NOTE: the 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_C <- inputs_list$tempInput 

# take formatted population vector from the output of the
# import_inputs() helper function
 reg_pop <- inputs_list$popInput

# 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 
  #   current sectors
driverFlag <- temp_C
  # Purpose:
  #   Specify the temperature trajectory to use as an input. 
  #   Temperature needs to be in degrees C, *CONUS* temperature, relative
  #   to the 1986-2005 average baseline
  #   NOTE: if temperature is in global degrees, use the 
  #   FrEDI::convertTemps() helper function to convert from global to CONUS
popFlag <- reg_pop
  # Purpose:
  #   Specify the regional population trajectory to use as an input. 
  #   Population needs to be regional, relative
  #   to the 1986-2005 average baseline, in the long popform format
silentFlag = TRUE
  # Purpose:
  #   Specify the level of messaging desired
  # Options: TRUE/FALSE
saveFlag = FALSE
  # Purpose:
  #   Specify whether to save output results to a pre-formatted Excel workbook
  # Options: TRUE/FALSE
outFlag = getwd()
  # Purpose:
  #   Specify a file directory to save the Excel file.
  # Options: TRUE/FALSE
overwriteFlag = T
  # Purpose: 
  #   Specify whether or not to overwrite any existing Excel workbooks
  # Options: TRUE/FALSE
addDateFlag = FALSE
  # Purpose: 
  #   Specify whether to add the date to the name of the output Excel file if
  # 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,
                          save        = saveFlag, 
                          outpath     = outFlag,
                          overwrite   = overwriteFlag,
                          addDate     = addDateFlag) 

# 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[5,]

Step 4. Analyze FrEDI_SV

Results from the FrEDI::run_fredi_sv() module can be analyzed directly in R or in the accompanying MS excel workbook (if input save = TRUE)

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.