maref.rqt {Qtools} | R 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 |
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
, where
is the response variable,
a design matrix, and
is a one-parameter transformation with inverse
,
maref
computes the marginal effect:
where 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
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
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)