plotwtdinteraction: Functions to Identify and Plot Predicted Probabilities As...

Description Usage Arguments Value Author(s)

View source: R/plotwtdinteraction.R

Description

plotwtdinteraction produces a plot from a regression object to illustrate a two- or three-way interaction for a prototypical individual holding constant all other variables (or other counterfactuals, depending on type). Prototypical individual is identified as the mean (numeric), median (ordinal), and/or modal (factors and logical variables) values for all measures. Standard errors are illustrated with polygons by default.

findwtdinteraction generates a table of point estimates from a regression object to illustrate a two- or three-way interaction for a prototypical individual holding constant all other variables. Prototypical individual is identified as the mean (numeric), median (ordinal), and/or modal (factors and logical variables) values for all measures. Standard errors are illustrated with polygons by default.

plotinteractpreds plots an object from findwtdinteraction.

These functions are known to be compatible with lm, glm, as well as multiply imputed lm and glm data generated with the mice package. They are also compatible with gam and bam regressions from the mgcv package under default.

ordinal regressions (polr) and multinomial regressions (multinom) do not currently support standard errors, additional methods are still being added.

*Note, this set of functions is still in beta, please let me know if you run into any bugs when using it.*

**Important: If you are using a regression output from a multiply imputed dataset with a continuous variable as an interacting term, you should always specify the levels (acrosslevs, bylevs, or atlevs) for the variable, as imputations can change the set of levels that are available and thus can make the point estimates across imputed datasets incompatible with one-another.**

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
plotwtdinteraction(x, across, by=NULL, at=NULL, acrosslevs=NULL, bylevs=NULL,
atlevs=NULL, weight=NULL, dvname=NULL, acclevnames=NULL, bylevnames=NULL,
atlevnames=NULL, stdzacross=FALSE, stdzby=FALSE, stdzat=FALSE, limitlevs=20,
type="response", seplot=TRUE, ylim=NULL, main=NULL, xlab=NULL, ylab=NULL,
legend=TRUE, placement="bottomright", lwd=3, add=FALSE, addby = TRUE, addat=FALSE,
mfrow=NULL, linecol=NULL, secol=NULL, showbynamelegend=FALSE,
showatnamelegend=FALSE, showoutnamelegend = FALSE, 
lty=NULL, density=30, startangle=45, approach="prototypical", data=NULL,
nsim=100, ...)

findwtdinteraction(x, across, by=NULL, at=NULL, acrosslevs=NULL, bylevs=NULL,
atlevs=NULL, weight=NULL, dvname=NULL, acclevnames=NULL, bylevnames=NULL,
atlevnames=NULL, stdzacross=FALSE, stdzby=FALSE, stdzat=FALSE, limitlevs=20,
type="response", approach="prototypical", data=NULL, nsim=100)

plotinteractpreds(out, seplot=TRUE, ylim=NULL, main=NULL, xlab=NULL, ylab=NULL,
legend=TRUE, placement="bottomright", lwd=3, add=FALSE, addby = TRUE,
addat=FALSE, mfrow=NULL, linecol=NULL, secol=NULL, showbynamelegend=FALSE,
showatnamelegend=FALSE, showoutnamelegend = FALSE, lty=NULL,
density=30, startangle=45, ...)

Arguments

x

x is a regression object in lm, glm, or mira (multiply imputed) format that includes the variables to be plotted.

out

out is an object estimate using findwtdinteraction that should be plotted.

across

across specifies the name of the variable, in quotation marks, that was used in the regression that should be plotted on the X axis.

by

by specifies the name of the variable, in quotation marks, that was used in the regression that should form each of the separate lines in the regression.

at

at (optional) specifies the name of the variable, in quotation marks, that represents the third-way of a 3-way interaction. Depending on specifications, this can either be plotted as additional lines or as separate graphs.

acrosslevs

acrosslevs (optional) specifies the unique levels of the variable across that should be estimated across the x axis. If this is not specified, each unique level of the across variable will be used.

bylevs

bylevs (optional) specifies the unique levels of the variable by that should yield separate lines. If this is not specified, each unique level of the by variable will be used.

atlevs

atlevs (optional) specifies the unique levels of the variable at that should yield separate figures or lines. If this is not specified, each unique level of the at variable will be used.

weight

weight (optional) allows the user to introduce a separate weight that was not used in the original regression. If the regression was run using weights, those weights will always be used to generate estimates of the prototypical individual to be used.

dvname

