Skip to contents

Running FrEDI with Default Parameters

FrEDI is commonly used to project the annual, climate-driven physical and economic impacts associated with user-defined trajectories of U.S. temperature change (relative to a 1985-2005 baseline), population, and GDP.

This vignette provides a simple example of how to run and analyze data from FrEDI’s default scenario.

This example script:

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

For more information about FrEDI, 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 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.

# To run FrEDI 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'

slrInputFile <- NULL 
  # Description: csv file with time series of global mean sea level rise relative to 2000
  # (units: cm, values: >= 0 and <= 250)
  # data must start in 2000 or earlier
  # column 1 = 'year', column 2 = 'slr_cm'
  # If NULL - slr is calculated from the input temperature trajectory

gdpInputFile <- NULL
  # Description: csv file with time series of Gross Domestic Product (units: 2015$, values: >= 0) 
  # data must start in 2000 or earlier
  # column 1 = 'year', column 2 = 'gdp_usd' 
  # If NULL - use default GDP trajectory

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', columns 2:x = depends on data format (popform)
  # If NULL - use default population trajectory (from ICLUS)


## Input Trajectory parameters
popformFlag = 'wide'   
  # 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,
                        slrfile = slrInputFile,
                        popfile = popInputFile,
                        gdpfile = gdpInputFile,
                        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() will use default temperature, U.S. population, and GDP projections. In this case, run_fredi() 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), and GDP from the EPPA version 6 model (Chen et al., 2015). Default temperature projections are from the GCAM reference scenario. Current default projections of U.S. GDP, national population, and U.S. temperature in the year 2090 are 70 trillion (2015USD), 438 million, and 3.4°C respectively.


Next, set FrEDI runtime parameters

thru2300Flag = FALSE
  # Purpose: 
  #   Specify whether to run FrEDI through 2100 (default) or extend to 2300
  # Default: FALSE (will run to 2100)

baseYearFlag <- NULL     
  # Purpose: 
  #   Specify base year for calculating present values of annual impacts
  # Default: 2010

SectorListFlag <- NULL  
  # Purpose: 
  #   Specify the vector of sectors to calculate results for
  # Default: report output for all sectors
  # See FrEDI:get_sectorInfo() for list of all sectors

aggLevelFlag <- c('national','modelaverage','impactyear')
  # Purpose: 
  #   Specify the desired level of results aggregation. For example,
  #   to report national total results across all underlying climate-model 
  #   damage functions, set the flag to c('national','modelaverage')
  # Options: at least one from c('national', 'modelaverage', 'impactyear',
  #   'impacttype', 'all'), or "none". 
  # Default: c('national', 'modelaverage', 'impactyear','impacttype')

pvFlag <- NULL 
  # Purpose: 
  #   Calculate the present value of annual monetized impacts
  # Options: TRUE/FALSE.
  # Default: FALSE

rateFlag <- NULL         
  # Purpose: 
  #   If pvFlag = TRUE, specify the annual constant discount rate used 
  #   to calculate present values
  # Default: 0.03

maxYearFlag <- 2090
  # Purpose: 
  #   Specify the last year of the analysis 
  # Default: 2090

elasticityFlag <- 1   
  # Purpose: 
  #   Specify the income elasticity used to adjust the Value of a
  #   Statistical Life (VSL)
  # Options: any numeric value
  # Default: 0.4

silentFlag <- TRUE       
  # Purpose:
  #   Specify the level of messaging to the user
  # Options: TRUE/FALSE. 
  # Default: TRUE

outputListFlag <- TRUE
  # Purpose:
  #   Specify whether to return input arguments in addition to results data frame
  # Options: TRUE/FALSE. 
  # Default: FALSE


Step 3. Run FrEDI

Run FrEDI using the main run_fredi() function

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

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

output_df <- run_fredi(inputsList= inputs_list, 
                       thru2300 = thru2300Flag,
                       sectorList = SectorListFlag,
                       aggLevels=aggLevelFlag,
                       pv = pvFlag,
                       baseYear = baseYearFlag,
                       rate = rateFlag,
                       maxYear = maxYearFlag,
                       elasticity = elasticityFlag,
                       silent = silentFlag,
                       outputList = outputListFlag
                       ) 
## Checking input values...
## No temperature scenario provided...using default temperature scenario...
## Creating SLR scenario from temperature scenario...
## No GDP scenario provided...Using default GDP scenario...
## Creating Population scenario from defaults...
## Formatting results...
##  Interpolating between impact year estimates...
##  Calculating model averages...
##  Calculating national totals...
## 
## Finished.
# 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

The following chunks provide three examples options for how to analyze the raw output dataframe from FrEDI::run_fredi()

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

Example 1

Extract national average of economic damages (in billions of dollars in 2015$) for all FrEDI sectors for a specified year

Output of this chunk includes a snapshot of a subset of the resulting dataframe

*Note: Use the sectorprimary ==1 and includeaggregate ==1 flags to filter the FrEDI dataframe for impacts from only the default impact sectors and variants.

#specify year
c_years = c(2090)

