View source: R/standardize_data.R
| standardize_data | R Documentation |
Rewrites user column names into a single project-standard schema and attaches metadata used by every downstream fitting and prediction helper. This is the single entry point for raw data — everything else in the library assumes the output of this function.
standardize_data(
data,
temp,
duration,
n_total = NULL,
n_surv = NULL,
n_dead = NULL,
survival = NULL,
mortality = NULL,
proportion = NULL,
proportion_eps = 0.001,
random_effects = NULL,
duration_unit = "hours",
temp_mean = NULL,
detection_limit = NULL
)
data |
Raw data frame or tibble. |
temp |
Column name of the assay temperature (°C). |
duration |
Column name of the exposure duration. The unit is
whatever is in the source data; record it via
|
n_total |
Column name for total individuals per replicate.
Required for count responses; leave |
n_surv |
Column name for survivor counts. |
n_dead |
Column name for death counts. Converted to |
survival |
Column name for survival proportions in |
mortality |
Column name for mortality proportions in |
proportion |
Column name for a continuous proportion response in
|
proportion_eps |
Half-open clamp applied to |
random_effects |
Optional character vector of grouping variables for
random effects, e.g. |
duration_unit |
Label for the unit of |
temp_mean |
Value to subtract from |
detection_limit |
For a continuous
Censored rows store their limit in The pointwise log-likelihood of a censored fit ( |
Two response types are supported:
Count data (binomial / beta-binomial): supply n_total plus exactly
one of n_surv, n_dead, survival, or mortality. The other counts
are derived and the standardised columns include n_total, n_surv,
n_dead, survival. response_type is recorded as "count".
Continuous proportion (Beta), e.g. a chlorophyll-fluorescence
F_v/F_m ratio with no denominator: supply proportion and omit the
count arguments. The value is stored in survival (clamped into the open
interval (proportion_eps, 1 - proportion_eps) so the Beta likelihood is
finite, except on a side with a detection_limit); no
n_total/n_surv columns are created. response_type is
recorded as "proportion". If the instrument cannot resolve values
beyond a limit (e.g. it records 0 when function is below what it can
read), give that limit as detection_limit so those readings are treated
as censored rather than clamped.
If the dataset spans multiple categories (life stages, species, populations, etc.), filter to one category before calling this function and fit a separate model per subset — the fitter does not estimate category-level effects.
A tibble with the standardised columns (plus censored and
survival_recorded when detection_limit is given) and a
"tdt_meta" attribute
storing temp_mean, duration_unit, random_effects,
response_type ("count" or "proportion"), response_var
(the response column name for a proportion fit, else NULL),
proportion_eps (the clamp half-width used for a proportion fit, else
NULL), detection_limit (as supplied, else NULL), censored
(TRUE when a detection_limit was supplied) and n_censored (the
numbers of left- and right-censored rows, else NULL).
# Count data
raw <- data.frame(
temperature_C = rep(c(30, 32, 34), each = 4),
exposure_h = rep(c(1, 2, 4, 8), times = 3),
n = 30L,
alive = c(29, 28, 25, 5, 30, 27, 18, 2, 28, 22, 10, 1)
)
standardize_data(raw,
temp = "temperature_C",
duration = "exposure_h",
n_total = "n",
n_surv = "alive")
# Continuous proportion (Beta) data
raw_p <- data.frame(
temperature_C = rep(c(30, 32, 34), each = 4),
exposure_h = rep(c(1, 2, 4, 8), times = 3),
fvfm_ratio = c(0.95, 0.9, 0.7, 0.2, 0.92, 0.6, 0.3, 0, 0.8, 0.4, 0.1, 0)
)
standardize_data(raw_p,
temp = "temperature_C",
duration = "exposure_h",
proportion = "fvfm_ratio")
# The instrument records 0 below 0.05: treat those zeros as censored
cens <- standardize_data(raw_p,
temp = "temperature_C",
duration = "exposure_h",
proportion = "fvfm_ratio",
detection_limit = 0.05)
table(cens$censored)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.