svem_random_table_from_model: Generate a Random Prediction Table from a Fitted SVEMnet...

View source: R/svem_random_table.R

svem_random_table_from_modelR Documentation

Generate a Random Prediction Table from a Fitted SVEMnet Model (no refit)

Description

Samples the original predictor factor space using ranges and levels cached inside a fitted svem_model (from SVEMnet()) and computes predictions at those points. Optional mixture groups let you sample composition variables on a (possibly truncated) simplex via a Dirichlet draw. No refitting is performed.

Usage

svem_random_table_from_model(
  object,
  n = 1000,
  mixture_groups = NULL,
  debias = FALSE
)

Arguments

object

A fitted svem_model returned by SVEMnet(). The object must contain $sampling_schema, which is created by the updated SVEMnet().

n

Number of random points to generate (default 1000).

mixture_groups

Optional list of mixture factor groups. Each element is a list with components:

  • vars: character vector of mixture variable names (must be in the model).

  • lower: numeric vector of lower bounds (same length as vars).

  • upper: numeric vector of upper bounds (same length as vars).

  • total: scalar specifying the group total (e.g., 1.0).

If omitted, all variables are sampled independently using the cached schema.

debias

Logical; if TRUE, applies the calibration from object$debias_fit (if available) to the mean prediction (default FALSE).

Details

This function uses:

  • object$sampling_schema$num_ranges for uniform sampling of numeric variables.

  • object$sampling_schema$factor_levels for categorical sampling.

  • object$terms, object$xlevels, and object$contrasts (via predict.svem_model) to encode the model matrix consistently.

Mixture groups are handled by drawing Dirichlet weights and mapping them to the truncated simplex defined by lower, upper, and total; proposals violating upper bounds are rejected (with oversampling to keep it efficient).

Value

A data frame with sampled predictors and a predicted response column. The response column name matches the left-hand side of object$formula.

See Also

SVEMnet, predict.svem_model, svem_significance_test, svem_significance_test_parallel

Examples


set.seed(1)
n <- 40
X1 <- runif(n); X2 <- runif(n)
A <- runif(n); B <- runif(n); C <- pmax(0, 1 - A - B)  # simple mixture-ish
F <- factor(sample(c("lo","hi"), n, TRUE))
y <- 1 + 2*X1 - X2 + 3*A + 1.5*B + 0.5*C + (F=="hi") + rnorm(n, 0, 0.3)
d <- data.frame(y, X1, X2, A, B, C, F)

fit <- SVEMnet(y ~ X1 + X2 + A + B + C + F, d, nBoot = 50, glmnet_alpha = 1)

# No mixture constraints (independent sampling using cached ranges/levels)
tbl1 <- svem_random_table_from_model(fit, n = 50)
head(tbl1)

# With mixture constraints for A,B,C that sum to 1 and have bounds
mix <- list(list(vars = c("A","B","C"),
                 lower = c(0.1, 0.1, 0.1),
                 upper = c(0.7, 0.7, 0.7),
                 total = 1.0))
tbl2 <- svem_random_table_from_model(fit, n = 50, mixture_groups = mix)
head(tbl2)



SVEMnet documentation built on Sept. 9, 2025, 5:38 p.m.