Learn R Programming

qfa (version 5.0)

sqr: Spline Quantile Regression by Formula

Description

This function computes the spline quantile regression solution SQR, SQR1, or SAR3 on a given set of quantile levels from a regression formula with or without user-supplied smoothing parameter. SQR represents the regression coefficients as cubic spline functions of the quantile level and employs the L1-norm of their second derivative as roughness penalty. SQR1 represents the regression coefficients as linear spline functions and employs the total variation of their first derivatives as roughness penalty. SQR3 also represents the regression coefficients as cubic spline functions but employs the L2-norm of their second derivatives as roughness penalty. SQR and SQR1 are solved as linear program (LP) using sqr.fit() and sqr1.fit(), respectively. SQR3 is solved as quadratic program (QP) using sqr3.fit().

Usage

sqr(
  formula,
  tau = seq(0.1, 0.9, 0.2),
  tau0 = tau,
  spar = NULL,
  w = rep(1, length(tau0)),
  mthreads = FALSE,
  criterion = c("AIC", "BIC", "GIC"),
  method = c("sqr", "sqr1", "sqr3"),
  type = c("dual", "primal"),
  ztol = NULL,
  solver = NULL,
  interval = NULL,
  npar = c(1, 2),
  all.knots = FALSE,
  control = list(),
  data,
  subset,
  na.action,
  model = TRUE
)

Value

object of sqr.fit(), sqr1.fit(), or sqr3.fit()

Arguments

formula

formula object, with the response on the left of a ~ operator, and the terms, separated by + operators, on the right.

tau

sequence of quantile levels for evaluation

tau0

sequence of quantile levels for fitting (min(tau0) <= tau <= max(tau0); default = tau)

spar

smoothing parameter, selected automatically by criterion if spar = NULL (default)

w

weight sequence in penalty (default = rep(1,length(tau0)))

mthreads

if FALSE (default), set RhpcBLASctl::blas_set_num_threads(1)

criterion

criterion for smoothing parameter selection ("AIC", "BIC", or "GIC")

method

'sqr' (default), 'sqr1', or 'sqr3'

type

type of QP formulation for SQR3: 'dual' (default) or 'primal'

ztol

zero-tolerance parameter to determine the model complexity (default = NULL: set internally to 1e-5 for SQR and SQR1 or 1e-4 for SQR3)

solver

'fnb' or 'sfn' for SQR and SQR1; 'piqp' or 'osqp' for SQR3 (default = NULL: set internally to 'fnb' for SQR and SQR1 or 'piqp' for SQR3)

interval

interval for spar optimization (default: c(-1.5,1.5) for SQR and SQR1 or c(1.0,2.5) for SQR3)

npar

experimental parameter (default = 1)

all.knots

TRUE or FALSE (default), same as in stats::smooth.spline()

control

list of control parameters for QP solvers 'piqp' and 'osqp'

data

data.frame object containing the observations

subset

an optional vector specifying a subset of observations to be used

na.action

a function to filter missing data (see rq() in the 'quantreg' package)

model

if TRUE then the model frame is returned (needed for calling summary subsequently)

Examples

Run this code
library(quantreg)
data(engel)
engel$income <- (engel$income - mean(engel$income))/1000
tau <- seq(0.1,0.9,0.05)
fit <- rq(foodexp ~ income,tau=tau,data=engel)
fit.sqr1 <- sqr(foodexp ~ income,tau=tau,spar=0.5,method="sqr1",data=engel)
fit.sqr3 <- sqr(foodexp ~ income,tau=tau,spar=0.5,method="sqr3",data=engel)
par(mfrow=c(1,1),pty="m",lab=c(10,10,2),mar=c(4,4,2,1)+0.1,las=1)
plot(tau,fit$coef[2,],xlab="Quantile Level",ylab="Coeff1")
lines(tau,fit.sqr1$coef[2,])
lines(tau,fit.sqr3$coef[2,],col=2)

Run the code above in your browser using DataLab