View source: R/margEff.polywog.r
| margEff.polywog | R Documentation | 
Computes average and observationwise marginal effects from a fitted
polywog model.
## S3 method for class 'polywog'
margEff(object, xvar = NULL, drop = FALSE, ...)
| object | a fitted model of class  | 
| xvar | a character string containing the name of a raw input variable
(from  | 
| drop | logical: whether to convert one-column matrices in the output to vectors. | 
| ... | other arguments, currently ignored. | 
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.
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".
Brenton Kenkel and Curtis S. Signorino
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.
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.