Learn R Programming

effects (version 4.1-4)

EffectMethods: Functions For Constructing Effect Displays for Many Modeling Paradigms

Description

The Effect, effect and predictorEffects methods are used to draw effects plots to visualize a fitted regression surface. These plots can be drawn at least in principle for any model that uses a linear predictor. Methods for modeling paradigms than the basic lm, glm, multinom and polr methods are documented here. To add methods for new classes of statistical models, see the vignette Defining Effect Methods for Other Models.

Usage

# S3 method for default
Effect(focal.predictors, mod,  ...,
    sources=NULL)

# S3 method for gls Effect(focal.predictors, mod, ...)

# S3 method for clm2 Effect(focal.predictors, mod, ...)

# S3 method for clmm Effect(focal.predictors, mod, ...)

# S3 method for clm Effect(focal.predictors, mod, ...)

# S3 method for merMod Effect(focal.predictors, mod, ..., KR=FALSE)

# S3 method for rlmerMod Effect(focal.predictors, mod, ...)

# S3 method for lme Effect(focal.predictors, mod, ...)

# S3 method for poLCA Effect(focal.predictors, mod, ...)

# S3 method for mlm Effect(focal.predictors, mod, response, ...)

# S3 method for betareg Effect(focal.predictors, mod, ...)

Arguments

focal.predictors

a character vector of one or more predictors in the model in any order.

mod

a fitted model object of the appropriate class.

...

additional arguments passed to other Effect. See Effect for all the arguments included.

response

for an "mlm" object, a vector containing the name(s) or indices of one or more response variable(s). The default is to use all responses in the model.

sources

This argument appears only in the default method for Effect, and allows the user to draw effects plots for fitting methods for which there are not existing methods in the effects package. Seven arguments are provided:

type

the default is "glm", which assumes the modeling method shares characteristics with a generalized linear model, including a univariate response, a linear predictor, and possibly a error family and link function.

call

For S3 objects, the default is ojbect$call, returning the call that created the object. This is used to harvest standard arguments like data, subset and family.

formula

the formula for the linear predictor, defaulting to formula(object).

family

if the model object includes an error family, but it is not returned by family(object), specify the family with this argument; otherwise it can be ignored.

method

For ordinal response models only, see the method argument to polr.

coefficients

The estimates of the coefficents in the linear predictor, with default coef(object).

vcov

the estimated variance covariance materix to be used in computing errors in the effects plots; default is codevcov(object).

KR

if TRUE and the pbkrtest package is installed, use the Kenward-Roger coefficient covariance matrix to compute effect standard errors for linear mixed models fit with lmer in the lme4 package. The default is FALSE because the computation can be very slow.

Value

See Effect

Details

Most of these methods simply call the Effect.default method with the appropriate values in the arguement sources. See the vignettte Effect Methods in the vignettes for the effects package. All the iteresting work is done by the methods described in Effect.

References

The Defining Effect Methods for Other Models vignette.

See Also

Effect and the links therein.

Examples

Run this code
# NOT RUN {
# lme
require(nlme)
fm1 <- lme(distance ~ age + Sex, data = Orthodont, random = ~ 1)
plot(predictorEffects(fm1))

# gls
library(nlme)
g <- gls(Employed ~ GNP + Population,
         correlation=corAR1(form= ~ Year), data=longley)
print(predictorEffects(g))

# lmer  uses method Effect.lmerMod
if("package:nlme" <!-- %in% search()) detach(package:nlme) -->
require(lme4)
data("Orthodont", package="nlme")
fm2 <- lmer(distance ~ age + Sex + (1 |Subject), data = Orthodont)
plot(allEffects(fm2))

# glmer  uses method Effect.lmerMod
require(lme4)
gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
              data = cbpp, family = binomial)
as.data.frame(predictorEffect("period", gm1))

# rlmer  uses method Effect.rlmerMod
require(lme4)
fm3 <- robustlmm::rlmer(distance ~ age + Sex + (1 |Subject), data = Orthodont)
plot(effect("age:Sex", fm3))
plot(predictorEffects(fm3, ~ age + Sex))

# betareg from the betareg package
library(betareg)
library(lme4)
data("GasolineYield", package = "betareg")
gy_logit <- betareg(yield ~ batch + temp, data = GasolineYield)
summary(gy_logit)
Effect("batch", gy_logit)
predictorEffects(gy_logit)

# clm in ordinal
require(ordinal)
require(MASS)
mod.wvs1 <- clm(poverty ~ gender + religion + degree + country*poly(age,3),
    data=WVS)
plot(Effect(c("country", "age"), mod.wvs1), 
     lines=list(multiline=TRUE), layout=c(2, 2))

# clm2
require(ordinal)
require(MASS)
v2 <- clm2(poverty ~ gender + religion + degree + country*poly(age,3),data=WVS)
plot(emod2 <- Effect(c("country", "age"), v2))

# clmm
require(ordinal)
require(MASS)
mm1 <- clmm(SURENESS ~ PROD + (1|RESP) + (1|RESP:PROD), 
        data = soup, link = "logit", threshold = "flexible")
plot(Effect("PROD", mm1),lines=list(multiline=TRUE))

# poLCA
library(poLCA)
data(election)
f2a <- cbind(MORALG,CARESG,KNOWG,LEADG,DISHONG,INTELG,
             MORALB,CARESB,KNOWB,LEADB,DISHONB,INTELB)~PARTY
nes2a <- poLCA(f2a,election,nclass=3,nrep=5)    # log-likelihood: -16222.32
allEffects(nes2a)

# multivariate linear model
data(Baumann, package="carData")
b1 <- lm(cbind(post.test.1, post.test.2, post.test.3) ~ group + 
    pretest.1 + pretest.2, data = Baumann))
plot(Effect("group", b1)

# }

Run the code above in your browser using DataLab