margEff.polywog: Marginal effects for polywog models

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Computes average and observationwise marginal effects from a fitted polywog model.

Usage

1
2
## S3 method for class 'polywog'
margEff(object, xvar = NULL, drop = FALSE, ...)

Arguments

object

a fitted model of class "polywog", typically the output of polywog. The object must have a model element, meaning it was fit with model = TRUE.

xvar

a character string containing the name of a raw input variable (from object$varNames). Partial matches are allowed.

drop

logical: whether to convert one-column matrices in the output to vectors.

...

other arguments, currently ignored.

Details

For input variables that are binary, logical, or factors, margEff.polywog computes a first difference with comparison to a reference category. All other variables are treated as continuous: the function computes the partial derivative of the fitted value with respect to the selected variable.

Value

If xvar is specified, a numeric object containing the marginal effect of the chosen variable at each observation in object$model. For factor variables, if there are more than two levels or drop = FALSE, the returned object is a matrix; otherwise it is a vector.

If xvar is NULL, a list of such results for each raw input variable in the model is returned.

In either case, the returned object is of class "margEff.polywog".

Author(s)

Brenton Kenkel and Curtis S. Signorino

See Also

To plot the density of the observationwise marginal effects, see plot.margEff.polywog. For a table of average marginal effects and order statistics, summary.margEff.polywog.

To compute fitted values, see predict.polywog and predVals.

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
## Using occupational prestige data
data(Prestige, package = "carData")
Prestige <- transform(Prestige, income = income / 1000)

## Fit a polywog model
## (note: using low convergence threshold to shorten computation time of the
## example, *not* recommended in practice!)
set.seed(22)
fit1 <- polywog(prestige ~ education + income | type,
                data = Prestige,
                degree = 2,
                thresh = 1e-4)

## Compute marginal effects for all variables
me1 <- margEff(fit1)
summary(me1)  # type was included linearly, hence constant effects

## Plotting density of the results
plot(me1)

## Can do the same when just examining a single variable
me2 <- margEff(fit1, xvar = "income")
summary(me2)
plot(me2)

brentonk/polywog documentation built on May 13, 2019, 5:10 a.m.