twoway (version 0.6.3)

plot.twoway: Plot methods for two-way tables

Description

Plots either the fitted values and residuals under additivity or a diagnostic plot for removable non-additivity by a power transformation

Usage

# S3 method for twoway
plot(x, which = c("fit", "diagnose"), ...,
  na.rm=any(is.na(x$residuals)))

# S3 method for twoway.fit plot(x, main = paste0("Tukey two-way fit plot for ", x$name, " (method: ", x$method, ")"), xlab = expression(hat(mu) * " + Column Effect - Row Effect"), ylab = expression("Fit = " * hat(mu) * " + Column Effect + Row Effect"), rfactor = 1, rcolor = c("blue", "red"), lwd = 3, ylim = NULL, ..., na.rm=any(is.na(x$residuals)))

# S3 method for twoway.diagnose plot(x, annotate = TRUE, jitter = FALSE, smooth = FALSE, pch = 16, ...)

Arguments

x

a class("twoway") object

which

one of "fit" or "diagnose"

...

other arguments, passed to plot

na.rm

logical. Should missing values be removed?

main

plot title

xlab

X axis label

ylab

Y axis label

rfactor

draw lines for abs(residuals) > rfactor*sqrt(MSPE)

rcolor

a vector of length 2 giving the color of lines for positive and negative residuals

lwd

line width for residual lines in the fit plot

ylim

Y axis limits

annotate

A logical value; if TRUE, the slope and power are displayed in the diagnostic plot

jitter

A logical value; if TRUE, the comparison values in the plot are jittered to avoid overplotting

smooth

A logical value; if TRUE, a smoothed loess curve is added to the plot

pch

Plot character for point symbols in the diagnostic plot

Value

The diagnostic plot invisibly returns a list with elements c("slope", "power")

Details

For the which="fit" plot, the basic result comes from a plot of the row effects against the column fitted values, which appears as a rectangular grid in these coordinates. Rotating this 45 degrees counterclockwise give a plot in which the vertical coordinate is the fitted value for the two-way table, and the horizontal coordinate is the column fit minus the row effect. The spacing of the grid lines for the rows and columns of the table show the relative magnitudes of the row/column means or medians.

For the which="diagnose" plot, the interaction residuals from an additive model, \(y_{ij} = \mu + \alpha_i + \beta_j\), are plotted against the estimated components \(\alpha_i \beta_j / \mu\). If this plot shows a substantially non-zero slope, \(b\), this analysis suggests that a power transformation, \( y \rightarrow y^(1-b)\) might reduce the apparent interaction effects.

For both plots, if you want to directly compare the result of method="mean" and method="median", it is essential to set the same xlim and ylim axes in the call.

Examples

Run this code
# NOT RUN {
data(taskRT)
tw <- twoway(taskRT)
tw
twmed <- twoway(taskRT, method="median")
twmed
plot(tw,    xlim=c(2,7), ylim=c(2,7)) ## use the same xlim and ylim, for comparison
plot(twmed, xlim=c(2,7), ylim=c(2,7))

plot(tw,    which="diagnose", xlim=c(-.19, .19), ylim=c(-.5, .55))
plot(twmed, which="diagnose", xlim=c(-.19, .19), ylim=c(-.5, .55))

data(insectCounts)
twi <- twoway(insectCounts)
twimed <- twoway(insectCounts, method="median")

plot(twi,    xlim=c(-250, 700), ylim=c(-180, 900))
plot(twimed, xlim=c(-250, 700), ylim=c(-180, 900))

plot(twi,    which="diagnose", xlim=c(-160, 170), ylim=c(-200, 400))  ## power = .1
plot(twimed, which="diagnose", xlim=c(-160, 170), ylim=c(-200, 400))  ## power = .3

# }

Run the code above in your browser using DataCamp Workspace