View source: R/standardize_data.R
| standardize_data | R Documentation |
Rewrites user column names into the common data schema used by fit_4pl()
and the TDT compatibility helpers. Direct fit_tls() column and tls_bf()
formula fits can use a data frame without this conversion; supply durations
in minutes for those interfaces.
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 = NULL,
temp_mean = NULL,
left_censored = NULL,
censor_limit = NULL
)
data |
Raw data frame or tibble. |
temp |
Column name of the assay temperature (°C). |
duration |
Column name of the exposure duration. Supply its source
unit with |
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 |
Boundary clamp applied to exact |
random_effects |
Optional character vector of grouping variables for
random effects, e.g. |
duration_unit |
Unit of the input |
temp_mean |
Value to subtract from |
left_censored |
Optional column name containing non-missing logical
indicators for measurements known only to lie below a
detection limit. Must be paired with |
censor_limit |
Optional numeric column name with one lower detection
limit per observation. Values must be finite and
strictly inside |
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; without censoring,
values are clamped into (proportion_eps, 1 - proportion_eps). For explicit
left-censored measurements, provide both censoring columns below. Their
placeholders and exact interior proportions are retained; exact boundary
values are clamped only when this keeps them above their detection limit.
A warning reports affected rows whenever values are changed; no
n_total/n_surv columns are created. response_type
is recorded as "proportion".
If the dataset spans multiple categories (life stages, species, populations,
etc.), retain the grouping column. Use fit_4pl(by = "group") or grouped
formulas in tls_bf() to estimate category-level effects, or filter first
when separate models are scientifically preferable.
A tibble with the standardised columns plus a "tdt_meta" attribute
storing temp_mean, duration_unit (always "minutes"),
input_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 used for a proportion fit, else NULL),
and has_left_censoring (whether censoring columns were explicitly
requested for a proportion response).
# 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",
duration_unit = "hours")
# 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",
duration_unit = "hours")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.