Description Usage Arguments Value Examples

Function calculates all possible values of a selected statistical metric between one or more response variables and monthly sequences of environmental data. Calculations are based on moving window which slides through monthly environmental data. All calculated metrics are stored in a matrix. The location of stored calculated metric in the matrix is indicating a window width (row names) and a location in a matrix of monthly sequences of environmental data (column names).

1 2 3 4 5 6 7 8 9 10 11 | ```
monthly_response(response, env_data, method = "lm",
metric = "r.squared", cor_method = "pearson",
previous_year = FALSE, neurons = 1, brnn_smooth = TRUE,
remove_insignificant = TRUE, alpha = 0.05,
row_names_subset = FALSE, PCA_transformation = FALSE,
log_preprocess = TRUE, components_selection = "automatic",
eigenvalues_threshold = 1, N_components = 2,
aggregate_function = "mean", temporal_stability_check = "sequential",
k = 2, k_running_window = 30, cross_validation_type = "blocked",
subset_years = NULL, plot_specific_window = NULL, ylimits = NULL,
seed = NULL, tidy_env_data = FALSE)
``` |

`response` |
a data frame with tree-ring proxy variables as columns and (optional) years as row names. Row.names should be matched with those from a env_data data frame. If not, set row_names_subset = TRUE. |

`env_data` |
a data frame of monthly sequences of environmental data as columns and years as row names. Each row represents a year and each column represents a day of a year (or month). Row.names should be matched with those from a response data frame. If not, set row_names_subset = TRUE. Alternatively, env_data could be a tidy data with three columns, i.e. Year, DOY (Month) and third column representing values of mean temperatures, sum of precipitation etc. If tidy data is passed to the function, set the argument tidy_env_data to TRUE. |

`method` |
a character string specifying which method to use. Current possibilities are "cor", "lm" and "brnn". |

`metric` |
a character string specifying which metric to use. Current possibilities are "r.squared" and "adj.r.squared". If method = "cor", metric is not relevant. |

`cor_method` |
a character string indicating which correlation coefficient is to be computed. One of "pearson" (default), "kendall", or "spearman". |

`previous_year` |
if set to TRUE, env_data and response variables will be rearranged in a way, that also previous year will be used for calculations of selected statistical metric. |

`neurons` |
positive integer that indicates the number of neurons used for brnn method |

`brnn_smooth` |
if set to TRUE, a smoothing algorithm is applied that removes unrealistic calculations which are a result of neural net failure. |

`remove_insignificant` |
if set to TRUE, removes all correlations bellow the significant threshold level, based on a selected alpha. For "lm" and "brnn" method, squared threshold is used, which corresponds to R squared statistics. |

`alpha` |
significance level used to remove insignificant calculations. |

`row_names_subset` |
if set to TRUE, row.names are used to subset env_data and response data frames. Only years from both data frames are kept. |

`PCA_transformation` |
if set to TRUE, all variables in the response data frame will be transformed using PCA transformation. |

`log_preprocess` |
if set to TRUE, variables will be transformed with logarithmic transformation before used in PCA |

`components_selection` |
character string specifying how to select the Principal Components used as predictors. There are three options: "automatic", "manual" and "plot_selection". If argument is set to automatic, all scores with eigenvalues above 1 will be selected. This threshold could be changed by changing the eigenvalues_threshold argument. If parameter is set to "manual", user should set the number of components with N_components argument. If components selection is set to "plot_selection", Scree plot will be shown and a user must manually enter the number of components to be used as predictors. |

`eigenvalues_threshold` |
threshold for automatic selection of Principal Components |

`N_components` |
number of Principal Components used as predictors |

`aggregate_function` |
character string specifying how the monthly data should be aggregated. The default is 'mean', the two other options are 'median' and 'sum' |

`temporal_stability_check` |
character string, specifying, how temporal stability between the optimal selection and response variable(s) will be analysed. Current possibilities are "sequential", "progressive" and "running_window". Sequential check will split data into k splits and calculate selected metric for each split. Progressive check will split data into k splits, calculate metric for the first split and then progressively add 1 split at a time and calculate selected metric. For running window, select the length of running window with the k_running_window argument. |

`k` |
integer, number of breaks (splits) for temporal stability and cross validation analysis. |

`k_running_window` |
the length of running window for temporal stability check. Applicalbe only if temporal_stability argument is set to running window. |

`cross_validation_type` |
character string, specifying, how to perform cross validation between the optimal selection and response variables. If the argument is set to "blocked", years will not be shuffled. If the argument is set to "randomized", years will be shuffled. |

`subset_years` |
a subset of years to be analyzed. Should be given in the form of subset_years = c(1980, 2005) |

`plot_specific_window` |
integer representing window width to be displayed for plot_specific |

