# \donttest{
# Fast computation example with synthetic data
n <- 80
p <- 16
# Generate synthetic data with 2 blocks
set.seed(789)
x_train <- matrix(rnorm(n * p), n, p)
x_tuning <- matrix(rnorm(40 * p), 40, p)
x_test <- matrix(rnorm(25 * p), 25, p)
# True coefficients
beta_true <- c(rep(1.2, 3), rep(0, 5), rep(-0.8, 2), rep(0, 6))
# Response variables
y_train <- x_train %*% beta_true + rnorm(n, sd = 0.3)
y_tuning <- x_tuning %*% beta_true + rnorm(40, sd = 0.3)
y_test <- x_test %*% beta_true + rnorm(25, sd = 0.3)
# Block sizes (2 blocks of 8 variables each)
pp <- c(8, 8)
# Run fast AdapDiscom (faster with fewer tuning parameters)
result <- fast_adapdiscom(beta = beta_true,
x = x_train, y = y_train,
x.tuning = x_tuning, y.tuning = y_tuning,
x.test = x_test, y.test = y_test,
nlambda = 15, pp = pp, n.l = 20)
# View results
print(paste("Test R-squared:", round(result$R2, 3)))
print(paste("Computation time:", round(result$time[3], 2), "seconds"))
# }
Run the code above in your browser using DataLab