## ---- Gaussian example -------------------------------------------------
set.seed(1)
n <- 60
X1 <- rnorm(n); X2 <- rnorm(n); X3 <- rnorm(n)
y <- 1 + 0.8 * X1 - 0.6 * X2 + 0.2 * X3 + rnorm(n, 0, 0.4)
dat <- data.frame(y, X1, X2, X3)
fit_g <- SVEMnet(
y ~ (X1 + X2 + X3)^2, dat,
nBoot = 40, glmnet_alpha = c(1, 0.5),
relaxed = TRUE, family = "gaussian"
)
## Aggregate-coefficient predictions (with and without debiasing)
p_g <- predict(fit_g, dat) # debias = FALSE (default)
p_gd <- predict(fit_g, dat, debias = TRUE) # apply calibration, if available
## Bootstrap-based uncertainty (requires coef_matrix)
out_g <- predict(
fit_g, dat,
debias = TRUE,
se.fit = TRUE,
interval = TRUE,
level = 0.90
)
str(out_g)
# \donttest{
## ---- Binomial example ------------------------------------------------
set.seed(2)
n <- 120
X1 <- rnorm(n); X2 <- rnorm(n); X3 <- rnorm(n)
eta <- -0.3 + 1.1 * X1 - 0.8 * X2 + 0.5 * X1 * X3
p <- plogis(eta)
yb <- rbinom(n, 1, p)
db <- data.frame(yb = yb, X1 = X1, X2 = X2, X3 = X3)
fit_b <- SVEMnet(
yb ~ (X1 + X2 + X3)^2, db,
nBoot = 50, glmnet_alpha = c(1, 0.5),
relaxed = TRUE, family = "binomial"
)
## Probabilities, link, and classes
p_resp <- predict(fit_b, db, type = "response")
p_link <- predict(fit_b, db, type = "link")
y_hat <- predict(fit_b, db, type = "class") # 0/1 labels (no SE or interval)
## Bootstrap-based uncertainty on the probability scale
out_b <- predict(
fit_b, db,
type = "response",
se.fit = TRUE,
interval = TRUE,
level = 0.90
)
str(out_b)
# }
Run the code above in your browser using DataLab