MarginalEffects: Marginal effects

Description Usage Arguments Details Value Examples

View source: R/util-func.R

Description

This computes marginal effects for a small change in a chosen continuous explanatory variable as difference of semiparametric conditional probabilities.

Usage

1
2
3
4
5
6
7
8
MarginalEffects(
  fit,
  variable,
  delta,
  p.cutoffs = NULL,
  h = NULL,
  trimming = FALSE
)

Arguments

fit

a fitted 'semiBRM' object.

variable

an integer indicating the position of the explanatory variable of interest or character of its name. For example, to compute marginal effects of the first explanatory variable, variable needs to be either 1L or its name in character.

delta

the size of perturbation over which difference of semiparametric conditional probabilities are computed. Popular choice of delta would be 1 or standard deviation of the variable of interest.

p.cutoffs

a numeric vector of probabilities (e.g. p.cutoffs = c(1/4, 2/4, 3/4)).

h

a numeric of bandwidth size in the Nadaraya-Watson estimator. If not given, it will use the Silverman's rule of thumb bandwidth, h = sd(x)*1.06*N^(-1/5).

trimming

a logical indicating whether to trim semiparametric conditional probabilities near boundaries into zeros. If trimming = TRUE, then the trimming indicator is extracted from the given 'semiBRM' object.

Details

This function is designed to analyze marginal effects of a chosen explanatory variable over its change by delta, where marginal effects are defined as difference between the two semiparametric conditional probabilities evaluated with and without perturbation delta to the variable of interest. Notice that this is designed for a continuous variable in x.

If p.cutoffs = NULL, then it will return average marginal effects over data points. If a numeric vector of probabilities is given for p.cutoffs, it will calculate quantile marginal effects accordingly to the grouping by quantile values at p.cutoffs. For example, if p.cutoffs = c(1/4, 2/4, 3/4), it will return quartile marginal effects over the four quartile groups.

Value

a vector or matrix of marginal effects and standard errors.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# data generating process
N <- 1000L
X1 <- rnorm(N)
X2 <- (X1 + 2*rnorm(N))/sqrt(5) + 1
X3 <- rnorm(N)^2/sqrt(2)
X <- cbind(X1, X2, X3)
beta <- c(2, 2, -1, -1)
V <- as.vector(cbind(X, 1)%*%beta)
Y <- ifelse(V >= rnorm(N), 1L, 0L)

# parameter estimation
qmle <- semiBRM(x = X, y = Y, control = list(iterlim=50))

# average marginal effects of X1
av_me <- MarginalEffects(qmle, variable = "X1", delta = sd(X1))

# quantile marginal effects of X1
q_me <- MarginalEffects(qmle, variable = "X1", delta = sd(X1), p.cutoffs = c(1/3, 2/3))

henrykye/semiBRM documentation built on Dec. 20, 2021, 3:49 p.m.