View source: R/predictorEffects.R

predictorEffects | R Documentation |

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.

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)

`mod` |
A model object. Supported models include all those described on the help page for |

`predictor` |
quoted name of the focal predictor. |

`predictors` |
If the default, |

`focal.levels` |
for For |

`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 If the focal predictor is included in the The default behavior of The |

`...` |
Additional arguments passed to |

`sources` |
Provides a mechanism for applying |

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.

`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")`

.

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

See `Effect`

.

`Effect`

, `plot.predictoreff`

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

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))))) }

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.