sqr.fit.optim | R Documentation |
This function computes spline quantile regression by a gradient algorithm BFGS, ADAM, or GRAD.
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)
)
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 |
method |
optimization method: |
beta.rq |
matrix of regression coefficients from |
theta0 |
initial value of spline coefficients (default = |
spar0 |
smoothing parameter for |
sg.rate |
vector of sampling rates for quantiles and observations in stochastic gradient version of GRAD and ADAM |
mthreads |
if |
control |
a list of control parameters
|
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 |
fit |
object from the optimization algorithm |
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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.