Mid-Quantile Regression for Discrete Responses
midrq.RdThis function is used to fit a mid-quantile regression model when the response is discrete.
Usage
midrq(formula, data, tau = 0.5, lambda = NULL, subset, weights, na.action,
contrasts = NULL, offset, type = 3, midFit = NULL, control = list())
midrq.fit(x, y, offset, lambda, binary, midFit, type, tau, method)Arguments
- formula
an object of class
formula: a symbolic description of the model to be fitted.- data
an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which
midrqis called.- tau
quantile to be estimated. This can be a vector of quantiles in
midrq, but must be one single quantile inmidrq.fit.- lambda
a numerical value for the transformation parameter. This is provided by the user or set to
NULL. The transformation is always Box-Cox, unless the response is binary (0-1) in which case the trasformation is Aranda-Ordaz. Seebcandao.- subset
an optional vector specifying a subset of observations to be used in the fitting process.
- weights
an optional vector of weights to be used in the fitting process.
- na.action
a function which indicates what should happen when the data contain
NAs.- contrasts
an optional list. See the
contrasts.argofmodel.matrix.default.- offset
an optional offset to be included in the model frame. This must be provided in
midrq.fit(e.g., a vector of zeros).- type
estimation method for the fitting process. See details.
- midFit
cmidecdfobject used for fitting conditional mid-quantiles. If set toNULLinmidrq, it is automatically created. It must be provided inmidrq.fit.- control
list of control parameters of the fitting process. See
midrqControl.- x
design matrix of dimension \(n * p\).
- y
vector of observations of length \(n\).
- binary
logical flag. Is the response binary?
- method
character vector that specifies the optimization algorithm in
optimto fit a conditional mid-quantile model whentype = 1ortype = 2. Only"Nelder-Mead"has been tested.
Details
A linear mid-quantile regression model is fitted to the transformed response. The transformation of the response can be changed with the argument lambda. If lambda = NULL, then no transformation is applied (i.e., identity); if lambda is a numeric value, then the Box-Cox transformation is applied (e.g., 0 for log-transformation). However, midrq will automatically detect whether the response is binary, in which case the Aranda-Ordaz transformation is applied. In contrast, the user must declare whether the response is binary in midrq.fit.
There are 3 different estimators. type = 1 is based on a general-purpose estimator (i.e., optim). type = 2 is similar to type = 1, except the loss function is averaged over the space of the predictors (i.e., CUSUM). type = 3 is the least-squares estimator discussed by Geraci and Farcomeni (2019).
The warning `tau is outside mid-probabilities range' indicates that there are observations for which tau is below or above the range of the corresponding estimated conditional mid-probabilities. This affects estimation in a way similar to censoring.
Value
a list of class midrq containing the following components
- call
the matched call.
- x
the model matrix.
- y
the model response.
- hy
the tranformed model response.
- tau
the order of the estimated quantile(s).
- coefficients
regression quantile (on the log–scale).
- fitted.values
fitted values (on the response scale).
- offset
offset.
- terms
the terms object used.
- term.labels
names of coefficients.
References
Geraci, M. and A. Farcomeni. Mid-quantile regression for discrete responses. arXiv:1907.01945 [stat.ME]. URL: https://arxiv.org/abs/1907.01945.
Examples
if (FALSE) { # \dontrun{
# Esterase data
data(esterase)
# Fit quantiles 0.25 and 0.75
fit <- midrq(Count ~ Esterase, tau = c(0.25, 0.75), data = esterase, type = 3, lambda = 0)
coef(fit)
# Plot
with(esterase, plot(Count ~ Esterase))
lines(esterase$Esterase, fit$fitted.values[,1], col = "blue")
lines(esterase$Esterase, fit$fitted.values[,2], col = "red")
legend(8, 1000, lty = c(1,1), col = c("blue", "red"), legend = c("tau = 0.25","tau = 0.75"))
} # }