Fits a smooth spline to a set of given observations using penalized splines with curvature or difference penalty and multiple covariates. The underlying linear system is solved with a matrix-free preconditioned conjugated gradient (PCG) method using a diagonal preconditioner.
PCG_smooth(
m,
q,
lambda,
X,
y,
pen_type = "curve",
l = NULL,
alpha_start = NULL,
K_max = NULL,
tolerance = 1e-06,
print_error = TRUE
)
Vector of non-negative integers. Each entry gives the number of inner knots for the respective covariate.
Vector of positive integers. Each entry gives the spline degree for the respective covariate.
Positive number as weight for the penalty term.
Matrix containing the covariates as columns and the units as rows.
Vector of length nrow(X)
as the variable of interest.
Utilized penalization method. Either "curve"
for the curvature penalty or "diff"
for the difference penalty. Defaults to "curve"
.
Positive integer vector of length P
indicating for the penalty degree. Only required if pen_type = "diff"
.
Vector of length prod(m+q+1)
as starting value for the PCG-method. Defaults to zero.
Positive integer as upper bound for the number of PCG-iterations. Defaults to prod(m+q+1)
.
Positive number as error tolerance for the stopping criterion of the PCG-method. Defaults to 1e-6
.
Logical, indicating if the iteration error should be printed or not.
Returns a list containing the input m
, q
, and Omega
. Further gives the fitted spline coefficients alpha
, the fitted values fitted_values
, the residuals residuals
, the root mean squared error rmse
and the R-squared value R_squared
.
# NOT RUN {
data <- generate_test_data(100, 2)
X <- data$X_train
y <- data$y_train
PCG_smooth(m = c(7,7), q = c(3,3), lambda = 0.1, X = X, y = y)
# }
Run the code above in your browser using DataLab