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")). Alternatively, use the syntax ?FrEDI::*functionName* (e.g., ?FrEDI::run_fredi_sv()).

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
### Population input file
### - Purpose: Specify the population trajectory to use as an input.
### - Requires columns year, region, state, postal, and pop
### - Default: if null, uses default population trajectory
popInputFile <- NULL

### * Temperature input file
### - 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
### - Contains columns year, temp_C, scenario
tempInputFile <- NULL

### * Temperature type flag
### - 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)
### - Default: defaults to "conus"
temptypeflag <- "global" 

### * Module flag
### - Description: Use this to specify for which module to import inputs 
### - Options: fredi/methane/sv 
### - Default: Defaults to "fredi" if NULL
moduleflag   <- "sv" 

### Use the import_inputs() helper function to format the input trajectories for use in FrEDI
inputs_list <- import_inputs(inputsList = list(
    pop  = popInputFile,
    temp = tempInputFile
  ),
  module = moduleflag
)
inputs_list |> glimpse()
##  list()

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

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

### Sector Flag: Specify a specific sector
### - 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
sectorFlag  <- "Air Quality - Premature Mortality"
  
### Silent Flag
### - Purpose: Specify the level of messaging desired
### - Options: TRUE/FALSE
silentFlag <- TRUE

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_sv <- run_fredi_sv(
  sector      = sectorFlag, 
  inputsList  = inputs_list,
  silent      = silentFlag
) 

### Glimpse results
output_sv |> glimpse()

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

### First five lines of output dataframe
# output_sv[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.