#filter and aggregate data, assign to aggregate categories
df_filter <- output_df$results %>%
  # filter for primary sectors and variants (included to avoid 
  #  double counting final impacts)
    filter(sectorprimary ==1,
           includeaggregate ==1) %>%
  # use helper function to aggregate across the impact types of 
  #  each sector
    aggregate_impacts(aggLevels = 'impactType') %>%
  # filter for national aggregate results averaged across all GCMs, 
  #  for the specified year
    filter(model %in% c('Average','Interpolation'),
           region == "National Total",
           year %in% c_years) %>%
  # convert to billions of dollars
    mutate(annual_impacts = annual_impacts /1e9) %>% 
  # round results
    mutate(across(annual_impacts, round, 0)) %>%
  # select (and rename) relevant columns
    select('sector','region','year','annual_impacts') %>%
    rename('billions_2015$' = annual_impacts) 
    

#Display first 10 sectors
library('kableExtra')
kable(df_filter[1:10,], 
      caption = 'Example *Subset* of 2090 Annual National Sectoral Climate-Driven Impacts') %>%
  kable_styling(font_size = 12, full_width = F)
Example Subset of 2090 Annual National Sectoral Climate-Driven Impacts
sector region year billions_2015$
ATS Extreme Temperature National Total 2090 2196
Air Quality National Total 2090 215
CIL Agriculture National Total 2090 11
CIL Crime National Total 2090 1
Coastal Properties National Total 2090 9
Electricity Demand and Supply National Total 2090 15
Electricity Transmission and Distribution National Total 2090 12
High Tide Flooding and Traffic National Total 2090 139
Inland Flooding National Total 2090 1
Labor National Total 2090 44

Example 2

Extract national average of physical damages for all FrEDI sectors that include physical impacts, for a specified year

Output of this chunk includes a snapshot of a subset of the resulting dataframe

*Note: Use the sectorprimary ==1 and includeaggregate ==1 flags to filter the FrEDI dataframe for impacts from only the default impact sectors and variants.

#specify year
c_years = c(2090)

#filter and aggregate data, assign to aggregate categories
df_filter <- output_df$results %>%
  # filter for primary sectors and variants (included to avoid 
  #  double counting final impacts)
    filter(sectorprimary ==1,
           includeaggregate ==1) %>%
  # filter for national aggregate results averaged across all GCMs
  #  and only include sectors that include physical impacts
    filter(model %in% c('Average','Interpolation'),
           region == "National Total",
           year %in% c_years,
           !(is.na(physicalmeasure))) %>%
  # round results
   mutate(across(c('physical_impacts'), round, 0)) %>%
  # select relevant columns to display
  select('sector','region','year','physicalmeasure',
         'impactType','physical_impacts')

#display first 10 rows
kable(df_filter[1:10,], 
      caption = 'Example *Subset* of 2090 Annual National Sectoral Climate-Driven Physical Impacts') %>%
  kable_styling(font_size = 12, full_width = F)
Example Subset of 2090 Annual National Sectoral Climate-Driven Physical Impacts
sector region year physicalmeasure impactType physical_impacts
ATS Extreme Temperature National Total 2090 Premature Mortality N/A 74349
Air Quality National Total 2090 Premature Mortality Ozone 1773
Air Quality National Total 2090 Premature Mortality PM2.5 5511
CIL Crime National Total 2090 Crimes Property 2753
CIL Crime National Total 2090 Crimes Violent 4627
Labor National Total 2090 Hours Lost N/A 580813874
Mental Health National Total 2090 Premature Mortality N/A 1345
Southwest Dust National Total 2090 Premature Mortality All Mortality 560
Valley Fever National Total 2090 Premature Mortality Mortality 420
Wildfire National Total 2090 Premature Mortality Mortality 1548

Example 3

Extract regional economic impacts for FrEDI sectors for a specified year

Output of this chunk includes a snapshot of a subset of the resulting dataframe

*Note: Use the sectorprimary ==1 and includeaggregate ==1 flags to filter the FrEDI dataframe for impacts from only the default impact sectors and variants.

#specify year
c_years = c(2090)

#filter and aggregate data, assign to aggregate categories
df_filter <- output_df$results %>%
  # filter for primary sectors and variants (included to avoid 
  #  double counting final impacts)
    filter(sectorprimary ==1,
           includeaggregate ==1) %>%
  # use helper function to aggregate across the impact types of 
  #  each sector
    aggregate_impacts(aggLevels = 'impactType') %>%
  # filter for regional results, averaged across all GCMs, 
  #  for the specified year
    filter(model %in% c('Average','Interpolation'),
           !(region == "National Total"),
           year %in% c_years) %>%
  # convert to billions (2015$)
    mutate(annual_impacts = annual_impacts /1e9) %>%
  # round results
    mutate(across(c('annual_impacts'), round, 0)) %>%
  # sum across all sectors for each region
    group_by_at(.vars = c('region','year')) %>%
     summarize_at(c("annual_impacts"), sum, na.rm=T) %>%
    ungroup %>%
  # select (and rename) relevant columns
    select('region','year','annual_impacts')%>%
    rename('billions_2015$' = annual_impacts)


kable(df_filter[1:7,], 
      caption = 'Example 2090 Annual Climate-Driven Damages, by Region') %>%
  kable_styling(font_size = 12, full_width = F)
Example 2090 Annual Climate-Driven Damages, by Region
region year billions_2015$
Midwest 2090 426
Northeast 2090 553
Northern Plains 2090 45
Northwest 2090 90
Southeast 2090 844
Southern Plains 2090 374
Southwest 2090 528

Please contact the FrEDI developers with additional questions.