displayPairs function

Display within-level pairwise comparisons for saturated two-way ANOVA model.

Display within-level pairwise comparisons for saturated two-way ANOVA model.

Displays within-level pairwise comparisons from a two-way ANOVA with interactions. Note that this is just a display function: it ignores any cross-level pairs included in allpairs, even though these will have contributed to the computations for the Tukey adjustments. The purpose is just to organise the output from emmeans into a more convenient format.

displayPairs(allpairs, levels1, levels2, brief = TRUE, asDF = FALSE)

Arguments

  • allpairs: pairwise output from a command like pairs. See details for a longer explanation.
  • levels1: a character string specifying which within-level comparisons from factor1 are wanted, and in which order.
  • levels2: a character string specifying which within-level comparisons from factor2 are wanted, and in which order.
  • brief: either TRUE or FALSE. If TRUE then the information displayed will be more succinct.
  • asDF: either TRUE or FALSE specifying whether to return a data.frame of results or just to display the output.

Details

allpairs is a pairwise output from a command like pairs(emmeans(fit, ~factor1 * factor2)). If allpairs is not already a data.frame it will be converted to a data.frame

within this function. It must contain a column called contrast with text descriptions like 'lev1 lev2 - lev3 lev4' etc. levels1

and levels2 are character strings specifying which within-level comparisons are wanted, and in which order. They must match the order specified in emmeans, so if using emmeans(fit, ~factor1 * factor2) then levels1 must belong to factor1 and levels2 must belong to factor2. All this function does is to pick out the rows of allpairs with the requested contrasts, so if there are no contrasts of the requested format (e.g. because levels1

and levels2 have been switched) it will output a blank list. If brief = TRUE, columns labelled df, SE, and t.ratio or z.ratio will be removed for a more succinct display. If asDF = TRUE, the output is returned as a data-frame suitable for further manipulation, whereas if asDF = FALSE it is returned as a list for display only.

Examples

## Fit a two-way ANOVA to the arousal data in arousal.df. ## The factors are gender (female, male) and picture shown to ## subject (infant, landscape, nude.f, nude.m): data(arousal.df) arousal.fit = lm(arousal ~ gender * picture, data = arousal.df) ## Create a data-frame with all pairwise comparisons using \code{emmeans}: require(emmeans) arousal.allpairs = pairs(emmeans(arousal.fit, ~gender * picture), infer = TRUE) ## Display only the within-level comparisons: displayPairs(arousal.allpairs, levels1 = c('female', 'male'), levels2 = c('infant', 'landscape', 'nude.f', 'nude.m'))

Author(s)

Rachel Fewster

  • Maintainer: James Curran
  • License: GPL-2 | file LICENSE
  • Last published: 2023-08-21