View source: R/svem_random_table.R
svem_random_table_from_model | R Documentation |
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.
svem_random_table_from_model(
object,
n = 1000,
mixture_groups = NULL,
debias = FALSE
)
object |
A fitted |
n |
Number of random points to generate (default |
mixture_groups |
Optional list of mixture factor groups. Each element is a list with components:
If omitted, all variables are sampled independently using the cached schema. |
debias |
Logical; if |
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).
A data frame with sampled predictors and a predicted response column.
The response column name matches the left-hand side of object$formula
.
SVEMnet
, predict.svem_model
,
svem_significance_test
, svem_significance_test_parallel
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.