Marginal Effects

Share:

Description

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

Usage

1
2
3
4
5
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 τth conditional quantile function Q_{h(Y)|X}(τ) = η = 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:

dQ(τ)/dx_{j} = dg(Q_{h(Y)})/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

dQ(τ)/dx_{j} = dg(η)/dη dη/dx_{j}

The derivative w.r.t. the linear predictor η 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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
## 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)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.