Learn R Programming

Qtools (version 1.0)

maref.rqt: Marginal Effects

Description

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

Usage

maref(object, newdata, index = 2, index.extra = NULL, ...)
## S3 method for class 'rqt':
maref(object, newdata, index = 2, index.extra = NULL, ...)
## S3 method for class 'rq.counts':
maref(object, newdata, index = 2, index.extra = NULL, ...)

Arguments

Value

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

Details

Given the general model Q(h(response)|X) = Xb, where Q is the conditional quantile function, X a design matrix with p columns, and h is a one- or two-parameter transformation with inverse hinv, maref allows computing the marginal effect: dQ(response|X)/dx[j] where j specifies the covariate in the design matrix with respect to which the marginal effect is to be computed and is given in the argument index. Since the model may contain interactions with x[j], additional terms in the matrix X to be included in the computation are given in the argument index.extra. See the examples below.

See Also

tsrq

Examples

Run this code
# 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, index = 2)

# Plot marginal effect over grid of values (for fixed girth)
nd <- data.frame(Height = seq(min(trees$Height), max(trees$Height), length = 100),
	Girth = rep(mean(trees$Girth), 100))
x <- maref(fit, newdata = nd, index = 2)
plot(nd$Height, x, xlab = "height", ylab = "marginal effect on volume")

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

# Marginal effect of 'Height'
maref(fit, index = 2, index.extra = 4)

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

Run the code above in your browser using DataLab