Title: | Penalized Quantile Regression with Fixed Effects |
---|---|
Description: | Quantile regression with fixed effects is a general model for longitudinal data. Here we proposed to solve it by several methods. The estimation methods include three loss functions as check, asymmetric least square and asymmetric Huber functions; and three structures as simple regression, fixed effects and fixed effects with penalized intercepts by LASSO. |
Authors: | Ian Meneghel Danilevicz [aut, cre] , Valderio A Reisen [aut], Pascal Bondon [aut] |
Maintainer: | Ian Meneghel Danilevicz <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.1 |
Built: | 2024-11-01 06:48:43 UTC |
Source: | CRAN |
Quantile regression with fixed effects is a general model for longitudinal data. Here we proposed to solve it by several methods. The estimation methods include three loss functions as check, asymmetric least square and asymmetric Huber functions; and three structures as simple regression, fixed effects and fixed effects with penalized intercepts by LASSO.
Index of help topics:
check_lambda check lambda choice_p choice model clean_data Clean missings d_psi_als D Psi ALS d_psi_mq D Psi M-quantile f_den Kernel density f_tab Tabular function loss_er Loss expectile regression loss_erfe Loss expectile regression with fixed effects loss_erlasso Loss lasso expectile regression with fixed effects loss_mqr Loss M-quantile regression loss_mqrfe Loss M-quantile regression with fixed effects loss_mqrlasso Loss lasso M-quantile regression with fixed effects loss_qr Loss quantile regression loss_qrfe Loss quantile regression with fixed effects loss_qrlasso Loss lasso quantile regression with fixed effects mpqr Multiple penalized quantile regression optim_er optim expectile regression optim_erfe optim expectile regression with fixed effects optim_erlasso optim expectile regression with fixed effects and LASSO optim_mqr optim M-quantile regression optim_mqrfe optim quantile regression with fixed effects optim_mqrlasso optim M-quantile regression with fixed effects and LASSO optim_qr optim quantile regression optim_qrfe optim quantile regression with fixed effects optim_qrlasso optim quantile regression with fixed effects and LASSO plot_taus Plot multiple penalized quantile regression pqr Penalized quantile regression with fixed effects pqrfe-package Penalized Quantile Regression with Fixed Effects print.PQR Print an PQR psi_als Psi ALS psi_mq Psi M-quantile q_cov Covariance rho_koenker Rho Koenker rho_mq Rho M-quantile sgf Identify significance
Ian Meneghel Danilevicz <[email protected]>
Ian Meneghel Danilevicz [aut, cre] (<https://orcid.org/0000-0003-4541-0524>), Valderio A Reisen [aut], Pascal Bondon [aut]
check lambda
check_lambda(lambda, infb, supb)
check_lambda(lambda, infb, supb)
lambda |
Numeric, value of lambda. |
infb |
Numeric, lower bound of lambda. |
supb |
Numeric, upper bound of lambda. |
lambda Numeric, valid value of lambda.
choice model
choice_p(effect)
choice_p(effect)
effect |
Factor, simple, fixed or lasso. |
penalty Numeric, 1, 2 and 3.
Clean missings
clean_data(y, x, id)
clean_data(y, x, id)
y |
Numeric vector, outcome. |
x |
Numeric matrix, covariates |
id |
Numeric vector, identifies the unit to which the observation belongs. |
list with the same objects y, x, id, but without missings.
n = 10 m = 4 d = 3 N = n*m L = N*d x = matrix(rnorm(L), ncol=d, nrow=N) subj = rep(1:n, each=m) alpha = rnorm(n) beta = rnorm(d) eps = rnorm(N) y = x %*% beta + matrix(rep(alpha, each=m) + eps) y = as.vector(y) x[1,3] = NA clean_data(y=y, x=x, id=subj)
n = 10 m = 4 d = 3 N = n*m L = N*d x = matrix(rnorm(L), ncol=d, nrow=N) subj = rep(1:n, each=m) alpha = rnorm(n) beta = rnorm(d) eps = rnorm(N) y = x %*% beta + matrix(rep(alpha, each=m) + eps) y = as.vector(y) x[1,3] = NA clean_data(y=y, x=x, id=subj)
Derivative of Psi asymetric least square
d_psi_als(x, tau)
d_psi_als(x, tau)
x |
generic vector |
tau |
percentile |
y vector, linear transformation by derivative ALS psi
Derivative of psi M-quantile
d_psi_mq(x, tau, c)
d_psi_mq(x, tau, c)
x |
generic vector |
tau |
percentile |
c |
tuning |
y vector, linear transformation by second derivative m-rho
Kernel density
f_den(x)
f_den(x)
x |
Numeric vector. |
y vector, kernel density estimation.
x = rnorm(10) f_den(x)
x = rnorm(10) f_den(x)
Tabular function
f_tab(N, n, d, theta, sig2, kind)
f_tab(N, n, d, theta, sig2, kind)
N |
sample size. |
n |
length of alpha. |
d |
length of beta. |
theta |
Numeric vector. |
sig2 |
Numeric vector. |
kind |
Numeric, 1 means alpha, 2 means beta |
a list with a dataframe Core and a matrix Matx, both display the same information
This function returns the core of expectile regression to be minimized
loss_er(beta, x, y, tau, N, d)
loss_er(beta, x, y, tau, N, d)
beta |
initial values |
x |
design matrix |
y |
vector output |
tau |
percentile |
N |
sample size |
d |
columns of x |
eta Numeric, sum of expectile regression
This function returns the core of expectile regression with fixed effects to be minimized
loss_erfe(theta, x, y, z, tau, n, d, mm)
loss_erfe(theta, x, y, z, tau, n, d, mm)
theta |
initial values |
x |
design matrix |
y |
vector output |
z |
incident matrix |
tau |
percentile |
n |
N sample size |
d |
columns of x |
mm |
n columns of z |
eta Numeric, sum of expectile regression with fixed effects
This function returns the core of lasso expectile regression with fixed effects to be minimized
loss_erlasso(theta, x, y, z, tau, n, d, mm, lambda)
loss_erlasso(theta, x, y, z, tau, n, d, mm, lambda)
theta |
initial values |
x |
design matrix |
y |
vector output |
z |
incident matrix |
tau |
percentile |
n |
N sample size |
d |
columns of x |
mm |
n columns of z |
lambda |
constriction parameter |
eta Numeric, sum of lasso expectile regression with fixed effects
This function returns the core of M-quantile regression to be minimized
loss_mqr(beta, x, y, tau, N, d, c)
loss_mqr(beta, x, y, tau, N, d, c)
beta |
initial values |
x |
design matrix |
y |
vector output |
tau |
percentile |
N |
sample size |
d |
columns of x |
c |
tuning |
eta Numeric, sum of M-quantile regression
This function returns the core of M-quantile regression with fixed effects to be minimized
loss_mqrfe(theta, x, y, z, tau, n, d, mm, c)
loss_mqrfe(theta, x, y, z, tau, n, d, mm, c)
theta |
initial values |
x |
design matrix |
y |
vector output |
z |
incident matrix |
tau |
percentile |
n |
N sample size |
d |
columns of x |
mm |
n columns of z |
c |
tuning |
eta Numeric, sum of M-quantile regression with fixed effects
This function returns the core of lasso M-quantile regression with fixed effects to be minimized
loss_mqrlasso(theta, x, y, z, tau, n, d, mm, c, lambda)
loss_mqrlasso(theta, x, y, z, tau, n, d, mm, c, lambda)
theta |
initial values |
x |
design matrix |
y |
vector output |
z |
incident matrix |
tau |
percentile |
n |
N sample size |
d |
columns of x |
mm |
n columns of z |
c |
tuning |
lambda |
constriction parameter |
eta Numeric, sum of lasso M-quantile regression with fixed effects
This function returns the core of quantile regression to be minimized
loss_qr(beta, x, y, tau, N, d)
loss_qr(beta, x, y, tau, N, d)
beta |
initial values |
x |
design matrix |
y |
vector output |
tau |
percentile |
N |
sample size |
d |
columns of x |
eta Numeric, sum of quantile regression
This function returns the core of quantile regression with fixed effects to be minimized
loss_qrfe(theta, x, y, z, tau, n, d, mm)
loss_qrfe(theta, x, y, z, tau, n, d, mm)
theta |
initial values |
x |
design matrix |
y |
vector output |
z |
incident matrix |
tau |
percentile |
n |
N sample size |
d |
columns of x |
mm |
n columns of z |
eta Numeric, sum of quantile regression with fixed effects
This function returns the core of lasso quantile regression with fixed effects to be minimized
loss_qrlasso(theta, x, y, z, tau, n, d, mm, lambda)
loss_qrlasso(theta, x, y, z, tau, n, d, mm, lambda)
theta |
initial values |
x |
design matrix |
y |
vector output |
z |
incident matrix |
tau |
percentile |
n |
N sample size |
d |
columns of x |
mm |
n columns of z |
lambda |
constriction parameter |
eta Numeric, sum of lasso quantile regression with fixed effects
Estimate penalized quantile regression for several taus
mpqr(x, y, subj, tau = 1:9/10, effect = "simple", c = 0)
mpqr(x, y, subj, tau = 1:9/10, effect = "simple", c = 0)
x |
Numeric matrix, covariates |
y |
Numeric vector, outcome. |
subj |
Numeric vector, identifies the unit to which the observation belongs. |
tau |
Numeric vector, identifies the percentiles. |
effect |
Factor, "simple" simple regression, "fixed" regression with fixed effects, "lasso" penalized regression with fixed effects. |
c |
Numeric, 0 is quantile, Inf is expectile, any number between zero and infinite is M-quantile. |
Beta Numeric array, with three dimmensions: 1) tau, 2) coef., lower bound, upper bound, 3) exploratory variables.
Beta array with dimension (ntau, 3, d), where Beta[i,1,k] is the i-th tau estimation of beta_k, Beta[i,2,k] is the i-th tau lower bound 95% confidence of beta_k, and Beta[i,3,k] is the i-th tau lower bound 95% confidence of beta_k.
n = 10 m = 5 d = 4 N = n*m L = N*d x = matrix(rnorm(L), ncol=d, nrow=N) subj = rep(1:n, each=m) alpha = rnorm(n) beta = rnorm(d) eps = rnorm(N) y = as.vector(x %*% beta + rep(alpha, each=m) + eps) Beta = mpqr(x,y,subj,tau=1:9/10, effect="fixed", c = 1.2) Beta
n = 10 m = 5 d = 4 N = n*m L = N*d x = matrix(rnorm(L), ncol=d, nrow=N) subj = rep(1:n, each=m) alpha = rnorm(n) beta = rnorm(d) eps = rnorm(N) y = as.vector(x %*% beta + rep(alpha, each=m) + eps) Beta = mpqr(x,y,subj,tau=1:9/10, effect="fixed", c = 1.2) Beta
This function solves a expectile regression
optim_er(beta, x, y, tau, N, d)
optim_er(beta, x, y, tau, N, d)
beta |
Numeric vector, initials values beta. |
x |
Numeric matrix, covariates. |
y |
Numeric vector, output. |
tau |
Numeric scalar, the percentile. |
N |
Numeric integer, sample size. |
d |
Numeric integer, X number of columns. |
parametric vector and residuals.
This function solves a expectile regression with fixed effects
optim_erfe(beta, alpha, x, y, z, tau, N, d, n)
optim_erfe(beta, alpha, x, y, z, tau, N, d, n)
beta |
Numeric vector, initials values beta. |
alpha |
Numeric vector, initials values alpha. |
x |
Numeric matrix, covariates. |
y |
Numeric vector, output. |
z |
Numeric matrix, incidence matrix. |
tau |
Numeric scalar, the percentile. |
N |
Numeric integer, sample size. |
d |
Numeric integer, X number of columns. |
n |
Numeric integer, length of alpha. |
parametric vector and residuals.
This function solves a expectile regression with fixed effects and LASSO
optim_erlasso(beta, alpha, x, y, z, tau, N, d, n)
optim_erlasso(beta, alpha, x, y, z, tau, N, d, n)
beta |
Numeric vector, initials values beta. |
alpha |
Numeric vector, initials values alpha. |
x |
Numeric matrix, covariates. |
y |
Numeric vector, output. |
z |
Numeric matrix, incidence matrix. |
tau |
Numeric scalar, the percentile. |
N |
Numeric integer, sample size. |
d |
Numeric integer, X number of columns. |
n |
Numeric integer, length of alpha. |
parametric vector and residuals.
This function solves a M-quantile regression
optim_mqr(beta, x, y, tau, N, d, c)
optim_mqr(beta, x, y, tau, N, d, c)
beta |
Numeric vector, initials values beta. |
x |
Numeric matrix, covariates. |
y |
Numeric vector, output. |
tau |
Numeric scalar, the percentile. |
N |
Numeric integer, sample size. |
d |
Numeric integer, X number of columns. |
c |
Numeric, positive real value. |
parametric vector and residuals.
This function solves a quantile regression with fixed effects
optim_mqrfe(beta, alpha, x, y, z, tau, N, d, n, c)
optim_mqrfe(beta, alpha, x, y, z, tau, N, d, n, c)
beta |
Numeric vector, initials values beta. |
alpha |
Numeric vector, initials values alpha. |
x |
Numeric matrix, covariates. |
y |
Numeric vector, output. |
z |
Numeric matrix, incidence matrix. |
tau |
Numeric scalar, the percentile. |
N |
Numeric integer, sample size. |
d |
Numeric integer, X number of columns. |
n |
Numeric integer, length of alpha. |
c |
Numeric, positive real value. |
parametric vector and residuals.
This function solves a M-quantile regression with fixed effects and LASSO
optim_mqrlasso(beta, alpha, x, y, z, tau, N, d, n, c)
optim_mqrlasso(beta, alpha, x, y, z, tau, N, d, n, c)
beta |
Numeric vector, initials values beta. |
alpha |
Numeric vector, initials values alpha. |
x |
Numeric matrix, covariates. |
y |
Numeric vector, output. |
z |
Numeric matrix, incidence matrix. |
tau |
Numeric scalar, the percentile. |
N |
Numeric integer, sample size. |
d |
Numeric integer, X number of columns. |
n |
Numeric integer, length of alpha. |
c |
Numeric, positive real value. |
parametric vector and residuals.
This function solves a quantile regression
optim_qr(beta, x, y, tau, N, d)
optim_qr(beta, x, y, tau, N, d)
beta |
Numeric vector, initials values. |
x |
Numeric matrix, covariates. |
y |
Numeric vector, output. |
tau |
Numeric scalar, the percentile. |
N |
Numeric integer, sample size. |
d |
Numeric integer, X number of columns. |
parametric vector and residuals.
This function solves a quantile regression with fixed effects
optim_qrfe(beta, alpha, x, y, z, tau, N, d, n)
optim_qrfe(beta, alpha, x, y, z, tau, N, d, n)
beta |
Numeric vector, initials values beta. |
alpha |
Numeric vector, initials values alpha. |
x |
Numeric matrix, covariates. |
y |
Numeric vector, output. |
z |
Numeric matrix, incidence matrix. |
tau |
Numeric scalar, the percentile. |
N |
Numeric integer, sample size. |
d |
Numeric integer, X number of columns. |
n |
Numeric integer, length of alpha. |
parametric vector and residuals.
This function solves a quantile regression with fixed effects and LASSO
optim_qrlasso(beta, alpha, x, y, z, tau, N, d, n)
optim_qrlasso(beta, alpha, x, y, z, tau, N, d, n)
beta |
Numeric vector, initials values beta. |
alpha |
Numeric vector, initials values alpha. |
x |
Numeric matrix, covariates. |
y |
Numeric vector, output. |
z |
Numeric matrix, incidence matrix. |
tau |
Numeric scalar, the percentile. |
N |
Numeric integer, sample size. |
d |
Numeric integer, X number of columns. |
n |
Numeric integer, length of alpha. |
parametric vector and residuals.
plot penalized quantile regression for several taus
plot_taus( Beta, tau = 1:9/10, D, col = 2, lwd = 1, lty = 2, pch = 16, cex.axis = 1, cex.lab = 1, main = "", shadow = "gray90" )
plot_taus( Beta, tau = 1:9/10, D, col = 2, lwd = 1, lty = 2, pch = 16, cex.axis = 1, cex.lab = 1, main = "", shadow = "gray90" )
Beta |
Numeric array, with three dimmensions: 1) tau, 2) coef., lower bound, upper bound, 3) exploratory variables. |
tau |
Numeric vector, identifies the percentiles. |
D |
covariate's number. |
col |
color. |
lwd |
line width. |
lty |
line type. |
pch |
point character. |
cex.axis |
cex axis length. |
cex.lab |
cex axis length. |
main |
title. |
shadow |
color of the Confidence Interval 95% |
None
n = 10 m = 5 d = 4 N = n*m L = N*d x = matrix(rnorm(L), ncol=d, nrow=N) subj = rep(1:n, each=m) alpha = rnorm(n) beta = rnorm(d) eps = rnorm(N) y = as.vector(x %*% beta + rep(alpha, each=m) + eps) Beta = mpqr(x,y,subj,tau=1:9/10, effect="lasso", c = Inf) plot_taus(Beta,tau=1:9/10,D=1)
n = 10 m = 5 d = 4 N = n*m L = N*d x = matrix(rnorm(L), ncol=d, nrow=N) subj = rep(1:n, each=m) alpha = rnorm(n) beta = rnorm(d) eps = rnorm(N) y = as.vector(x %*% beta + rep(alpha, each=m) + eps) Beta = mpqr(x,y,subj,tau=1:9/10, effect="lasso", c = Inf) plot_taus(Beta,tau=1:9/10,D=1)
Estimate parameters and tuning parameter.
pqr(x, y, subj, tau = 0.5, effect = "simple", c = 1)
pqr(x, y, subj, tau = 0.5, effect = "simple", c = 1)
x |
Numeric matrix, covariates |
y |
Numeric vector, outcome. |
subj |
Numeric vector, identifies the unit to which the observation belongs. |
tau |
Numeric scalar between zero and one, identifies the percentile. |
effect |
Factor, "simple" simple regression, "fixed" regression with fixed effects, "lasso" penalized regression with fixed effects. |
c |
Numeric, 0 is quantile, Inf is expectile, any number between zero and infinite is M-quantile. |
alpha Numeric vector, intercepts' coefficients.
beta Numeric vector, exploratory variables' coefficients.
lambda Numeric, estimated lambda.
res Numeric vector, percentile residuals.
tau Numeric scalar, the percentile.
penalty Numeric scalar, indicate the chosen effect.
c Numeric scalar, indicate the chosen c.
sig2_alpha Numeric vector, intercepts' standard errors.
sig2_beta Numeric vector, exploratory variables' standard errors.
Tab_alpha Data.frame, intercepts' summary.
Tab_beta Data.frame, exploratory variables' summary.
Mat_alpha Numeric matrix, intercepts' summary.
Mat_beta Numeric matrix, exploratory variables' summary.
Koenker, R. (2004) "Quantile regression for longitudinal data", J. Multivar. Anal., 91(1): 74-89, <doi:10.1016/j.jmva.2004.05.006>
n = 10 m = 5 d = 4 N = n*m x = matrix(rnorm(d*N), ncol=d, nrow=N) subj = rep(1:n, each=m) alpha = rnorm(n) beta = rnorm(d) eps = rnorm(N) y = as.vector(x %*% beta + rep(alpha, each=m) + eps) m1 = pqr(x=x, y=y, subj=subj, tau=0.75, effect="lasso", c = 0) m1$Tab_beta
n = 10 m = 5 d = 4 N = n*m x = matrix(rnorm(d*N), ncol=d, nrow=N) subj = rep(1:n, each=m) alpha = rnorm(n) beta = rnorm(d) eps = rnorm(N) y = as.vector(x %*% beta + rep(alpha, each=m) + eps) m1 = pqr(x=x, y=y, subj=subj, tau=0.75, effect="lasso", c = 0) m1$Tab_beta
Define the visible part of the object class PQR
## S3 method for class 'PQR' print(x, ...)
## S3 method for class 'PQR' print(x, ...)
x |
An object of class "PQR" |
... |
further arguments passed to or from other methods. |
None
Psi asymetric least square
psi_als(x, tau)
psi_als(x, tau)
x |
generic vector |
tau |
percentile |
y vector, linear transformation by ALS psi
Psi M-quantile
psi_mq(x, tau, c)
psi_mq(x, tau, c)
x |
generic vector |
tau |
percentile |
c |
tuning |
y vector, linear transformation by m-rho derivative
Estimate Covariance matrix
q_cov(n, N, d, Z, X, tau, res, penalty, c)
q_cov(n, N, d, Z, X, tau, res, penalty, c)
n |
length of alpha. |
N |
sample size. |
d |
length of beta. |
Z |
Numeric matrix, incident matrix. |
X |
Numeric matrix, covariates. |
tau |
Numeric, identifies the percentile. |
res |
Numeric vector, residuals. |
penalty |
Numeric, 1 quantile regression, 2 quantile regression with fixed effects, 3 Lasso quantile regression with fixed effects |
c |
Numeric, tuning |
a list with two matrices: sig2_alpha (which is the matrix of covariance of estimated alpha) and sig2_beta (which is the matrix of covariance of estimated beta)
Rho Koenker
rho_koenker(x, tau)
rho_koenker(x, tau)
x |
generic vector |
tau |
percentile |
y vector, linear transformation by rho
Rho M-quantile
rho_mq(x, tau, c)
rho_mq(x, tau, c)
x |
generic vector |
tau |
percentile |
c |
tuning |
y vector, linear transformation by m-rho
Identify significance
sgf(x)
sgf(x)
x |
Numeric vector. |
y vector Factor, symbol flag of significant p-values.
a vector of Factors, i.e., the symbols to help p-value interpretation
n = 10 pvalue = rgamma(10,1,10) sgf(pvalue)
n = 10 pvalue = rgamma(10,1,10) sgf(pvalue)