midrq | R Documentation |
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)
formula |
an object of class |
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 |
tau |
quantile to be estimated. This can be a vector of quantiles in |
lambda |
a numerical value for the transformation parameter. This is provided by the user or set to |
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 |
contrasts |
an optional list. See the |
offset |
an optional offset to be included in the model frame. This must be provided in |
type |
estimation method for the fitting process. See details. |
midFit |
|
control |
list of control parameters of the fitting process. See |
x |
design matrix of dimension |
y |
vector of observations of length |
binary |
logical flag. Is the response binary? |
method |
character vector that specifies the optimization algorithm in |
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.
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. |
Marco Geraci with contributions from Alessio Farcomeni
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
## Not run:
# 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"))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.