View source: R/cv_GeDSMethod.R
crossv_GeDS | R Documentation |
crossv_GeDS
performs k-fold cross-validation for tuning the relevant
parameters of the NGeDS
, GGeDS
, NGeDSgam
, and
NGeDSboost
models.
formula |
a description of the structure of the model structure, including the dependent and independent variables. |
data |
a data frame containing the variables referenced in the formula. |
model_fun |
the GeDS model to be fitted, that is, |
parameters |
to tune via cross-validation. These are: |
Two data frames, best_params
and results
.
best_params
contains the best combination of parameters according to
the cross-validated MSE. results
presents the cross-validated MSE and
the average number of internal knots across the folds for each possible
combination of parameters, given the input parameters
. In the case of
model_fun = NGeDSboost
, it also provides the cross-validated number of
boosting iterations.
###################################################
# Generate a data sample for the response variable
# Y and the single covariate X
set.seed(123)
N <- 500
f_1 <- function(x) (10*x/(1+100*x^2))*4+4
X <- sort(runif(N, min = -2, max = 2))
# Specify a model for the mean of Y to include only a component
# non-linear in X, defined by the function f_1
means <- f_1(X)
# Add (Normal) noise to the mean of Y
Y <- rnorm(N, means, sd = 0.1)
data = data.frame(X = X, Y = Y)
## Not run:
## NGeDS
# Define different combinations of parameters to cross-validate
param = list(beta_grid = c(0.5),
phi_grid = c(0.9, 0.95),
q_grid = c(2))
cv_NGeDS <- crossv_GeDS(Y ~ f(X), data = data, NGeDS, n = 3L,
parameters = param)
print(cv_NGeDS$best_params)
View(cv_NGeDS$results)
## NGeDSboost
param = list(int.knots_init_grid = c(1, 2),
shrinkage_grid = 1,
beta_grid = c(0.3, 0.5),
phi_grid = c(0.95, 0.99),
q_grid = 2)
cv_NGeDSboost <- crossv_GeDS(Y ~ f(X), data = data, NGeDSboost, n = 2L,
n_folds = 2L, parameters = param)
print(cv_NGeDSboost$best_params)
View(cv_NGeDSboost$results)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.