clim.twd.test: Statistical testing for clim.twd output

View source: R/stats.clim.twd.R

clim.twd.testR Documentation

Statistical testing for clim.twd output

Description

Performs hypothesis tests on parameters derived from clim.twd() output.

This function is designed for scenarios such as:

  • species comparison as a whole,

  • species comparison by year,

  • site comparison as a whole,

  • site comparison by year,

  • species-within-site comparison,

  • ID-wise comparisons.

The function uses the period_info table from clim.twd() and tests selected parameters across groups such as trees, species, sites, or species-site combinations.

Usage

clim.twd.test(
  x,
  tree_info = NULL,
  parameter = c("lag_to_below_zero", "lag_to_max_adverse_decline", "lag_to_return_zero",
    "max_adverse_decline_value", "change_end_adverse", "change_end_full_period",
    "continuous_end_full_period"),
  compare_by = c("tree", "species", "site", "species_site"),
  within = c("all", "year", "ID"),
  test_method = c("auto", "t_test", "welch_t", "wilcox", "anova", "kruskal"),
  ids = NULL,
  years = NULL,
  months = NULL,
  doy_window = NULL,
  year_window = NULL,
  pairwise = TRUE,
  p_adjust_method = "BH",
  min_n_per_group = 2
)

Arguments

x

An object of class "clim_twd_output" returned by clim.twd().

tree_info

Optional metadata table describing trees. It must contain a column named tree, and may additionally contain species and site. A named character vector is also accepted for species-only mapping, where names are trees and values are species.

parameter

Character. Parameter from x$period_info to test. Supported examples include:

'"lag_to_below_zero"'

Lag from adverse start until relative change first drops below zero.

'"lag_to_max_adverse_decline"'

Lag from adverse start until maximum adverse decline is reached.

'"lag_to_return_zero"'

Lag from adverse start until relative change returns to zero or above.

'"max_adverse_decline_value"'

Most negative relative change during the adverse phase.

'"change_end_adverse"'

Relative change at the end of the adverse phase.

'"change_end_full_period"'

Relative change at the end of the full period.

'"continuous_end_full_period"'

Continuous end value across periods.

compare_by

Character. Grouping variable to compare. One of "tree", "species", "site", or "species_site".

within

Character. Defines the comparison scenario:

'"all"'

Compare groups across all retained IDs.

'"year"'

Compare groups separately within each adverse-start year.

'"ID"'

Compare groups separately within each ID.

test_method

Character. One of "auto", "t_test", "welch_t", "wilcox", "anova", or "kruskal". With "auto", the function uses:

  • Welch t-test or one-way ANOVA when group distributions look approximately normal,

  • Wilcoxon or Kruskal-Wallis otherwise.

ids

Optional numeric vector of IDs to retain before testing.

years

Optional numeric vector of years to retain based on adverse_start.

months

Optional numeric vector of months (1–12) to retain based on adverse_start.

doy_window

Optional numeric vector of length 2 defining the allowed day-of-year window of adverse_start. Wrapped windows such as c(300, 50) are supported.

year_window

Optional numeric vector of length 2 defining the allowed year range for adverse_start.

pairwise

Logical. If TRUE, pairwise post-hoc tests are computed for strata with more than two groups when applicable.

p_adjust_method

Character. P-value adjustment method for pairwise tests. Default is "BH".

min_n_per_group

Minimum number of non-missing observations required per group before testing. Default is 2.

Value

A list of class "clim_twd_test" containing:

data_used

Filtered test data used for the analyses.

test_results

Main test results by stratum.

pairwise_results

Pairwise comparison table where available.

group_summary

Descriptive summaries by stratum and group.

settings

Settings used for the analysis.

Examples


rel_out <- clim.twd(
  df = gf_nepa17,
  Clim = ktm_rain17,
  thresholdClim = "<10",
  thresholdDays = ">5",
  showPlot = FALSE
)

tree_info <- data.frame(
  tree = c("T2", "T3"),
  species = c("Pinus", "Pinus"),
  site = c("Ktm", "Ktm")
)

# species comparison across all retained IDs
tst1 <- clim.twd.test(
  rel_out,
  tree_info = tree_info,
  parameter = "max_adverse_decline_value",
  compare_by = "species",
  within = "all"
)

summary(tst1)
plot(tst1)

# species comparison by year
tst2 <- clim.twd.test(
  rel_out,
  tree_info = tree_info,
  parameter = "lag_to_return_zero",
  compare_by = "species",
  within = "year"
)

# site comparison by year
tst3 <- clim.twd.test(
  rel_out,
  tree_info = tree_info,
  parameter = "change_end_full_period",
  compare_by = "site",
  within = "year",
  test_method = "kruskal"
)



dendRoAnalyst documentation built on May 20, 2026, 5:07 p.m.