## generate sample data
set.seed(1)
n <- 40
p <- 18 # number of basis to GENERATE beta
r <- 100
s <- seq(0, 1, length.out = r)
beta_basis <- splines::bs(s, df = p, intercept = TRUE) # basis
coef_data <- matrix(rnorm(n*floor(p/2)), n, floor(p/2))
fun_data <- coef_data %*% t(splines::bs(s, df = floor(p/2), intercept = TRUE))
x_0 <- apply(matrix(rnorm(p, sd=1),p,1), 1, fdaSP::softhresh, 1) # regression coefficients
x_fun <- beta_basis %*% x_0
b <- fun_data %*% x_fun + rnorm(n, sd = sqrt(crossprod(fun_data %*% x_fun ))/10)
l <- 10^seq(2, -4, length.out = 30)
maxit <- 1000
## set the hyper-parameters
maxit <- 1000
rho_adaptation <- TRUE
rho <- 1
reltol <- 1e-5
abstol <- 1e-5
mod <- f2sSP(vY = b, mX = fun_data, M = p,
group_weights = NULL, var_weights = NULL, standardize.data = FALSE, splOrd = 4,
lambda = NULL, nlambda = 30, lambda.min = NULL, overall.group = FALSE,
control = list("abstol" = abstol,
"reltol" = reltol,
"adaptation" = rho_adaptation,
"rho" = rho,
"print.out" = FALSE))
# plot coefficiente path
matplot(log(mod$lambda), mod$sp.coef.path, type = "l",
xlab = latex2exp::TeX("$\\log(\\lambda)$"), ylab = "", bty = "n", lwd = 1.2)
Run the code above in your browser using DataLab