`ylimits` |
limit of the y axes for plot_extreme and plot_specific. It should be given in the form of: ylimits = c(0,1) |

`seed` |
optional seed argument for reproducible results |

`tidy_env_data` |
if set to TRUE, env_data should be inserted as a data frame with three columns: "Year", "Month", "Precipitation/Temperature/etc." |

a list with 15 elements:

1 | $calculations | a matrix with calculated metrics |

2 | $method | the character string of a method |

3 | $metric | the character string indicating the metric used for calculations |

4 | $analysed_period | the character string specifying the analysed period based on the information from row names. If there are no row names, this argument is given as NA |

5 | $optimized_return | data frame with two columns, response variable and aggregated (averaged) monthly data that return the optimal results. This data.frame could be directly used to calibrate a model for climate reconstruction |

6 | $optimized_return_all | a data frame with aggregated monthly data, that returned the optimal result for the entire env_data (and not only subset of analysed years) |

7 | $transfer_function | a ggplot object: scatter plot of optimized return and a transfer line of the selected method |

8 | $temporal_stability | a data frame with calculations of selected metric for different temporal subsets |

9 | $cross_validation | a data frame with cross validation results |

10 | $plot_heatmap | ggplot2 object: a heatmap of calculated metrics |

11 | $plot_extreme | ggplot2 object: line or bar plot of a row with the highest value in a matrix of calculated metrics |

12 | $plot_specific | not avaliable for monthly_response() |

13 | $PCA_output | princomp object: the result output of the PCA analysis |

14 | $type | the character string describing type of analysis: daily or monthly |

15 | $reference_window | character string, which referece window was used for calculations |

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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | ```
## Not run:
# Load the dendroTools R package
library(dendroTools)
# Load data used for examples
data(data_MVA)
data(data_TRW)
data(data_TRW_1)
data(example_proxies_individual)
data(example_proxies_1)
data(LJ_monthly_temperatures)
data(LJ_monthly_precipitation)
# 1 Example with tidy precipitation data
example_tidy_data <- monthly_response(response = data_MVA, env_data = LJ_monthly_precipitation,
method = "cor", row_names_subset = TRUE,
remove_insignificant = TRUE, previous_year = TRUE,
alpha = 0.05, aggregate_function = 'sum',
tidy_env_data = TRUE, previous_year = TRUE)
summary(example_tidy_data)
example_tidy_data$plot_extreme
example_tidy_data$plot_heatmap
# 2 Example with splited data for past and present
example_MVA_past <- monthly_response(response = data_MVA, env_data = LJ_monthly_temperatures,
method = "cor", row_names_subset = TRUE, previous_year = TRUE,
remove_insignificant = TRUE, alpha = 0.05,
subset_years = c(1940, 1980), aggregate_function = 'mean')
example_MVA_present <- monthly_response(response = data_MVA, env_data = LJ_monthly_temperatures,
method = "cor", row_names_subset = TRUE, alpha = 0.05,
previous_year = TRUE, remove_insignificant = TRUE,
subset_years = c(1981, 2010), aggregate_function = 'mean')
example_MVA_past$plot_heatmap
example_MVA_present$plot_heatmap
example_MVA_past$plot_extreme
example_MVA_present$plot_extreme
# 3 Example with principal component analysis
example_PCA <- monthly_response(response = example_proxies_individual,
env_data = LJ_monthly_temperatures, method = "lm",
row_names_subset = TRUE, remove_insignificant = TRUE,
alpha = 0.01, PCA_transformation = TRUE, previous_year = TRUE,
components_selection = "manual", N_components = 2)
summary(example_PCA$PCA_output)
example_PCA$plot_heatmap
example_PCA$plot_extreme
# 4 Example negative correlations
example_neg_cor <- monthly_response(response = data_TRW_1, alpha = 0.05,
env_data = LJ_monthly_temperatures,
method = "cor", row_names_subset = TRUE,
remove_insignificant = TRUE)
example_neg_cor$plot_heatmap
example_neg_cor$plot_extreme
example_neg_cor$temporal_stability
# 5 Example of multiproxy analysis
summary(example_proxies_1)
cor(example_proxies_1)
example_multiproxy <- monthly_response(response = example_proxies_1,
env_data = LJ_monthly_temperatures,
method = "lm", metric = "adj.r.squared",
row_names_subset = TRUE, previous_year = FALSE,
remove_insignificant = TRUE, alpha = 0.05)
example_multiproxy$plot_heatmap
# 6 Example to test the temporal stability
example_MVA_ts <- monthly_response(response = data_MVA, env_data = LJ_monthly_temperatures,
method = "lm", metric = "adj.r.squared", row_names_subset = TRUE,
remove_insignificant = TRUE, alpha = 0.05,
temporal_stability_check = "running_window", k_running_window = 10)
example_MVA_ts$temporal_stability
## End(Not run)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.