dvname (optional) allows the user to relabel the dependent variable for printouts.

acclevnames

dvname (optional) allows the user to specify the names for the specified levels of the accross variable.

bylevnames

dvname (optional) allows the user to specify the names for the specified levels of the by variable.

atlevnames

dvname (optional) allows the user to specify the names for the specified levels of the at variable.

stdzacross

dvname (optional) shows levels of across variable in (weighted) standard deviation units. This defaults to showing 1SD below mean and 1SD above mean; specifying acrosslevs to other values will provide results in SD units instead of variable units.

stdzby

dvname (optional) shows levels of by variable in (weighted) standard deviation units. This defaults to showing 1SD below mean and 1SD above mean; specifying bylevs to other values will provide results in SD units instead of variable units.

stdzat

dvname (optional) shows levels of at variable in (weighted) standard deviation units. This defaults to showing 1SD below mean and 1SD above mean; specifying atlevs to other values will provide results in SD units instead of variable units.

limitlevs

limitlevs sets the number of different levels that any given interacting variable can have. This is meant to prevent inadvertent generation and plotting of tons of point estimates for continuous variables. The default is set to 20.

type

type sets the type of prediction to be used for generation of the estimates. This defaults to "response" but can be used with any type of model prediction for which only one numeric estimate is given. (Not currently compatible with estimates derived from polr regression).

seplot

seplot (optional) if set to TRUE, plots will include polygons illustrating standard errors.

ylim

ylim (optional) passes on y-axis limits to plot function.

main

main (optional) passes on title to plot function.

xlab

xlab (optional) passes on x-axis labels to plot function.

ylab

ylab (optional) passes on y-axis labels to plot function.

legend

legend (optional) if TRUE will produce a legend on the interaction figure.

placement

placement (optional) passes to legend function a location for the legend. Can be set to "bottomright", "bottomleft", "topright", and "topleft".

lwd

lwd (optional) specifies the line strength for plots, this passes on to the plot command.

add

add (optional) logical statement to add the results to an existing plot (at=TRUE) rather than generating a new one (at=FALSE is the default).

addby

addby (optional) logical statement specifying whether the levels of by should be different plots (addby=TRUE) or if each level of by should generate a new plot (addby=TRUE is the default). This only influences some types of plots.

addat

addat (optional) logical statement specifying whether the levels of at should be different plots (addat=TRUE) or if each level of at should generate a new plot (addat=FALSE is the default)

mfrow

mfrow (optional) temporarily changes the number of plots per page in par for the purpose of generating current plots. This should generally only be used for 3-way interactions. It takes commands of the form c(2,3), specifying the number of rows and columns in the graphics interface. The algorithm defaults to putting all 3-way interactions on a single page with a width of 2.

linecol

linecol (optional) Specifies the colors of lines in the figure(s). For two-way interactions, this should be a vector of the same length as bylevs. For 3-way interactions, the colors demarcate the levels of at instead and should be the same length as atlevs.

secol

secol (optional) Specifies the colors of standard error in the figure(s). For two-way interactions, this should be a vector of the same length as bylevs. For 3-way interactions, the colors demarcate the levels of at instead and should be the same length as atlevs.

showbynamelegend

showbynamelegend (optional) adds name of by variable to names of value levels in legend.

showatnamelegend

showatnamelegend (optional) adds name of at variable to names of value levels in legend.

showoutnamelegend

showoutnamelegend (optional) adds name of DV to legend in multinomial logit plots only.

lty

lty (optional) line type to pass on to plot.

density

density (optional) line density for standard error plots.

startangle

startangle (optional) line angle for standard error plots.

approach

approach determines whether you want to estimate counterfactuals for a prototypical individual approach="prototypical" (the default), for the entire population approach="population", or for individuals in the subgroups specified in the by and at categories approach="at", approach="by", approach="atby".

data

data (optional) allows you to replace the dataset used in the regression to produce other prototypical values.

nsim

nsim (optional) set the number of bootstrapped simulations to use to generate standard errors for lmer-style regressions. Note that this SIGNIFICANLY increases the time to run, so test with smaller numbers before running.

...

... (optional) Additional arguments to be passed on to plot command (or future methods of findwtdinteraction).

Value

A table or figure illustrating the predicted values of the dependent variable across levels of the independent variables for a prototypical respondent.

Author(s)

Josh Pasek, Assistant Professor of Communication Studies at the University of Michigan (www.joshpasek.com).


weights documentation built on June 11, 2021, 1:06 a.m.