| Title: | Quantile-Based Estimators |
|---|---|
| Description: | Quantile-based estimators (Q-estimators) fit any parametric distribution through its quantile function, by minimizing the integrated loss of quantile regression. They are usually more robust than maximum likelihood estimators, and allow for censored and truncated data. The package implements user-defined quantile functions, built-in families (normal, gamma, continuous Poisson, uniform), linear models and proportional hazards models. The method is described in Sottile and Frumento (2022) <doi:10.1016/j.csda.2022.107471>. |
| Authors: | Gianluca Sottile [aut, cre] (ORCID: <https://orcid.org/0000-0001-9347-7251>), Paolo Frumento [aut] |
| Maintainer: | Gianluca Sottile <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 2.0.0 |
| Built: | 2026-10-18 11:30:18 UTC |
| Source: | https://github.com/gianluca-sottile/qest |
Baseline Cumulative Hazard of a Qcoxph Model
basehaz.Qcoxph(fit, centered = TRUE, se.fit = FALSE, times)basehaz.Qcoxph(fit, centered = TRUE, se.fit = FALSE, times)
fit |
an object of class |
centered |
logical: if |
se.fit |
logical: compute the variance of the estimates (delta method)? |
times |
the times at which |
The baseline cumulative hazard of the fitted model is piecewise
linear, . Unlike
survival::basehaz(), this is not a step function.
A data frame with columns hazard (the cumulative hazard), time
and, if se.fit = TRUE, varhaz.
library(survival) set.seed(1) x <- runif(200) t <- rexp(200, exp(x)) cens <- runif(200, 0, 3) fit <- Qcoxph(Surv(pmin(t, cens), t <= cens) ~ x) head(basehaz.Qcoxph(fit, se.fit = TRUE))library(survival) set.seed(1) x <- runif(200) t <- rexp(200, exp(x)) cens <- runif(200, 0, 3) fit <- Qcoxph(Surv(pmin(t, cens), t <= cens) ~ x) head(basehaz.Qcoxph(fit, se.fit = TRUE))
Given a quantile function and a value of
, computes by bisection.
invQ(Q, theta, y, data, n.it = 17)invQ(Q, theta, y, data, n.it = 17)
Q |
a quantile function |
theta |
the parameters. |
y |
the response: one value for each row of |
data |
a data frame. |
n.it |
the number of iterations of the bisection algorithm (the accuracy
is |
A vector with .
Qlinmod <- function(theta, tau, data) { qnorm(tau, theta[2] + theta[3] * data$x, exp(theta[1])) } set.seed(1) dat <- data.frame(x = runif(10)) U <- runif(10) y <- Qlinmod(c(0, 1, 2), U, dat) cbind(U, invQ(Qlinmod, c(0, 1, 2), y, dat))Qlinmod <- function(theta, tau, data) { qnorm(tau, theta[2] + theta[3] * data$x, exp(theta[1])) } set.seed(1) dat <- data.frame(x = runif(10)) U <- runif(10) y <- Qlinmod(c(0, 1, 2), U, dat) cbind(U, invQ(Qlinmod, c(0, 1, 2), y, dat))
If the model is correctly specified, are a sample from
a distribution. The plot compares their empirical distribution
(the Kaplan-Meier estimator, with censored or truncated data) with the
uniform distribution function.
## S3 method for class 'Qest' plot(x, conf.int = TRUE, ...)## S3 method for class 'Qest' plot(x, conf.int = TRUE, ...)
x |
an object of class |
conf.int |
logical: add pointwise 95% confidence bands (Greenwood)? |
... |
additional graphical parameters passed to |
Invisibly, a data frame with the Kaplan-Meier estimate of the
distribution of .
set.seed(1) y <- rgamma(300, shape = 2, scale = 3) plot(Qest(y ~ 1, Q = Qgamma)) # good fit plot(Qest(y ~ 1, Q = Qnorm)) # poor fitset.seed(1) y <- rgamma(300, shape = 2, scale = 3) plot(Qest(y ~ 1, Q = Qgamma)) # good fit plot(Qest(y ~ 1, Q = Qnorm)) # poor fit
Predictions from a Qcoxph Model
## S3 method for class 'Qcoxph' predict( object, newdata, type = c("lp", "risk", "expected", "survival", "quantile"), se.fit = FALSE, p = c(0.25, 0.5, 0.75), ... )## S3 method for class 'Qcoxph' predict( object, newdata, type = c("lp", "risk", "expected", "survival", "quantile"), se.fit = FALSE, p = c(0.25, 0.5, 0.75), ... )
object |
an object of class |
newdata |
an optional data frame. For |
type |
the type of prediction: the linear predictor ( |
se.fit |
logical: compute standard errors (delta method)? Not available
for |
p |
the quantile orders for |
... |
not used. |
A vector, or a list with items fit and se.fit; for
type = "quantile", a matrix with one column for each value of p.
library(survival) set.seed(1) dat <- data.frame(x = runif(200)) t <- rexp(200, exp(dat$x)); cens <- runif(200, 0, 3) dat$y <- pmin(t, cens); dat$d <- as.numeric(t <= cens) fit <- Qcoxph(Surv(y, d) ~ x, data = dat) predict(fit, newdata = data.frame(x = c(0, 0.5, 1)), type = "risk", se.fit = TRUE) predict(fit, newdata = data.frame(x = c(0, 1)), type = "quantile", p = c(0.25, 0.5))library(survival) set.seed(1) dat <- data.frame(x = runif(200)) t <- rexp(200, exp(dat$x)); cens <- runif(200, 0, 3) dat$y <- pmin(t, cens); dat$d <- as.numeric(t <= cens) fit <- Qcoxph(Surv(y, d) ~ x, data = dat) predict(fit, newdata = data.frame(x = c(0, 0.5, 1)), type = "risk", se.fit = TRUE) predict(fit, newdata = data.frame(x = c(0, 1)), type = "quantile", p = c(0.25, 0.5))
Computes the fitted quantiles , or the fitted distribution
function at the observed (or new) values of the response.
## S3 method for class 'Qest' predict( object, newdata, type = c("quantile", "CDF"), p = c(0.1, 0.25, 0.5, 0.75, 0.9), ... )## S3 method for class 'Qest' predict( object, newdata, type = c("quantile", "CDF"), p = c(0.1, 0.25, 0.5, 0.75, 0.9), ... )
object |
an object of class |
newdata |
an optional data frame. For |
type |
|
p |
the quantile orders for |
... |
additional arguments of a user-defined |
For a user-defined Q, newdata is passed as the argument data
of Q. For type = "CDF", is computed by inverting
(see invQ()). For censored data, the CDF is evaluated at the
observed times.
For type = "quantile", a matrix with one row for each observation
and one column for each value of p; for type = "CDF", a vector.
set.seed(1) dat <- data.frame(x = runif(200)) dat$y <- rgamma(200, shape = 2, scale = exp(1 + dat$x)) fit <- Qest(y ~ x, Q = Qgamma, data = dat) predict(fit, newdata = data.frame(x = c(0, 1)), p = c(0.1, 0.5, 0.9)) head(predict(fit, type = "CDF"))set.seed(1) dat <- data.frame(x = runif(200)) dat$y <- rgamma(200, shape = 2, scale = exp(1 + dat$x)) fit <- Qest(y ~ x, Q = Qgamma, data = dat) predict(fit, newdata = data.frame(x = c(0, 1)), p = c(0.1, 0.5, 0.9)) head(predict(fit, type = "CDF"))
Predictions from Qlm Models
## S3 method for class 'Qlm' predict( object, newdata, type = c("response", "quantile"), se.fit = FALSE, p = c(0.1, 0.25, 0.5, 0.75, 0.9), na.action = stats::na.pass, ... )## S3 method for class 'Qlm' predict( object, newdata, type = c("response", "quantile"), se.fit = FALSE, p = c(0.1, 0.25, 0.5, 0.75, 0.9), na.action = stats::na.pass, ... )
object |
an object of class |
newdata |
an optional data frame. |
type |
|
se.fit |
logical: return the standard errors of the fitted mean? |
p |
the quantile orders for |
na.action |
how to treat missing values in |
... |
not used. |
A vector, a list with items fit and se.fit, or (for
type = "quantile") a matrix with one column for each value of p.
set.seed(1) x <- runif(100) y <- 1 + 2 * x + rnorm(100) fit <- Qlm(y ~ x) predict(fit, newdata = data.frame(x = c(0, 0.5)), se.fit = TRUE) predict(fit, newdata = data.frame(x = c(0, 0.5)), type = "quantile", p = c(0.1, 0.9))set.seed(1) x <- runif(100) y <- 1 + 2 * x + rnorm(100) fit <- Qlm(y ~ x) predict(fit, newdata = data.frame(x = c(0, 0.5)), se.fit = TRUE) predict(fit, newdata = data.frame(x = c(0, 0.5)), type = "quantile", p = c(0.1, 0.9))
Fits a proportional hazards model with the Q-estimator of Sottile and
Frumento (2022). The baseline cumulative hazard is piecewise
linear, so that the model is fully parametric, and
.
Qcoxph( formula, weights, start, data, subset, na.action, knots, wtau = NULL, control = Qcoxph.control(), ... )Qcoxph( formula, weights, start, data, subset, na.action, knots, wtau = NULL, control = Qcoxph.control(), ... )
formula |
a formula with a |
weights |
an optional vector of non-negative (sampling) weights. |
start |
optional starting values for the regression coefficients
|
data |
an optional data frame. |
subset, na.action
|
as in |
knots |
the knots of |
wtau |
an optional weighting function |
control |
a list created by |
... |
additional arguments of |
The model is , with
, where is a piecewise
linear basis. All quantities of the estimating equations have closed forms
(Appendix D2 of the paper). The coefficients have the same interpretation
as in survival::coxph(); the estimates are typically very close, but more
robust. Starting points are obtained from the partial likelihood and the
Breslow estimator of .
Methods are available to compute the fitted survival curves (survfit.Qcoxph(),
which returns an object of class "survfit"), predictions
(predict.Qcoxph()), residuals (residuals.Qcoxph()) and the baseline
cumulative hazard (basehaz.Qcoxph()). All of them are based on the fitted
parametric model.
An object of class c("Qcoxph", "Qest"), a list with items
coefficients, var
|
the estimated |
obj.function |
the loss at the solution. |
iter, converged
|
number of iterations and convergence. |
linear.predictors |
|
residuals |
martingale residuals. |
means, n, nevent
|
means of the covariates, number of observations and of events. |
concordance |
Harrell's concordance index (from |
internal |
the knots, the coefficients |
and terms, assign, formula, call, y, x, model, xlevels,
na.action.
Sottile, G. and Frumento, P. (2022). Robust estimation and regression with parametric quantile functions. Computational Statistics and Data Analysis, 171, 107471. doi:10.1016/j.csda.2022.107471
survfit.Qcoxph(), predict.Qcoxph(), residuals.Qcoxph(),
basehaz.Qcoxph(), Qest()
library(survival) set.seed(1) n <- 200 x <- runif(n, 0, 3) t <- rweibull(n, shape = 2, scale = (1 / exp(2 + 2 * x))^(1 / 2)) cens <- runif(n, 0, 1) dat <- data.frame(y = pmin(t, cens), d = as.numeric(t <= cens), x = x) m1 <- coxph(Surv(y, d) ~ x, data = dat) m2 <- Qcoxph(Surv(y, d) ~ x, data = dat) summary(m2) cbind(coxph = coef(m1), Qcoxph = coef(m2)) sf <- survfit(m2, newdata = data.frame(x = c(0.5, 1.5))) plot(sf, col = 1:2)library(survival) set.seed(1) n <- 200 x <- runif(n, 0, 3) t <- rweibull(n, shape = 2, scale = (1 / exp(2 + 2 * x))^(1 / 2)) cens <- runif(n, 0, 1) dat <- data.frame(y = pmin(t, cens), d = as.numeric(t <= cens), x = x) m1 <- coxph(Surv(y, d) ~ x, data = dat) m2 <- Qcoxph(Surv(y, d) ~ x, data = dat) summary(m2) cbind(coxph = coef(m1), Qcoxph = coef(m2)) sf <- survfit(m2, newdata = data.frame(x = c(0.5, 1.5))) plot(sf, col = 1:2)
Fits a parametric model by minimizing the integrated loss of quantile
regression (Sottile and Frumento, 2022). The model is specified through its
quantile function , either written by the user
or chosen among the built-in families (see Qfamily). Censored and
truncated data are allowed.
Qest( formula, Q, weights, start, data, subset, na.action, ntau = 199, wtau = NULL, control = Qest.control(), ... )Qest( formula, Q, weights, start, data, subset, na.action, ntau = 199, wtau = NULL, control = Qest.control(), ... )
formula |
a two-sided formula of the form |
Q |
a quantile function |
weights |
an optional vector of non-negative weights. They are treated as sampling weights: the (sandwich) standard errors do not depend on their scale. |
start |
the starting points. With a user-defined |
data |
an optional data frame containing the variables in the model. It
is also the argument |
subset, na.action
|
as in |
ntau |
the number of points of the grid of quantile orders used for numerical integration (default 199). |
wtau |
an optional weighting function |
control |
a list of operational parameters created by |
... |
additional named arguments of |
The Q-estimator minimizes
where . It is consistent and
asymptotically normal, and its robustness can be tuned by choosing
(Sottile and Frumento, 2022). For censored and truncated data,
the estimating equations of Appendix A of the paper are solved.
User-defined quantile functions. Q(theta, tau, data) must have these
three arguments, in this order (other arguments can follow and are passed
through ...), and must return, for each row of data,
. The argument tau is either a matrix with
one row for each row of data (then Q returns a matrix of the same size),
or a vector with one value for each row of data (then Q returns a
vector). data is the data frame used to fit the model (after removing
missing values, subset and observations with zero weight). Q must be
increasing in tau and twice differentiable in theta; it is evaluated on a grid of ntau quantile orders in
, and its derivatives with respect
to theta are computed by central differences.
Starting points. If start contains NA (or control$restart = TRUE),
a nonparametric estimate is obtained from a
piecewise-constant hazard model that uses the covariates in formula, and the
starting points minimize
(Sottile and Frumento, 2022, Algorithm 1), searched from the values in start
(with NA replaced by zero): with poorly scaled data, rough starting values for
all parameters are recommended.
Algorithm. The estimating equations are solved by Newton-Raphson with backtracking, switching to Levenberg-Marquardt steps when the Newton step fails. The Jacobian is the exact derivative of the discretized estimating equations. Standard errors are computed with the sandwich formula.
An object of class "Qest", a list with items
coefficients |
the estimated parameters. |
std.errs |
their standard errors. |
covar |
the estimated covariance matrix. |
obj.function |
the value of the loss at the solution (for censored or truncated data, the loss of Appendix A, which is not the function whose gradient is solved). |
ee, jacobian
|
the estimating equations (divided by the sample size) and their Jacobian at the solution. |
CDF, PDF
|
the fitted |
converged, n.it
|
convergence of the algorithm and number of iterations. |
internal |
quantities used by the methods. |
and the usual call, formula, terms, data, na.action, xlevels,
contrasts, control.
Sottile, G. and Frumento, P. (2022). Robust estimation and regression with parametric quantile functions. Computational Statistics and Data Analysis, 171, 107471. doi:10.1016/j.csda.2022.107471
Qfamily, Qlm(), Qcoxph(), summary.Qest(), wtrunc(),
invQ().
# Normal linear model Qlinmod <- function(theta, tau, data) { X <- model.matrix(~ x1 + x2, data = data) qnorm(tau, c(X %*% theta[-1]), exp(theta[1])) } set.seed(1) n <- 100 dat <- data.frame(x1 = rnorm(n), x2 = runif(n, 0, 3)) dat$y <- 4 + dat$x1 + 2 * dat$x2 + rnorm(n) m1 <- Qest(y ~ x1 + x2, Q = Qlinmod, start = rep(NA, 4), data = dat) m2 <- Qest(y ~ x1 + x2, Q = Qnorm, data = dat) # the same model, as a Qfamily m3 <- Qlm(y ~ x1 + x2, data = dat) # ... or with Qlm (fastest) summary(m1) cbind(user = coef(m1), family = coef(m2)) # A Weibull proportional hazards model with censored data QWeibPH <- function(theta, tau, data) { shape <- exp(theta[1]) X <- model.matrix(~ x, data = data) qweibull(tau, shape = shape, scale = exp(-c(X %*% theta[-1]) / shape)) } dat <- data.frame(x = runif(n, 0, 3)) t <- QWeibPH(c(log(2), -0.5, 1), runif(n), dat) cens <- runif(n, 0, 2) dat$y <- pmin(t, cens); dat$d <- as.numeric(t <= cens) m4 <- Qest(survival::Surv(y, d) ~ x, Q = QWeibPH, start = rep(NA, 3), data = dat) summary(m4) # Gamma model with more weight around the median y <- rgamma(n, shape = 3, scale = 2) m5 <- Qest(y ~ 1, Q = Qgamma, wtau = function(tau, h) dnorm((tau - 0.5) / h), h = 0.2) coef(m5)# Normal linear model Qlinmod <- function(theta, tau, data) { X <- model.matrix(~ x1 + x2, data = data) qnorm(tau, c(X %*% theta[-1]), exp(theta[1])) } set.seed(1) n <- 100 dat <- data.frame(x1 = rnorm(n), x2 = runif(n, 0, 3)) dat$y <- 4 + dat$x1 + 2 * dat$x2 + rnorm(n) m1 <- Qest(y ~ x1 + x2, Q = Qlinmod, start = rep(NA, 4), data = dat) m2 <- Qest(y ~ x1 + x2, Q = Qnorm, data = dat) # the same model, as a Qfamily m3 <- Qlm(y ~ x1 + x2, data = dat) # ... or with Qlm (fastest) summary(m1) cbind(user = coef(m1), family = coef(m2)) # A Weibull proportional hazards model with censored data QWeibPH <- function(theta, tau, data) { shape <- exp(theta[1]) X <- model.matrix(~ x, data = data) qweibull(tau, shape = shape, scale = exp(-c(X %*% theta[-1]) / shape)) } dat <- data.frame(x = runif(n, 0, 3)) t <- QWeibPH(c(log(2), -0.5, 1), runif(n), dat) cens <- runif(n, 0, 2) dat$y <- pmin(t, cens); dat$d <- as.numeric(t <= cens) m4 <- Qest(survival::Surv(y, d) ~ x, Q = QWeibPH, start = rep(NA, 3), data = dat) summary(m4) # Gamma model with more weight around the median y <- rgamma(n, shape = 3, scale = 2) m5 <- Qest(y ~ 1, Q = Qgamma, wtau = function(tau, h) dnorm((tau - 0.5) / h), h = 0.2) coef(m5)
Control Parameters of Qest, Qlm and Qcoxph
Qest.control( tol = 1e-08, maxit = NULL, display = FALSE, restart = FALSE, deriv.step = 1e-04, ... ) Qcoxph.control(tol = 1e-08, maxit = NULL, display = FALSE, ...)Qest.control( tol = 1e-08, maxit = NULL, display = FALSE, restart = FALSE, deriv.step = 1e-04, ... ) Qcoxph.control(tol = 1e-08, maxit = NULL, display = FALSE, ...)
tol |
convergence tolerance on the norm of the estimating equations (divided by the sample size). |
maxit |
maximum number of iterations (default |
display |
logical: print the iterations? |
restart |
logical: if |
deriv.step |
relative step of the central differences used for the
derivatives of a user-defined |
... |
arguments of 'Qest' 1.0.x that were removed ( |
A list with the control parameters.
Qest.control(tol = 1e-10, display = TRUE)Qest.control(tol = 1e-10, display = TRUE)
Built-in parametric models for Qest(), with analytical (or nearly
analytical) estimating equations: much faster and more accurate than the
equivalent user-defined quantile functions.
Qgamma() Qnorm() Qpois(offset = NULL) Qunif(min = TRUE)Qgamma() Qnorm() Qpois(offset = NULL) Qunif(min = TRUE)
offset |
an optional vector of offsets of the log-rate ( |
min |
logical ( |
A family can be passed to Qest() by name ("Qpois"), as a function
(Qpois) or as a call (Qpois()); the latter allows to pass arguments.
Qnorm: normal homoskedastic model, ;
parameters log(sigma), beta. With complete data, Qlm() fits the
same model with a richer output.
Qgamma: Gamma model with shape and log-scale ;
parameters log(shape), beta.
Qpois: Poisson model with log-rate . To obtain a continuous
quantile function, qpois is replaced by the inverse with respect to
of the regularized upper incomplete gamma function
(Ilienko, 2013). The model should be applied to a jittered response,
y + runif(n).
Qunif: Uniform model with and
, or if min = FALSE.
Qnorm and Qgamma can be used with censored and truncated data; Qpois
and Qunif cannot. Qgamma and Qpois require an intercept.
An object of class "Qfamily".
Ilienko, A. (2013). Continuous counterparts of Poisson and binomial distributions and their properties. Annales Univ. Sci. Budapest., Sect. Comp., 39, 137-147.
Sottile, G. and Frumento, P. (2022). Robust estimation and regression with parametric quantile functions. Computational Statistics and Data Analysis, 171, 107471. doi:10.1016/j.csda.2022.107471
set.seed(1) n <- 250 x <- runif(n) eta <- 1 + 2 * x m1 <- Qest(y ~ x, Qnorm, data = data.frame(y = rnorm(n, eta, exp(1)), x = x)) m2 <- Qest(y ~ x, Qgamma, data = data.frame(y = rgamma(n, shape = exp(1), scale = exp(eta)), x = x)) m3 <- Qest(y ~ x, Qpois, data = data.frame(y = rpois(n, exp(eta)) + runif(n), x = x)) m4 <- Qest(y ~ x, Qunif(min = TRUE), data = data.frame(y = runif(n, 0, eta), x = x)) m5 <- Qest(y ~ x, Qunif(min = FALSE), data = data.frame(y = runif(n, 0, eta), x = x)) coef(m2)set.seed(1) n <- 250 x <- runif(n) eta <- 1 + 2 * x m1 <- Qest(y ~ x, Qnorm, data = data.frame(y = rnorm(n, eta, exp(1)), x = x)) m2 <- Qest(y ~ x, Qgamma, data = data.frame(y = rgamma(n, shape = exp(1), scale = exp(eta)), x = x)) m3 <- Qest(y ~ x, Qpois, data = data.frame(y = rpois(n, exp(eta)) + runif(n), x = x)) m4 <- Qest(y ~ x, Qunif(min = TRUE), data = data.frame(y = runif(n, 0, eta), x = x)) m5 <- Qest(y ~ x, Qunif(min = FALSE), data = data.frame(y = runif(n, 0, eta), x = x)) coef(m2)
Fits a linear model with normal homoskedastic errors,
, with the
Q-estimator of Sottile and Frumento (2022). The estimating equations and the
Hessian have closed forms (Appendix D1 of the paper), and the estimator is
fast and robust to outliers in the response.
Qlm( formula, data, subset, weights, na.action, start = NULL, contrasts = NULL, wtau = NULL, control = Qest.control(), ... ) Qlm.fit( y, X, w = rep(1, nobs), start = NULL, wtau = NULL, control = Qest.control(), ... )Qlm( formula, data, subset, weights, na.action, start = NULL, contrasts = NULL, wtau = NULL, control = Qest.control(), ... ) Qlm.fit( y, X, w = rep(1, nobs), start = NULL, wtau = NULL, control = Qest.control(), ... )
formula, data, subset, na.action, contrasts
|
as in |
weights |
an optional vector of non-negative (sampling) weights; the standard errors do not depend on their scale. |
start |
optional starting values for the regression coefficients
(excluding |
wtau |
an optional weighting function |
control |
a list created by |
... |
additional arguments of |
y, X, w
|
for |
Qlm(formula) estimates the same model as Qest(formula, Q = Qnorm), with
a much richer output. Censored and truncated data are not allowed (use
Qest() with Q = Qnorm). Standard errors are computed with the sandwich
formula, and the tests in summary.Qlm() are based on the asymptotic normal
distribution.
Qlm returns an object of class c("Qlm", "Qest") with items
coefficients, std.errs, covar
|
the estimated regression coefficients, their standard errors and covariance matrix. |
dispersion |
the estimated |
sigma |
the estimated |
residuals, fitted.values
|
residuals and fitted values. |
CDF |
the fitted |
obj.function |
the minimized loss. |
gradient, hessian
|
the estimating equations and the Hessian of the loss
at the solution (including |
covar.full |
the covariance matrix of |
and rank, df.residual, weights, converged, n.it, call, terms,
model, xlevels, contrasts, na.action. Qlm.fit returns a similar list.
Sottile, G. and Frumento, P. (2022). Robust estimation and regression with parametric quantile functions. Computational Statistics and Data Analysis, 171, 107471. doi:10.1016/j.csda.2022.107471
summary.Qlm(), predict.Qlm(), Qest()
set.seed(1234) n <- 100 x1 <- rnorm(n) x2 <- runif(n, 0, 3) y <- rnorm(n, 4 + x1 + 2 * x2, 1) y[1:5] <- y[1:5] + 20 # outliers m1 <- Qlm(y ~ x1 + x2) summary(m1) m2 <- Qlm(y ~ x1 + x2, wtau = wtrunc, delta.left = 0.05, delta.right = 0.05) cbind(lm = coef(lm(y ~ x1 + x2)), Qlm = coef(m1), Qlm.trunc = coef(m2))set.seed(1234) n <- 100 x1 <- rnorm(n) x2 <- runif(n, 0, 3) y <- rnorm(n, 4 + x1 + 2 * x2, 1) y[1:5] <- y[1:5] + 20 # outliers m1 <- Qlm(y ~ x1 + x2) summary(m1) m2 <- Qlm(y ~ x1 + x2, wtau = wtrunc, delta.left = 0.05, delta.right = 0.05) cbind(lm = coef(lm(y ~ x1 + x2)), Qlm = coef(m1), Qlm.trunc = coef(m2))
Residuals of a Qcoxph Model
## S3 method for class 'Qcoxph' residuals(object, type = c("martingale", "deviance"), ...)## S3 method for class 'Qcoxph' residuals(object, type = c("martingale", "deviance"), ...)
object |
an object of class |
type |
|
... |
not used. |
A vector of residuals.
Summarizing Qcoxph Fits
## S3 method for class 'Qcoxph' summary(object, conf.int = 0.95, scale = 1, ...) ## S3 method for class 'summary.Qcoxph' print( x, digits = max(getOption("digits") - 3, 3), signif.stars = getOption("show.signif.stars"), ... )## S3 method for class 'Qcoxph' summary(object, conf.int = 0.95, scale = 1, ...) ## S3 method for class 'summary.Qcoxph' print( x, digits = max(getOption("digits") - 3, 3), signif.stars = getOption("show.signif.stars"), ... )
object |
an object of class |
conf.int |
the level of the confidence intervals for the hazard ratios. |
scale |
a vector of scale factors for the coefficients. |
... |
not used. |
x |
an object of class |
digits, signif.stars
|
printing options. |
An object of class "summary.Qcoxph", with the table of
coefficients (coefficients), the confidence intervals of the hazard ratios
(conf.int), the concordance index and its standard error (concordance),
and the loss (obj.function).
Summary methods for objects of class "Qest" (fitted by Qest()) and
"Qlm" (fitted by Qlm()).
## S3 method for class 'Qest' summary(object, covar = FALSE, ...) ## S3 method for class 'summary.Qest' print( x, digits = max(3L, getOption("digits") - 3L), signif.stars = getOption("show.signif.stars"), ... ) ## S3 method for class 'Qlm' summary(object, correlation = FALSE, ...) ## S3 method for class 'summary.Qlm' print( x, digits = max(3L, getOption("digits") - 3L), signif.stars = getOption("show.signif.stars"), ... )## S3 method for class 'Qest' summary(object, covar = FALSE, ...) ## S3 method for class 'summary.Qest' print( x, digits = max(3L, getOption("digits") - 3L), signif.stars = getOption("show.signif.stars"), ... ) ## S3 method for class 'Qlm' summary(object, correlation = FALSE, ...) ## S3 method for class 'summary.Qlm' print( x, digits = max(3L, getOption("digits") - 3L), signif.stars = getOption("show.signif.stars"), ... )
object |
an object of class |
covar |
logical: include the covariance matrix? |
... |
not used. |
x |
a summary object. |
digits, signif.stars
|
printing options. |
correlation |
logical: include the correlation matrix of the
coefficients ( |
The tests are based on the asymptotic normal distribution of the estimators, with standard errors from the sandwich formula (Sottile and Frumento, 2022).
summary.Qest returns an object of class "summary.Qest" with the
table of coefficients (coefficients), the loss (obj.function), the
numbers of observations and parameters, the convergence status and,
optionally, the covariance matrix. summary.Qlm returns an object of class
"summary.Qlm" with the table of coefficients, the estimate of
and its standard error, the residuals and, optionally, the
correlation matrix.
set.seed(1) y <- rgamma(200, shape = 3, scale = 2) fit <- Qest(y ~ 1, Q = Qgamma) summary(fit, covar = TRUE)set.seed(1) y <- rgamma(200, shape = 3, scale = 2) fit <- Qest(y ~ 1, Q = Qgamma) summary(fit, covar = TRUE)
Computes the survival curves
of the fitted model, with pointwise confidence intervals based on the
delta method.
## S3 method for class 'Qcoxph' survfit( formula, newdata, se.fit = TRUE, conf.int = 0.95, conf.type = c("log", "log-log", "plain", "none"), times, ... )## S3 method for class 'Qcoxph' survfit( formula, newdata, se.fit = TRUE, conf.int = 0.95, conf.type = c("log", "log-log", "plain", "none"), times, ... )
formula |
an object of class |
newdata |
a data frame with the covariates of the curves. By default, one curve at the mean of the covariates. |
se.fit |
logical: compute the standard errors? |
conf.int |
the level of the confidence intervals. |
conf.type |
the transformation used for the confidence intervals:
|
times |
the times (by default, the observed times). |
... |
not used. |
An object of class "survfit" (see survival::survfit.object): the
methods print, plot, lines and summary of 'survival' can be used.
library(survival) set.seed(1) dat <- data.frame(x = runif(200)) t <- rexp(200, exp(dat$x)); cens <- runif(200, 0, 3) dat$y <- pmin(t, cens); dat$d <- as.numeric(t <= cens) fit <- Qcoxph(Surv(y, d) ~ x, data = dat) sf <- survfit(fit, newdata = data.frame(x = c(0, 1))) plot(sf, col = 1:2, conf.int = TRUE)library(survival) set.seed(1) dat <- data.frame(x = runif(200)) t <- rexp(200, exp(dat$x)); cens <- runif(200, 0, 3) dat$y <- pmin(t, cens); dat$d <- as.numeric(t <= cens) fit <- Qcoxph(Surv(y, d) ~ x, data = dat) sf <- survfit(fit, newdata = data.frame(x = c(0, 1))) plot(sf, col = 1:2, conf.int = TRUE)
A weighting function that assigns zero weight to the quantiles
below delta.left and above 1 - delta.right, to be used as the argument
wtau of Qest(), Qlm() and Qcoxph(). Truncated weights make the
estimators more robust to outliers (Sottile and Frumento, 2022, Section 3).
wtrunc( tau, delta.left = 0.05, delta.right = 0.05, smooth = FALSE, sigma = 0.01 )wtrunc( tau, delta.left = 0.05, delta.right = 0.05, smooth = FALSE, sigma = 0.01 )
tau |
a vector of quantile orders in |
delta.left, delta.right
|
the proportions of quantiles with zero weight in the left and right tail. |
smooth |
logical: if |
sigma |
the scale of the smooth version (only used if |
With smooth = FALSE, .
With smooth = TRUE, the indicators are replaced by
and .
A delta equal to zero means no truncation on that side. The arguments
delta.left, delta.right, smooth and sigma are passed through the
... of the fitting functions.
A vector of weights of the same length as tau.
Sottile, G. and Frumento, P. (2022). Robust estimation and regression with parametric quantile functions. Computational Statistics and Data Analysis, 171, 107471. doi:10.1016/j.csda.2022.107471
taus <- seq(0, 1, length.out = 1000) plot(taus, wtrunc(taus, delta.left = 0.05, delta.right = 0.1), type = "l") lines(taus, wtrunc(taus, 0.05, 0.1, smooth = TRUE, sigma = 0.01), col = 2) # in a model set.seed(1) y <- c(rnorm(95), rnorm(5, 10)) # 5% of outliers fit <- Qlm(y ~ 1, wtau = wtrunc, delta.left = 0.05, delta.right = 0.05) coef(fit)taus <- seq(0, 1, length.out = 1000) plot(taus, wtrunc(taus, delta.left = 0.05, delta.right = 0.1), type = "l") lines(taus, wtrunc(taus, 0.05, 0.1, smooth = TRUE, sigma = 0.01), col = 2) # in a model set.seed(1) y <- c(rnorm(95), rnorm(5, 10)) # 5% of outliers fit <- Qlm(y ~ 1, wtau = wtrunc, delta.left = 0.05, delta.right = 0.05) coef(fit)