Skip to contents

S3 plot method for pigauto_pred objects, using base R graphics. Three plot types are available: scatter plots of observed vs predicted values, interval plots per species, and probability charts for discrete traits.

Usage

# S3 method for class 'pigauto_pred'
plot(x, data = NULL, splits = NULL, type = "scatter", trait = NULL, ...)

Arguments

x

An object of class "pigauto_pred".

data

Optional numeric matrix or data.frame of observed values in original scale. Rows must match the predictions in x one-for-one and in the same order; rows are paired by position, not matched by row names or species identifiers. Trait columns are selected by name. Values are overlaid on scatter and interval plots. For probability plots, class labels are used to group predictions; rows with missing or unrecognized labels are omitted from these groups.

splits

Optional list (output of make_missing_splits). Currently unused by this plotting method. All finite pairs in data and x$imputed are plotted, so the scatter is not a held-out performance estimate. To display held-out cells, obtain predict(fit, evaluation = TRUE), and supply a truth frame with every cell outside the desired validation/test subset set to NA.

type

Character. "scatter" (default): grid of observed-vs-predicted scatter plots for continuous, count, and proportion traits, with 1:1 line and conformal interval bands where available. "intervals": for each trait, species sorted by predicted value with conformal-interval ribbon; observed values shown in red where available. "probabilities": for binary traits, the probability of the second class level is shown in boxplots grouped by observed class when usable labels are present; otherwise a histogram shows the probabilities. For categorical traits, usable labels give stacked bars of mean predicted probabilities by observed class; without usable labels, stacked bars show up to 100 observations, ordered by their most probable class. These plots are descriptive: grouping by observed class does not itself assess calibration. Unless the predictions are for cells held out from fitting and data supplies their truth, they are not held-out performance assessments. To inspect held-out predictions, use predict(fit, evaluation = TRUE) and provide a truth frame with all other cells set to NA. Select only traits with at least one usable held-out class label; otherwise the fallback plot uses predictions without restricting them to held-out cells.

trait

Character vector of trait names to plot. If NULL (default), all traits appropriate for the chosen type are plotted.

...

Additional arguments passed to base plotting functions.

Value

Invisible NULL. Called for its side effect (plotting).

Examples

# \donttest{
data(avonet300, tree300)
tree <- ape::keep.tip(tree300, tree300$tip.label[seq_len(30L)])
traits <- avonet300[match(tree$tip.label, avonet300$Species_Key),
                     c("Mass", "Wing.Length"), drop = FALSE]
rownames(traits) <- tree$tip.label
traits$Mass[seq_len(3L)] <- NA_real_
result <- impute(traits, tree, epochs = 5L, verbose = FALSE)
#> Warning: Small validation set for 2 trait(s): Mass (n=3), Wing.Length (n=4). Calibrated gate and conformal scores will be noisy for these trait(s). 95% split-conformal coverage is NOT achievable for 2 trait(s) with fewer than 19 validation cells (Mass (n=3), Wing.Length (n=4)): the achievable ceiling is n_val / (n_val + 1), which only reaches 0.95 at n_val >= 19. See `?fit_pigauto` under 'Calibration at small n' for smoothing options.
pred <- result$prediction
plot(pred)
Ranked predictions for Mass and Wing.Length across species; both rise toward higher ranks, with a steep final increase.
plot(pred, type = "scatter", data = traits) # descriptive all-finite pairs
Observed versus predicted Mass and Wing.Length. Points are shown with a dashed equality line and a broad shaded interval; the displayed correlation is 1 for both traits.
plot(pred, type = "intervals", trait = "Mass")
Mass predictions by species rank with a shaded uncertainty band. The line rises gradually, then sharply for the highest-ranked species; the band also widens at the upper end.
# These two continuous traits each occupy one latent column.
evaluation_pred <- predict(result$fit, evaluation = TRUE)
heldout_truth <- as.matrix(traits)
heldout_truth[] <- NA_real_
idx <- result$fit$splits$test_idx
heldout_truth[idx] <- as.matrix(traits)[idx]
plot(evaluation_pred, type = "scatter", data = heldout_truth)
Observed versus predicted Mass and Wing.Length for held-out cells. Each panel has a dashed equality line and shaded interval; Mass has three visible points and Wing.Length includes one point well below equality.
# }