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:
-
Installs the
FrEDI
R package from GitHub -
Sets
FrEDI
input and run parameters. -
Runs
FrEDI
with inputs specified in Step 2 -
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
## 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
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 U.S. Gross Domestic Product (units: 2015$, values: >= 0)
# data must start in 2010 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 U.S. population (values >= 0)
# data must start in 2010 or earlier
# column 1 = 'year', column 2 = 'pop', column 3 = depends on "popArea"
# If NULL - use default population trajectory (from ICLUS)
## Input Trajectory parameters
popAreaflag = 'state'
# Description: Use this to specify the geographical scale of the population data
# Options: "state","regional","national".
# For more information, see `?import_inputs()` for more information
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,
popArea = popAreaflag)
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)
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')
maxYearFlag <- 2100
# Purpose:
# Specify the last year of the analysis
# Default: 2100
elasticityFlag <- 1
# Purpose:
# Specify the income elasticity used to adjust the Value of a
# Statistical Life (VSL)
# Options: any numeric value
# Default: 1
outputListFlag <- FALSE
# Purpose:
# Specify whether to return input arguments in addition to results data frame
# Options: TRUE/FALSE.
# Default: FALSE
allColsFlag <- TRUE
# Purpose:
# Specify whether to include physical and economic multipliers (used in testing)
# Options: TRUE/FALSE.
# Default: FALSE
silentFlag <- TRUE
# Purpose:
# Specify the level of messaging to the user
# Options: TRUE/FALSE.
# Default: TRUE
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,
sectorList = SectorListFlag,
aggLevels = aggLevelFlag,
elasticity = elasticityFlag,
maxYear = maxYearFlag,
thru2300 = thru2300Flag,
outputList = outputListFlag,
allCols = allColsFlag,
silent = silentFlag
)
## 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...
## Updating scalars...
## Calculating impacts...
## Formatting results...
##
## 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[1: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. For recommendations on aggregating impacts across
sectors, see the FrEDI Technical Documentation (Chapter 2) and
FrEDI::run_fredi() documentation.
#specify year
c_years = c(2100)
df_filter <- output_df %>%
# 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 2100 Annual National Sectoral Climate-Driven Impacts') %>%
kable_styling(font_size = 12, full_width = F)
sector | region | year | billions_2015$ |
---|---|---|---|
ATS Temperature-Related Mortality | National Total | 2100 | 2767 |
CIL Agriculture | National Total | 2100 | 9 |
CIL Crime | National Total | 2100 | 2 |
Climate-Driven Changes in Air Quality | National Total | 2100 | 291 |
Coastal Properties | National Total | 2100 | 14 |
Electricity Demand and Supply | National Total | 2100 | 19 |
Electricity Transmission and Distribution | National Total | 2100 | 15 |
Inland Flooding | National Total | 2100 | 1 |
Labor | National Total | 2100 | 56 |
Marine Fisheries | National Total | 2100 | 0 |
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.For recommendations on aggregating
impacts across sectors, see the FrEDI Technical Documentation (Chapter
2) and FrEDI::run_fredi() documentation.
#specify year
c_years = c(2100)
df_filter <- output_df %>%
# 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[c(1,6:9,14),],
caption = 'Example *Subset* of 2100 Annual National Sectoral Climate-Driven Physical Impacts') %>%
kable_styling(font_size = 12, full_width = F)
sector | region | year | physicalmeasure | impactType | physical_impacts |
---|---|---|---|---|---|
ATS Temperature-Related Mortality | National Total | 2100 | Premature Mortality | N/A | 83858 |
CIL Crime | National Total | 2100 | Crimes | Property | 3264 |
CIL Crime | National Total | 2100 | Crimes | Violent | 5713 |
Climate-Driven Changes in Air Quality | National Total | 2100 | Premature Mortality | Ozone | 2108 |
Climate-Driven Changes in Air Quality | National Total | 2100 | Premature Mortality | PM2.5 | 6717 |
Labor | National Total | 2100 | Lost Work Hours | N/A | 659458039 |
Example 3
Extract state 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. For recommendations on aggregating
impacts across sectors, see the FrEDI Technical Documentation (Chapter
2) and FrEDI::run_fredi() documentation.
#specify year
c_years = c(2100)
#filter and aggregate data, assign to aggregate categories
df_filter <- output_df %>%
# 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 state
group_by_at(.vars = c('state','year')) %>%
## SEE RECOMMENDATIONS FOR AGGREGATION in FrEDI TECHNICAL DOCUMENTATION ##
mutate(annual_impacts = case_when(sector == 'ATS Temperature-Related Mortality' ~
annual_impacts - annual_impacts[sector == 'Suicide'],
.default = annual_impacts)) %>%
summarize_at(c("annual_impacts"), sum, na.rm=T) %>%
ungroup %>%
# select (and rename) relevant columns
select('state','year','annual_impacts')%>%
rename('billions_2015$' = annual_impacts)
kable(df_filter[1:10,],
caption = 'Example 2100 Annual Climate-Driven Damages, by State') %>%
kable_styling(font_size = 12, full_width = F)
state | year | billions_2015$ |
---|---|---|
Alabama | 2100 | 63 |
Arizona | 2100 | 89 |
Arkansas | 2100 | 36 |
California | 2100 | 404 |
Colorado | 2100 | 70 |
Connecticut | 2100 | 28 |
Delaware | 2100 | 9 |
District of Columbia | 2100 | 6 |
Florida | 2100 | 217 |
Georgia | 2100 | 159 |
Please contact the FrEDI
developers with additional
questions.