Learn R Programming

polywog (version 0.4-1)

margEff.polywog: Marginal effects for polywog models

Description

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

Usage

# S3 method for 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.

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".

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.

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

Run this code
# NOT RUN {
## 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)
# }

Run the code above in your browser using DataLab