summarize_for_pca: Summarize threshold values to allocate climate futures by...

Description Usage Arguments Details Value Examples

View source: R/summarize_for_pca.R

Description

Takes data from calc_thresholds and summarizes the thresholds to be used to find most extreme climate futures from principal components analysis (PCA)

Usage

1
2
3
4
5
6
7
summarize_for_pca(
  SiteID,
  data = NULL,
  past_years = c(1950, 2000),
  future_year = 2040,
  directory = tempdir()
)

Arguments

SiteID

chosen name to use in file names, attributes, and directories. (character)

data

Default dataset to use for the .csv files this function will create. Follow vignette for example dataset creation. This should be the output of the calc_thresholds function (data frame)

past_years

years to base past data off of. Cannot be any earlier than 1950. Must be written as c(past_start, past_end). Defaults to 1950:2000 (numeric)

future_year

year to center changes from historical data around. Defaults to 2040 (numeric)

directory

where to save files to. Per CRAN guidelines, this defaults to a temporary directory and files created will be lost after R session ends. Specify a path to retain files.

Details

*For advanced users only.

Value

A csv that has summarized threshold values across all years for all models. This csv can be directly used to calculate model selection by pca using the cf_pca function.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
## Not run: 
# Generate sample data

data <- data.frame(
 date = sample(seq(as.Date('1950/01/01'), as.Date('2099/12/31'), by="day"), 1000),
 yr = rep(c(1980, 2040, 1980, 2040, 1980, 2040, 1980, 2040, 1980, 2040, 1980, 2040, 1980,
            2040, 1980, 2040, 1980, 2040, 1980, 2040), each = 50),
 month = rep(c(1:10), each = 100),
 quarter = rep(rep(c("DJF", "MAM", "JJA", "SON"), each = 250)),
 gcm = rep(c("bcc-csm1-1.rcp45", "BNU-ESM.rcp45", "CanESM2.rcp85", "CCSM4.rcp45",
             "CSIRO-Mk3-6-0.rcp45"), each = 200),
 precip = rnorm(1000),
 tmin = rnorm(1000),
 tmax = rnorm(1000),
 rhmax = rnorm(1000),
 rhmin = rnorm(1000),
 tavg = rnorm(1000),
 heat_index = rnorm(1000),
 heat_index_ec = rnorm(1000),
 heat_index_dan = rnorm(1000),
 temp_over_95_pctl =  as.logical(sample(x = c("TRUE","FALSE"), size = 1000, replace = TRUE)),
 temp_over_99_pctl =  as.logical(sample(x = c("TRUE","FALSE"), size = 1000, replace = TRUE)),
 temp_over_95_pctl_length =  as.logical(sample(x = c("TRUE","FALSE"), size = 1000,
                                               replace = TRUE)),
 temp_under_freeze =  as.logical(sample(x = c("TRUE","FALSE"), size = 1000, replace = TRUE)),
 temp_under_freeze_length =  as.logical(sample(x = c("TRUE","FALSE"), size = 1000,
                                               replace = TRUE)),
 temp_under_5_pctl =  as.logical(sample(x = c("TRUE","FALSE"), size = 1000, replace = TRUE)),
 no_precip  =  as.logical(sample(x = c("TRUE","FALSE"), size = 1000, replace = TRUE)),
 no_precip_length =  as.logical(sample(x = c("TRUE","FALSE"), size = 1000, replace = TRUE)),
 precip_95_pctl =  as.logical(sample(x = c("TRUE","FALSE"), size = 1000, replace = TRUE)),
 precip_99_pctl =  as.logical(sample(x = c("TRUE","FALSE"), size = 1000, replace = TRUE)),
 precip_moderate =  as.logical(sample(x = c("TRUE","FALSE"), size = 1000, replace = TRUE)),
 precip_heavy =  as.logical(sample(x = c("TRUE","FALSE"), size = 1000, replace = TRUE)),
 freeze_thaw =  as.logical(sample(x = c("TRUE","FALSE"), size = 1000, replace = TRUE)),
 gdd =  as.logical(sample(x = c("TRUE","FALSE"), size = 1000, replace = TRUE)),
 gdd_count = rnorm(1000),
 not_gdd_count = rnorm(1000),
 frost = as.logical(sample(x = c("TRUE","FALSE"), size = 1000, replace = TRUE)),
 grow_length = rnorm(1000),
 units = rep("imperial", each = 1000)
)

summarize_for_pca("SCBL", data = data)

## End(Not run)

nationalparkservice/rcf documentation built on Dec. 22, 2021, 12:01 a.m.