Learn R Programming

Qtools (version 1.6.0)

midq2q.midrq: Recover Ordinary Quantiles from Mid-Quantiles

Description

This function recovers ordinary quantiles from fitted mid-quantile objects.

Usage

# S3 method for midquantile
midq2q(object, observed = FALSE, ...)
# S3 method for midrq
midq2q(object, observed = FALSE, ..., newdata, offset, na.action = na.pass)

Value

a vector or a matrix of estimated ordinary quantiles. The attribute Fhat provides the corresponding estimated cumulative distribution.

Arguments

object

an object of class midquantile or midrq.

observed

logical flag. If TRUE, ordinary quantiles are recovered from observed sample values. Otherwise, they are calcuated as rounded mid-quantiles. See details.

newdata

optionally, a data frame in which to look for variables with which to predict. If omitted, the fitted values are used.

offset

an optional offset to be included in the model frame (when newdata is provided).

na.action

function determining what should be done with missing values in newdata. The default is to predict NA.

...

not used.

Author

Marco Geraci

Details

If the values of the support of the random variable are equally spaced integers, then observed should ideally be set to FALSE so that the ordinary quantile is obtained by rounding the predicted mid-quantile. Otherwise, the function returns an integer observed in the sample. See Geraci and Farcomeni for more details.

References

Geraci, M. and A. Farcomeni. Mid-quantile regression for discrete responses. arXiv:1907.01945 [stat.ME]. URL: https://arxiv.org/abs/1907.01945.

See Also

plot.midq2q, predict.midrq

Examples

Run this code

if (FALSE) {
# Esterase data
data(esterase)

# Fit conditional mid-quantiles 0.1, 0.15, ..., 0.85
fit <- midquantile(esterase$Count, probs = 2:17/20)

# Recover ordinary quantile function
print(Qhat <- midq2q(fit))

# Plot
plot(Qhat)

# Fit conditional mid-quantiles 0.1, 0.15, ..., 0.85
fit <- midrq(Count ~ Esterase, tau = 2:17/20, data = esterase, type = 3, lambda = 0)

# Recover ordinary quantile function
xx <- seq(min(esterase$Esterase), max(esterase$Esterase), length = 5)
print(Qhat <- midq2q(fit, newdata = data.frame(Esterase = xx)))

# Plot
plot(Qhat, sub = TRUE)

}

Run the code above in your browser using DataLab