| Title: | Kernel Ridge Regression using Matern 3/2 kernels |
|---|---|
| Description: | Interpretable Probabilistic Kernel Ridge Regression using Matern 3/2 kernels. |
| Authors: | T. Moudiki |
| Maintainer: | T. Moudiki <[email protected]> |
| License: | BSD_3_clause Clear + file LICENSE |
| Version: | 0.2.0 |
| Built: | 2026-05-09 07:12:46 UTC |
| Source: | https://github.com/thierrymoudiki/matern32 |
A more detailed description of what the package does. A length of about one to five lines is recommended.
This section should provide a more detailed overview of how to use the package, including the most important functions.
Your Name, email optional.
Maintainer: Your Name <[email protected]>
This optional section can contain literature or other references for background information.
Optional links to other man pages
## Not run: ## Optional simple examples of the most important functions ## These can be in \dontrun{} and \donttest{} blocks. ## End(Not run)## Not run: ## Optional simple examples of the most important functions ## These can be in \dontrun{} and \donttest{} blocks. ## End(Not run)
Compute the first and second order derivatives of the response function
derivatives(fit_obj, obs = NULL)derivatives(fit_obj, obs = NULL)
fit_obj |
Fitted object |
Direct sampling
direct_sampling( data = NULL, n = 100L, method = c("kde", "surrogate", "bootstrap"), kde = NULL, seed = NULL, ... )direct_sampling( data = NULL, n = 100L, method = c("kde", "surrogate", "bootstrap"), kde = NULL, seed = NULL, ... )
data |
A numeric vector or matrix. |
n |
The number of samples to draw. |
method |
The method to use for sampling. |
kde |
The kernel density estimate to use for sampling. |
seed |
The seed to use for sampling. |
... |
Additional arguments to pass to the density function. |
Fit Matern 3/2 model
fit_matern32( x, y, lambda = 10^seq(-10, 10, length.out = 100), l = NULL, method = c("chol", "solve", "svd", "eigen", "conformal"), with_kmeans = FALSE, centers = NULL, centering = FALSE, seed = 123, ... )fit_matern32( x, y, lambda = 10^seq(-10, 10, length.out = 100), l = NULL, method = c("chol", "solve", "svd", "eigen", "conformal"), with_kmeans = FALSE, centers = NULL, centering = FALSE, seed = 123, ... )
x |
Matrix of predictors |
y |
Vector of response values |
lambda |
Regularization parameter |
l |
Hyperparameter for the Matern 3/2 kernel |
method |
Method to use for fitting the model |
with_kmeans |
Use k-means to reduce the number of observations |
centers |
Number of centers to use in k-means |
centering |
Center the response |
seed |
Seed for reproducibility |
... |
|
sigma |
Hyperparameter for the Matern 3/2 kernel |
n <- 100; p <- 4 set.seed(456) X <- matrix(rnorm(n * p), n, p) # no intercept! y <- rnorm(n) lams <- 10^seq(-5, 4, length.out = 50) fit_obj <- matern32::fit_matern32(x = X, y = y, lambda = lams) par(mfrow=c(1, 2)) plot(log(lams), fit_obj$GCV, type = 'l', main = "GCV", ylab = "GCV") matplot(log(lams), t(fit_obj$coef), type = 'l', main = "coefficients = f(lambda)", xlab = "log(lambda)", ylab = "coefs") abline(h = 0, lty = 2, lwd = 2, col = "red") matern32::summary.matern32(fit_obj) library(MASS) X <- longley[,-7] y <- longley[, 7] fit_obj <- matern32::fit_matern32(x = X, y = y) par(mfrow=c(1, 2)) plot(log(fit_obj$lambda), fit_obj$GCV, type = 'l', main = "GCV", ylab = "GCV") matplot(log(fit_obj$lambda), t(fit_obj$coef), type = 'l', main = "coefficients = f(lambda)", xlab = "log(lambda)", ylab = "coefs") abline(h = 0, lty = 2, lwd = 2, col = "red") matern32::summary.matern32(fit_obj) library(MASS) X <- as.matrix(Boston[,-14]) y <- Boston[,14] fit_obj <- matern32::fit_matern32(x = X, y = y, lambda = lams) matern32::summary.matern32(fit_obj)n <- 100; p <- 4 set.seed(456) X <- matrix(rnorm(n * p), n, p) # no intercept! y <- rnorm(n) lams <- 10^seq(-5, 4, length.out = 50) fit_obj <- matern32::fit_matern32(x = X, y = y, lambda = lams) par(mfrow=c(1, 2)) plot(log(lams), fit_obj$GCV, type = 'l', main = "GCV", ylab = "GCV") matplot(log(lams), t(fit_obj$coef), type = 'l', main = "coefficients = f(lambda)", xlab = "log(lambda)", ylab = "coefs") abline(h = 0, lty = 2, lwd = 2, col = "red") matern32::summary.matern32(fit_obj) library(MASS) X <- longley[,-7] y <- longley[, 7] fit_obj <- matern32::fit_matern32(x = X, y = y) par(mfrow=c(1, 2)) plot(log(fit_obj$lambda), fit_obj$GCV, type = 'l', main = "GCV", ylab = "GCV") matplot(log(fit_obj$lambda), t(fit_obj$coef), type = 'l', main = "coefficients = f(lambda)", xlab = "log(lambda)", ylab = "coefs") abline(h = 0, lty = 2, lwd = 2, col = "red") matern32::summary.matern32(fit_obj) library(MASS) X <- as.matrix(Boston[,-14]) y <- Boston[,14] fit_obj <- matern32::fit_matern32(x = X, y = y, lambda = lams) matern32::summary.matern32(fit_obj)
Polynomial regression
fit_poly(x, y, degree = 1)fit_poly(x, y, degree = 1)
x |
Matrix of predictors |
y |
Vector of response values |
degree |
Degree of the polynomial |
Title
interactions(fit_obj, index_col1 = 1, index_col2 = 2, obs = NULL)interactions(fit_obj, index_col1 = 1, index_col2 = 2, obs = NULL)
fit_obj |
|
index_col1 |
|
index_col2 |
|
obs |
Title
plot_heterogeneity(fit_obj, var = 1, ...)plot_heterogeneity(fit_obj, var = 1, ...)
fit_obj |
|
var |
|
... |
Plot interactions
plot_interactions( fit_obj, var1 = 1, var2 = 2, method = c("poly", "mars"), degree = 1, ... )plot_interactions( fit_obj, var1 = 1, var2 = 2, method = c("poly", "mars"), degree = 1, ... )
fit_obj |
Fitted object of class 'matern32' |
var1 |
Covariate 1 |
var2 |
Covariate 2 |
method |
The method to use for smoothing the interactions |
degree |
The degree of the polynomial to use for smoothing |
... |
Title
plot_loocv(fit_obj, ...)plot_loocv(fit_obj, ...)
fit_obj |
|
... |
Plot residuals
plot_residuals(fit_obj, ...)plot_residuals(fit_obj, ...)
fit_obj |
Plot method for matern32 objects
plot.matern32( fit_obj, choice = c("coeffs", "GCV", "heterogeneity", "interactions", "residuals"), ... )plot.matern32( fit_obj, choice = c("coeffs", "GCV", "heterogeneity", "interactions", "residuals"), ... )
fit_obj |
Fitted object of class 'matern32' |
choice |
The type of plot to produce (coeffs, GCV, heterogeneity, interactions, residuals) |
... |
Predict from Matern 3/2 model
## S3 method for class 'matern32' predict( fit_obj, newx, level = NULL, method = c("splitconformal", "kde", "surrogate", "bootstrap"), nsim = 250L, B = nsim )## S3 method for class 'matern32' predict( fit_obj, newx, level = NULL, method = c("splitconformal", "kde", "surrogate", "bootstrap"), nsim = 250L, B = nsim )
fit_obj |
Fitted object from |
newx |
New data matrix |
level |
Confidence level for prediction intervals (between 0 and 100) |
method |
Method to use for prediction intervals |
nsim |
Number of simulations to use for prediction |
B |
Alias for |
n <- 100 ; p <- 4 set.seed(456) X <- matrix(rnorm(n * p), n, p) # no intercept! y <- rnorm(n) lams <- 10^seq(-10, 10, length.out = 50) fit_obj <- fit_matern32(x = X, y = y, lambda = lams) df <- data.frame(predict(fit_obj, X) - y) colnames(df) <- paste0(round(lams, 2)) summary(df) boxplot(df[, c(1, 10, 25, 35, 50)], main = "distribution of in sample bias", xlab = "lambda", ylab = "y_hat - y")n <- 100 ; p <- 4 set.seed(456) X <- matrix(rnorm(n * p), n, p) # no intercept! y <- rnorm(n) lams <- 10^seq(-10, 10, length.out = 50) fit_obj <- fit_matern32(x = X, y = y, lambda = lams) df <- data.frame(predict(fit_obj, X) - y) colnames(df) <- paste0(round(lams, 2)) summary(df) boxplot(df[, c(1, 10, 25, 35, 50)], main = "distribution of in sample bias", xlab = "lambda", ylab = "y_hat - y")
Predict method for polynomial regression
## S3 method for class 'poly' predict(object, newx)## S3 method for class 'poly' predict(object, newx)
object |
Fitted object |
newx |
New data |
Simple function using Rcpp
rcpp_hello_world()rcpp_hello_world()
## Not run: rcpp_hello_world() ## End(Not run)## Not run: rcpp_hello_world() ## End(Not run)
Simulate multivariate data
rmultivariate( data, method = c("bootstrap", "block-bootstrap"), n = 100L, block_size = 5 )rmultivariate( data, method = c("bootstrap", "block-bootstrap"), n = 100L, block_size = 5 )
data |
A numeric vector or matrix. |
method |
The method to use for sampling. |
n |
The number of samples to draw. |
block_size |
The size of the blocks to use for the block bootstrap. |
... |
Additional arguments to pass to the density function. |
Title
sensi1D(fit_obj, index_col, h, verbose = TRUE)sensi1D(fit_obj, index_col, h, verbose = TRUE)
fit_obj |
object fitted by using |
index_col |
an integer, column index |
h |
(must be small) |
Title
sensi2D(fit_obj, index_col1, index_col2, h1, h2, verbose = TRUE)sensi2D(fit_obj, index_col1, index_col2, h1, h2, verbose = TRUE)
fit_obj |
object fitted by using |
index_col1 |
an integer, column index |
index_col2 |
an integer, second column index |
h |
(must be small) |
Summary method for matern32
summary.matern32(fit_obj, obs = NULL, verbose = TRUE)summary.matern32(fit_obj, obs = NULL, verbose = TRUE)
fit_obj |
Fitted object of class 'matern32' |
obs |
observation number for which to calculate the derivatives (default is NULL) |
verbose |
logical indicating whether to print the summary (default is TRUE) |