Learn R Programming

qfa (version 4.0)

sqr.fit.optim: Spline Quantile Regression (SQR) by Gradient Algorithms

Description

This function computes spline quantile regression by a gradient algorithm BFGS, ADAM, or GRAD.

Usage

sqr.fit.optim(
  X,
  y,
  tau,
  spar = 0,
  d = 1,
  weighted = FALSE,
  method = c("BFGS", "ADAM", "GRAD"),
  beta.rq = NULL,
  theta0 = NULL,
  spar0 = NULL,
  sg.rate = c(1, 1),
  mthreads = TRUE,
  control = list(trace = 0)
)

Value

A list with the following elements:

beta

matrix of regression coefficients

all.beta

coefficients from all iterations for GRAD and ADAM

spars

smoothing parameters from stats::smooth.spline() for initialization

fit

object from the optimization algorithm

Arguments

X

vecor or matrix of explanatory variables (including intercept)

y

vector of dependent variable

tau

sequence of quantile levels in (0,1)

spar

smoothing parameter

d

subsampling rate of quantile levels (default = 1)

weighted

if TRUE, penalty function is weighted (default = FALSE)

method

optimization method: "BFGS" (default), "ADAM", or "GRAD"

beta.rq

matrix of regression coefficients from quantreg::rq(y~X) for initialization (default = NULL)

theta0

initial value of spline coefficients (default = NULL)

spar0

smoothing parameter for stats::smooth.spline() to smooth beta.rq for initilaiztion (default = NULL)

sg.rate

vector of sampling rates for quantiles and observations in stochastic gradient version of GRAD and ADAM

mthreads

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

control

a list of control parameters

maxit:

max number of iterations (default = 100)

stepsize:

stepsize for ADAM and GRAD (default = 0.01)

warmup:

length of warmup phase for ADAM and GRAD (default = 70)

stepupdate:

frequency of update for ADAM and GRAD (default = 20)

stepredn:

stepsize discount factor for ADAM and GRAD (default = 0.2)

line.search.type:

line search option (1,2,3,4) for GRAD (default = 1)

line.search.max:

max number of line search trials for GRAD (default = 1)

seed:

seed for stochastic version of ADAM and GRAD (default = 1000)

trace:

-1 return results from all iterations, 0 (default) return final result

Examples

Run this code
data(engel)
y <- engel$foodexp
X <- cbind(rep(1,length(y)),engel$income-mean(engel$income))
tau <- seq(0.1,0.9,0.05)
fit.rq <- quantreg::rq(y ~ X[,2],tau)
fit.sqr <- sqr(y ~ X[,2],tau,d=2,spar=0.2)
fit <- sqr.fit.optim(X,y,tau,spar=0.2,d=2,method="BFSG",beta.rq=fit.rq$coef)
fit <- sqr.fit.optim(X,y,tau,spar=0.2,d=2,method="BFSG",beta.rq=fit.rq$coef)
par(mfrow=c(1,2),pty="m",lab=c(10,10,2),mar=c(4,4,2,1)+0.1,las=1)
for(j in c(1:2)) {
  plot(tau,fit.rq$coef[j,],type="n",xlab="QUANTILE LEVEL",ylab=paste0("COEFF",j))
  points(tau,fit.rq$coef[j,],pch=1,cex=0.5)
  lines(tau,fit.sqr$coef[j,],lty=1); lines(tau,fit$beta[j,],lty=2,col=2)
}

Run the code above in your browser using DataLab