Fit a growth curve to the cleaned body weights of each pig and compute average daily gain (ADG) over a body weight stage.
calc_adg(weight, qc = weight$settings, verbose = 1, cores = 1)Result of clean_weight().
QC settings; by default the ones used by clean_weight().
Used here: stage_range, curve_model, max_extrap_days,
curve_extrap.
0 (silent), 1 (summary, default) or 2 (details).
Number of CPU cores for the per-pig computations. Default 1.
An object of class ppt_adg (a list):
per_pig: one row per pig (pigs removed by clean_weight() are not
included) with stage, curve_used, curve_r2, adg_type,
start_date / end_date and start_weight / end_weight (when the
curve reaches the stage limits, kg), stage_days,
extrap_days_start / extrap_days_end (days the curve is
extrapolated before the first / after the last weight), adg (g/d,
slope of the daily weights over the stage), r_squared (of that
regression), n_observed_days, n_interpolated_days,
n_curve_days (stage days by source of the weight), adg_curve
(g/d, stage weight difference / days of the growth curve, for
comparison), weight_status and weight_reason (from
clean_weight());
daily: one row per pig and day from start_date to end_date and
over the recorded days: observed weight (daily median, kg, NA on
days without valid weight), weight_filled (observed, interpolated
or curve weight, kg), source ("observed", "interpolated" or
"curve"), predicted weight of the growth curve with lower /
upper limits (± 1.96 residual SD) and in_stage;
removed: pigs removed so far, plus pigs without ADG;
settings: QC settings.
clean_weight() for the previous step.
visits <- prep_visits(nedap, verbose = 0)
w <- clean_weight(visits, verbose = 0)
adg <- calc_adg(w)
#>
#> ── ADG over 30-120 kg (poly2 curve) ────────────────────────────────────────────
#> Pigs 29
#> └ observed (stage inside the records) 21 72.4%
#> └ extrapolated at the ends 7 24.1%
#> └ partial (stage not fully reached) 1 3.4%
#> ! 1 pig does not reach the whole stage: ADG is based on part of it (adg_type = "partial").
#> ✔ ADG 1205 ± 133 g/d (mean ± SD) 0.3s
head(adg$per_pig[, .(responder, adg_type, start_date, end_date, stage_days, adg)])
#> responder adg_type start_date end_date stage_days adg
#> <char> <char> <Date> <Date> <num> <num>
#> 1: 13913 observed 2024-03-02 2024-05-16 75.56102 1209.897
#> 2: 13918 observed 2024-03-06 2024-05-24 78.43858 1162.966
#> 3: 13954 extrapolated 2024-03-10 2024-05-28 79.28093 1124.224
#> 4: 13996 observed 2024-02-28 2024-05-07 69.15285 1334.979
#> 5: 14962 observed 2024-02-26 2024-05-07 70.15055 1278.746
#> 6: 15006 observed 2024-02-28 2024-05-07 68.69428 1317.472
# Gompertz curve, with quadratic fallback
adg_g <- calc_adg(w, qc = qc_config(curve_model = "gompertz"), verbose = 0)
table(adg_g$per_pig$curve_used)
#>
#> gompertz + tangent (start)
#> 29
# Source of the daily weights over the stage
table(adg$daily[in_stage == TRUE, source])
#>
#> curve interpolated observed
#> 37 12 2158