predictorEffects: Functions For Computing Predictor Effects

View source: R/predictorEffects.R

predictorEffectsR Documentation

Functions For Computing Predictor Effects

Description

Alternatives to the Effect and allEffects functions that use a different paradigm for conditioning in an effect display. The user specifies one predictor, either numeric or a factor (where character and logical variables are treated as factors), for the horizontal axis of a plot, and the function determines the appropriate plot to display (which is drawn by plot). See the vignette Predictor Effects Graphics Gallery for details and examples.

Usage

predictorEffect(predictor, mod, focal.levels=50, xlevels=5, ...)

## S3 method for class 'poLCA'
predictorEffect(predictor, mod, focal.levels=50, 
    xlevels=5, ...)

## S3 method for class 'svyglm'
predictorEffect(predictor, mod, focal.levels=50, 
    xlevels=5, ...)

## Default S3 method:
predictorEffect(predictor, mod, focal.levels=50, 
    xlevels=5, ..., sources)

predictorEffects(mod, predictors, focal.levels=50, xlevels=5, ...)

## S3 method for class 'poLCA'
predictorEffects(mod, predictors = ~ ., 
    focal.levels=50, xlevels=5, ...)

## Default S3 method:
predictorEffects(mod, predictors = ~ .,
    focal.levels=50, xlevels=5,  ..., sources)

Arguments

mod

A model object. Supported models include all those described on the help page for Effect.

predictor

quoted name of the focal predictor.

predictors

If the default, ~ ., a predictor effect plot is drawn for each predictor (not regressor) in a model. Otherwise, this is a one-sided formula specifying the first-order predictors for which predictor effect plots are to be drawn.

focal.levels

for predictorEffect, the number of evenly-spaced values (the default is 50) for the numeric focal predictor or a vector of values for the focal predictor.

For predictorEffects, the number of evenly-spaced values (default 50) to use for each numeric focal predictor in turn, or a named list, similar to xlevels, giving the number of values or the values themselves for each predictor individually, to be used when that predictor is the focal predictor; if a numeric focal predictor doesn't appear in the list, the default of 50 values is used.

xlevels

this argument is used to set the levels of conditioning predictors; it may either be a single number specifying the number of evenly-spaced values (the default is 5) to which each conditioning predictor is to be set, or it may be a list with elements named for the predictors giving the number of values or a vector of values to which each conditioning predictor is to be set, as explained in the help for Effect.

If the focal predictor is included in the xlevels list, it is disregarded; if any conditioning predictor is omitted from the list, its number of values is set to 5.

The default behavior of xlevels is different when residuals=TRUE; in that case, it behaves as in Effect.lm, and is effectively set by default to the 0.2, 0.4, 0.6, and 0.8 quantiles of conditioning predictors.

The xlevels argument works similarly for predictorEffect and predictorEffects.

...

Additional arguments passed to Effect.

sources

Provides a mechanism for applying predictorEffect methods to a variety of regression models; see the vignette Regression Models Supported by the effects Package for an explanation.

Details

Effect plots view a fitted regression function E(Y|X) in (sequences of) two-dimensional plots using conditioning and slicing. The functions described here use a different method of determining the conditioning and slicing than allEffects uses. The predictor effect of a focal predictor, say x1, is the usual effect for the generalized interaction of x1 with all the other predictors in a model. When a predictor effect object is plotted, the focal predictor is by default plotted on the horizontal axis.

For example, in the model mod with formula y ~ x1 + x2 + x3, the predictor effect p1 <- predictorEffects(mod, ~ x1) is essentially equilavent to p2 <- Effect("x1", mod). When plotted, these objects may produce different graphs because plot(p1) will always put x1 on the horizontal axis, while plot(p2) uses a rule to determine the horizontal axis based on the characteristics of all the predictors, e.g., preferring numeric predictors over factors.

If mod has the formula y ~ x1 + x2 + x3 + x1:x2, then p1 <- predictorEffects(mod, ~ x1) is essentially equivalent to p2 <- Effect(c("x1", "x2"), mod). As in the last example, the plotted versions of these objects may differ because of different rules used to determine the predictor on the horizontal axis.

If mod has the formula y ~ x1 + x2 + x3 + x1:x2 + x1:x3, then p1 <- predictorEffects(mod, ~ x1) is essentially equilavent to p2 <- Effect(c("x1", "x2", "x3"), mod). Again, the plotted versions of these objects may differ because of the rules used to determine the horizontal axis.

Value

predictorEffect returns an object of class c("predictoreff", "eff"). The components of the object are described in the help for Effect; predictorEffects returns an object of class "predictorefflist", which is a list whose elements are of class c("predictoreff", "eff").

Author(s)

S. Weisberg sandy@umn.edu and J. Fox

References

See Effect.

See Also

Effect, plot.predictoreff, the Predictor Effects Graphics Gallery vignette, and the Effect Displays with Partial Residuals vignette.

Examples

mod <- lm(prestige ~ type*(education + income) + women, Prestige)
plot(predictorEffect("income", mod))
plot(predictorEffects(mod, ~ education + income + women))

mod.cowles <- glm(volunteer ~ sex + neuroticism*extraversion, data=Cowles, family=binomial)
plot(predictorEffects(mod.cowles, xlevels=4))
plot(predictorEffect("neuroticism", mod.cowles, xlevels=list(extraversion=seq(5, 20, by=5))),
     axes=list(grid=TRUE,
               x=list(rug=FALSE),
               y=list(lab="Probability of Vounteering")),
     lines=list(multiline=TRUE), 
     type="response")
predictorEffects(mod.cowles, focal.levels=4, xlevels=4)

# svyglm() example (adapting an example from the survey package)

if (require(survey)){
  data(api)
  dstrat<-svydesign(id=~1, strata=~stype, weights=~pw,
    data=apistrat, fpc=~fpc)
  mod <- svyglm(sch.wide ~ ell + meals + mobility, design=dstrat,
    family=quasibinomial())
  plot(predictorEffects(mod),
    axes=list(y=list(lim=log(c(0.4, 0.99)/c(0.6, 0.01)),
      ticks=list(at=c(0.4, 0.75, 0.9, 0.95, 0.99)))))
}


effects documentation built on July 13, 2022, 5:06 p.m.