This function is used to fit a mid-quantile regression model when the response is discrete.
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)
a list of class midrq
containing the following components
the matched call.
the model matrix.
the model response.
the tranformed model response.
the order of the estimated quantile(s).
regression quantile (on the log--scale).
fitted values (on the response scale).
offset.
the terms object used.
names of coefficients.
an object of class formula
: a symbolic description of the model to be fitted.
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 midrq
is called.
quantile to be estimated. This can be a vector of quantiles in midrq
, but must be one single quantile in midrq.fit
.
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. See bc
and ao
.
an optional vector specifying a subset of observations to be used in the fitting process.
an optional vector of weights to be used in the fitting process.
a function which indicates what should happen when the data contain NA
s.
an optional list. See the contrasts.arg
of model.matrix.default
.
an optional offset to be included in the model frame. This must be provided in midrq.fit
(e.g., a vector of zeros).
estimation method for the fitting process. See details.
cmidecdf
object used for fitting conditional mid-quantiles. If set to NULL
in midrq
, it is automatically created. It must be provided in midrq.fit
.
list of control parameters of the fitting process. See midrqControl
.
design matrix of dimension \(n * p\).
vector of observations of length \(n\).
logical flag. Is the response binary?
character vector that specifies the optimization algorithm in optim
to fit a conditional mid-quantile model when type = 1
or type = 2
. Only "Nelder-Mead"
has been tested.
Marco Geraci with contributions from Alessio Farcomeni
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.
Geraci, M. and A. Farcomeni. Mid-quantile regression for discrete responses. arXiv:1907.01945 [stat.ME]. URL: https://arxiv.org/abs/1907.01945.
residuals.midrq
, predict.midrq
, coef.midrq
if (FALSE) {
# 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"))
}
Run the code above in your browser using DataLab