% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mov.cor.dm.R
\name{mov.cor.dm}
\alias{mov.cor.dm}
\title{Running correlation between dendrometer data and climate}
\usage{
mov.cor.dm(
  df,
  Clim,
  TreeNum,
  win_size,
  cor_method = c("pearson", "kendall", "spearman"),
  boot = FALSE,
  R = 1000,
  boot.ci = 0.05,
  set_seed = 1,
  dm_stat = c("mean", "min", "max", "median", "amplitude", "change"),
  clim_vars = NULL,
  lag_days = 0,
  accum_days = 1,
  clim_fun = "raw",
  min_complete = NULL,
  p_adjust_method = "BH"
)
}
\arguments{
\item{df}{A data frame with the first column containing date-time in the format
\code{yyyy-mm-dd HH:MM:SS} (or convertible to \code{POSIXct}) and dendrometer
series in the following columns.}

\item{Clim}{A data frame with the first column containing daily date
(\code{yyyy-mm-dd}, \code{Date}, or convertible) and one or more climate
variables in the following columns.}

\item{TreeNum}{Integer indicating the dendrometer series to analyze.}

\item{win_size}{Integer giving the running window size in days. Minimum is 18.}

\item{cor_method}{Correlation method: one of \code{"pearson"},
\code{"kendall"}, or \code{"spearman"}.}

\item{boot}{Logical. If \code{TRUE}, bootstrap confidence intervals are
computed for each running correlation.}

\item{R}{Integer number of bootstrap iterations.}

\item{boot.ci}{Numeric confidence level selector: one of \code{0.01},
\code{0.05} (default), or \code{0.1}.}

\item{set_seed}{Integer seed for reproducibility of bootstrap results.}

\item{dm_stat}{Daily dendrometer statistic used for correlation. One of
\code{"mean"}, \code{"min"}, \code{"max"}, \code{"median"},
\code{"amplitude"}, or \code{"change"}.}

\item{clim_vars}{Optional character vector of climate variables to analyze.
If \code{NULL}, all numeric climate variables are used.}

\item{lag_days}{Climate lag in days. Can be:
\itemize{
  \item one value for all selected climate variables
  \item one value per selected climate variable
  \item a named numeric vector keyed by climate variable name
}}

\item{accum_days}{Antecedent window length in days for climate transformation.
Can be scalar, per-variable, or a named numeric vector.}

\item{clim_fun}{Climate transformation over the antecedent window. One of
\code{"raw"}, \code{"mean"}, \code{"sum"}, \code{"max"},
\code{"min"}, or \code{"median"}. Can be scalar, per-variable, or a named
character vector.}

\item{min_complete}{Minimum number of complete paired observations required in
a running window to calculate correlation. If \code{NULL}, defaults to
\code{max(3, ceiling(0.8 * win_size))}.}

\item{p_adjust_method}{Method for p-value adjustment in the non-bootstrap
output. Passed to \code{p.adjust()}. Use \code{"none"} to skip adjustment.}
}
\value{
A list with class \code{"mov_cor_dm"} (and \code{"mov_cor_dm_boot"} if
bootstrapped) containing:
\itemize{
  \item \code{results}: named list of tibbles, one per climate variable
  \item \code{metadata}: analysis metadata
  \item \code{call}: the matched function call
}
}
\description{
Calculates running correlations between a selected daily dendrometer summary
and one or more climate variables. The user can select the daily dendrometer
statistic, correlation method, optional bootstrap confidence intervals, and
lagged / antecedent climate transformations.
}
\details{
The dendrometer series is first aggregated to daily resolution. The daily
dendrometer statistic used for correlation is controlled by \code{dm_stat}:
\itemize{
  \item \code{"mean"}: daily mean dendrometer value
  \item \code{"min"}: daily minimum
  \item \code{"max"}: daily maximum
  \item \code{"median"}: daily median
  \item \code{"amplitude"}: daily amplitude (\code{max - min})
  \item \code{"change"}: day-to-day change in the daily mean
}

Users can choose the climate variables to analyze via \code{clim_vars}.
Climate transformation settings can be given as:
\itemize{
  \item a single value applied to all selected climate variables
  \item an unnamed vector with one value per selected climate variable
  \item a named vector mapping each selected climate variable to its own setting
}

This applies to \code{clim_fun}, \code{lag_days}, and \code{accum_days}.
}
\examples{
\donttest{
library(dendRoAnalyst)
data(gf_nepa17)
data(ktm_rain17)

# one common climate transformation for all selected variables
out_corr <- mov.cor.dm(
  df = gf_nepa17,
  Clim = ktm_rain17,
  TreeNum = 1,
  win_size = 21,
  clim_fun = "raw"
)
print(out_corr)
summary(out_corr)

# variable-specific climate transformations
out_varfun <- mov.cor.dm(
  df = gf_nepa17,
  Clim = ktm_rain17,
  TreeNum = 1,
  win_size = 21,
  clim_vars = c("rainfall"),
  clim_fun = c(rainfall = "sum"),
  lag_days = c(rainfall = 1),
  accum_days = c(rainfall = 7)
)

# bootstrap confidence intervals
out_boot <- mov.cor.dm(
  df = gf_nepa17,
  Clim = ktm_rain17,
  TreeNum = 1,
  win_size = 21,
  boot = TRUE,
  R = 250
)
summary(out_boot)
}

}
