# VARIABLE DOMAIN FUNCTIONAL DATA EXAMPLE
# set seed for reproducibility
set.seed(42)
# generate example data
data <- data_generator_vd(
N = 100,
J = 100,
beta_index = 1,
use_x = TRUE,
use_f = TRUE,
)
# Define a formula object that specifies the model behavior.
# The formula includes a functional form of the variable 'X_se' using 'ffvd'
# with a non-default number of basis functions ('nbasis' is set to c(10, 10, 10)).
# Additionally, it includes a smooth function 'f' applied to 'x2' with 10 segments ('nseg = 10'),
# a second-order penalty ('pord = 2'), and cubic splines ('degree = 3').
# The model also contains the linear term 'x1'.
formula <- y ~ ffvd(X_se, nbasis = c(10, 10, 10)) + f(x2, nseg = 10, pord = 2, degree = 3) + x1
# We can fit the model using the data and the formula
res <- vd_fit(formula = formula, data = data)
# Some important parameters of the model can be accesed as follows
res$Beta # variable domain functional coefficient
res$fit$fitted.values # estimated response variable
# Also, a summary of the fit can be accesed using the summary function
summary(res)
# And a heatmap for an specific beta can be obtained using the plot function
plot(res, beta_index = 1)
Run the code above in your browser using DataLab