Learn R Programming

SLGP (version 1.0.2)

predictSLGP_quantiles: Predict quantiles from a SLGP model at new locations

Description

Computes quantile values at specified levels (probs) for new covariate points, based on the posterior CDFs from a trained SLGP model.

Usage

predictSLGP_quantiles(
  SLGPmodel,
  newNodes,
  probs,
  interpolateBasisFun = "WNN",
  nIntegral = 101,
  nDiscret = 101,
  discrete = FALSE
)

Value

A data frame with columns:

  • The covariates in newNodes (repeated per quantile level),

  • A column probs indicating the quantile level,

  • Columns qSLGP_1, qSLGP_2, ... for each posterior sample's quantile estimate.

Arguments

SLGPmodel

An object of class SLGP-class.

newNodes

A data frame of covariate values.

probs

Numeric vector of quantile levels to compute (e.g., 0.1, 0.5, 0.9).

interpolateBasisFun

Character string specifying interpolation scheme: "nothing", "NN", or "WNN" (default).

nIntegral

Number of integration points for computing the SLGP outputs.

nDiscret

Discretization level of the response axis (for CDF inversion).

discrete

Boolean, indicates if we work with continuous pdfs (default, FALSE) or discrete probabilities

Examples

Run this code
# \donttest{
# Load Boston housing dataset
library(MASS)
data("Boston")
# Set input and output ranges manually (you can also use range(Boston$age), etc.)
range_x <- c(0, 100)
range_response <- c(0, 50)

# Train an SLGP model using Laplace estimation and RFF basis
modelLaplace <- slgp(medv ~ age,        # Use a formula to specify response and covariates
                 data = Boston,     # Use the original Boston housing data
                 method = "Laplace",    # Train using Maximum A Posteriori estimation
                 basisFunctionsUsed = "RFF",         # Random Fourier Features
                 sigmaEstimationMethod = "heuristic",  # Auto-tune sigma2 (more stable)
                 predictorsLower = range_x[1],         # Lower bound for 'age'
                 predictorsUpper = range_x[2],         # Upper bound for 'age'
                 responseRange = range_response,       # Range for 'medv'
                 opts_BasisFun = list(nFreq = 200,     # Use 200 Fourier features
                                      MatParam = 5/2), # Matern 5/2 kernel
                 seed = 1)                             # Reproducibility
dfX <- data.frame(age=seq(range_x[1], range_x[2], 1))
# Predict some quantiles, for instance here the first quartile, median, third quartile
predQuartiles <- predictSLGP_quantiles(SLGPmodel= modelLaplace,
                                       newNodes = dfX,
                                       probs=c(0.25, 0.50, 0.75))

# }

Run the code above in your browser using DataLab