Package 'matern32'

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

Help Index


A short title line describing what the package does

Description

A more detailed description of what the package does. A length of about one to five lines is recommended.

Details

This section should provide a more detailed overview of how to use the package, including the most important functions.

Author(s)

Your Name, email optional.

Maintainer: Your Name <[email protected]>

References

This optional section can contain literature or other references for background information.

See Also

Optional links to other man pages

Examples

## 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

Description

Compute the first and second order derivatives of the response function

Usage

derivatives(fit_obj, obs = NULL)

Arguments

fit_obj

Fitted object


Direct sampling

Description

Direct sampling

Usage

direct_sampling(
  data = NULL,
  n = 100L,
  method = c("kde", "surrogate", "bootstrap"),
  kde = NULL,
  seed = NULL,
  ...
)

Arguments

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

Description

Fit Matern 3/2 model

Usage

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,
  ...
)

Arguments

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

Examples

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

Description

Polynomial regression

Usage

fit_poly(x, y, degree = 1)

Arguments

x

Matrix of predictors

y

Vector of response values

degree

Degree of the polynomial


Title

Description

Title

Usage

interactions(fit_obj, index_col1 = 1, index_col2 = 2, obs = NULL)

Arguments

fit_obj
index_col1
index_col2
obs

Title

Description

Title

Usage

plot_coeffs(fit_obj, ...)

Arguments

fit_obj

Title

Description

Title

Usage

plot_GCV(fit_obj, ...)

Arguments

fit_obj

Title

Description

Title

Usage

plot_heterogeneity(fit_obj, var = 1, ...)

Arguments

fit_obj
var
...

Plot interactions

Description

Plot interactions

Usage

plot_interactions(
  fit_obj,
  var1 = 1,
  var2 = 2,
  method = c("poly", "mars"),
  degree = 1,
  ...
)

Arguments

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

Description

Title

Usage

plot_loocv(fit_obj, ...)

Arguments

fit_obj
...

Plot residuals

Description

Plot residuals

Usage

plot_residuals(fit_obj, ...)

Arguments

fit_obj

Plot method for matern32 objects

Description

Plot method for matern32 objects

Usage

plot.matern32(
  fit_obj,
  choice = c("coeffs", "GCV", "heterogeneity", "interactions", "residuals"),
  ...
)

Arguments

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

Description

Predict from Matern 3/2 model

Usage

## S3 method for class 'matern32'
predict(
  fit_obj,
  newx,
  level = NULL,
  method = c("splitconformal", "kde", "surrogate", "bootstrap"),
  nsim = 250L,
  B = nsim
)

Arguments

fit_obj

Fitted object from fit_matern32

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 nsim

Examples

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

Description

Predict method for polynomial regression

Usage

## S3 method for class 'poly'
predict(object, newx)

Arguments

object

Fitted object

newx

New data


Simple function using Rcpp

Description

Simple function using Rcpp

Usage

rcpp_hello_world()

Examples

## Not run: 
rcpp_hello_world()

## End(Not run)

Simulate multivariate data

Description

Simulate multivariate data

Usage

rmultivariate(
  data,
  method = c("bootstrap", "block-bootstrap"),
  n = 100L,
  block_size = 5
)

Arguments

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

Description

Title

Usage

sensi1D(fit_obj, index_col, h, verbose = TRUE)

Arguments

fit_obj

object fitted by using fit_matern32

index_col

an integer, column index

h

(must be small)


Title

Description

Title

Usage

sensi2D(fit_obj, index_col1, index_col2, h1, h2, verbose = TRUE)

Arguments

fit_obj

object fitted by using fit_matern32

index_col1

an integer, column index

index_col2

an integer, second column index

h

(must be small)


Summary method for matern32

Description

Summary method for matern32

Usage

summary.matern32(fit_obj, obs = NULL, verbose = TRUE)

Arguments

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)