maref.rqt: Marginal Effects

maref.rqtR Documentation

Marginal Effects

Description

This function computes marginal effects for rqt and rq.counts objects.

Usage

maref(object, namevec)
## S3 method for class 'rqt'
maref(object, namevec)
## S3 method for class 'rq.counts'
maref(object, namevec)

Arguments

object

an rqt or an rq.counts object.

namevec

character giving the name of the covariate with respect to which the marginal effect is to be computed.

Details

Given the \tauth conditional quantile function Q_{h(Y)|X}(\tau) = \eta = Xb, where Y is the response variable, X a design matrix, and h is a one-parameter transformation with inverse h^{-1} = g, maref computes the marginal effect:

\frac{dQ_{Y|X}(\tau)}{dx_{j}} = \frac{dg\{Q_{h(Y)|X}(\tau)\}}{dx_{j}}

where x_{j} is the j-th covariate with respect to which the marginal effect is to be computed and its name is given in the argument namevec.

The derivative of the quantile function is the the product of two components

\frac{dQ_{Y|X}(\tau)}{dx_{j}} = \frac{dg(\eta)}{d\eta} \cdot \frac{d\eta}{dx_{j}}

The derivative w.r.t. the linear predictor \eta is calculated symbolically after parsing the object's formula and is evaluated using the object's model frame. The function that parses formulae has a limited scope. It recognizes interactions and basic operators (e.g., log, exp, etc.). Therefore, it is recommended to use simple expressions for the model's formula.

This function can be applied to models of class rqt and rq.counts. Note that marginal effects can be similarly obtained using predict.rqt or predict.rq.counts with argument type = "maref" which, in addition, allows for an optional data frame to be specified via newdata.

Value

a vector for single quantiles or a matrix for multiple quantiles of marginal effects.

Author(s)

Marco Geraci

See Also

tsrq

Examples

## Not run: 
# Box-Cox quantile regression model (dataset trees from package 'datasets')
fit <- tsrq(Volume ~ Height, data = trees, tsf = "bc", tau = 0.9)

# Coefficients (transformed scale)
coef(fit)

# Design matrix
head(fit$x)

# Marginal effect of 'Height'
maref(fit, namevec = "Height")

# Predict marginal effects over grid of values for Height
nd <- data.frame(Height = seq(min(trees$Height), max(trees$Height), length = 100))
x <- predict(fit, newdata = nd, type = "maref", namevec = "Height")

# Plot
plot(nd$Height, x, xlab = "Height", ylab = "Marginal effect on volume")

# Include 'Girth' and interaction between 'Height' and 'Girth'
fit <- tsrq(Volume ~ Height * Girth, data = trees, tsf = "bc", tau = 0.5)
head(fit$x)

# Predict marginal effects over grid of values for Height (for fixed girth)
nd$Girth <- rep(mean(trees$Girth), 100)
x <- predict(fit, newdata = nd, type = "maref", namevec = "Height")
plot(nd$Height, x, xlab = "Height", ylab = "Marginal effect on volume")

# Quantile regression for counts (log transformation)
data(esterase)
fit <- rq.counts(Count ~ Esterase, tau = 0.25, data = esterase, M = 50)
maref(fit, namevec = "Esterase")

## End(Not run)

Qtools documentation built on Nov. 2, 2023, 6:11 p.m.