paircomp: Visualization of multiple pairwise comparison test results

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/paircomp.R

Description

This function performs multiple pairwise comparison tests on given data and views the results in the form of Hasse diagram.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
paircomp(obj, 
         grouping=NULL,
         test=c("t", "prop", "wilcox"),
         level=0.05,
         main=NULL,
         compress=TRUE,
         visualize=c("position", "size", "pvalue"),
         result=FALSE,
         draw=TRUE,
         ...)

Arguments

obj

either a vector or an object of class glht as returned from the glht function of the multcomp package.

If obj is an object of class glht, then arguments grouping and test may be arbitrary, because they will be not used. Otherwise, if test equals "t" or "wilcox", obj should be a numeric vector of responses, and if test equals "prop", obj should be a vector of 0's and 1's.

grouping

a grouping factor. If obj is a numeric vector, grouping must be a factor. If obj is an object of class glht, grouping should be NULL.

test

a name of the test to use. If obj is an object of class glht, the value of test does not have any effect. Otherwise, the values determine the type of the pairwise comparison test procedure. Allowed values "t", "prop" or "wilcox" imply internal call of pairwise.t.test(), pairwise.prop.test() or pairwise.wilcox.test(), respectively.

level

the maximum p-value that will be considered as significant; i.e. pairwise test results with p-value lower than the specified level will be represented with an edge in the resulting Hasse diagram.

main

main title of the diagram.

compress

TRUE if the edges should be compressed, i.e. if the maximum bi-cliques have to be found in the graph and replaced with a "dot" vertex. (See examples.)

visualize

vector of additional information to be included in the diagram: "position" enables vertex background color to be derived from the treatment's proportion ("prop" test) or mean value (otherwise); "size" enables vertex size to correspond to the treatment's sample size; "pvalue" sets the edges' line thickness accordingly to p-value (lower p-value corresponds to thicker line).

result

whether to return test results as a return value.

draw

whether to render the diagram.

...

other arguments that will be passed to the underlying function that performs pairwise comparisons (e.g. pairwise.t.test, pairwise.prop.test or pairwise.wilcox.test.

Details

All treatments in a set are compared in pairs using a selected statistical test. If the results form a partially ordered set, they can be viewed in a Hasse diagram.

Hasse diagram is a graph with each treatment being represented as a vertex. An edge is drawn downwards from vertex y to vertex x if and only if treatment x is significantly lower than treatment y, and there is no such treatment z that x was lower than z and z lower than y. Each edge is connected to exactly two vertices: its two endpoints. If there does not exist a path between some two treatments, it means that these two treatments are incomparable (i.e. the difference among them is not statistically significant).

The function accepts two types of inputs: either an instance of class glht or a vector obj of measured values and a factor grouping of treatments.

The glht object may be obtained from function glht of the multcomp package and set as the obj argument. Argument grouping must be NULL, in that case.

If obj is a numeric vector of measured values, grouping must not be NULL and also a type of statistical test must be selected by setting test argument.

Edge compression (introducing "dot" edges):

Sometimes, pairwise comparison tests may yield in such bipartite setting that each pair of nodes of some two node subsets would be inter-connected with an edge (without any edge between nodes in the same subset). More specifically, let U, V be two disjoint non-empty sets of edges, such that for each u from U and v from V, there exists an edge from u to v. (The number of such edges equals |U| \cdot |V|.) Starting from |U| > 2 and |V| > 2, the Hasse diagram may become too complicated and hence confusing. Therefore a compress argument exists in this function that enables “compression” of the edges in such a way that a new “dot” node w is introduced and |U| \cdot |V| edges between sets U and V are replaced with |U|+|V| edges from set U to node w and from node w to set V.

Value

If argument result is TRUE, the function returns everything that is returned by the underlying test function (pairwise.t.test, pairwise.prop.test or pairwise.wilcox.test accordingly to the test argument), or a copy of the obj argument, if obj is an instance of class glht.

Author(s)

Michal Burda

See Also

pairwise.t.test, pairwise.prop.test, pairwise.wilcox.test, glht hasse

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  # Example of test="prop":
  o <- c(rep(1, 10), rep(0, 10), rep(c(0,1), 5))
  g <- c(rep(1,10), rep(2, 10), rep(3, 10))
  paircomp(o, g, test="prop")

  # Example of test="t" and test="wilcox":
  paircomp(InsectSprays$count, InsectSprays$spray, test="t")
  paircomp(InsectSprays$count, InsectSprays$spray, test="wilcox")

  # Example of t-test with non-pooled SD and Bonferroni adjustment
  # for multiple comparisons:
  paircomp(InsectSprays$count, InsectSprays$spray, test="t",
           pool.sd=FALSE, p.adjust.method="bonferroni")

  # Compare diagrams with and without compressed edges:
  paircomp(InsectSprays$count, InsectSprays$spray, test="t",
           compress=FALSE)
  paircomp(InsectSprays$count, InsectSprays$spray, test="t",
           compress=TRUE)

  # perform Tukey test:
  library(rpart) # for car90 dataset
  library(multcomp) # for glht() function
  aovR <- aov(Price ~ Type, data = car90)
  glhtR <- glht(aovR, linfct = mcp(Type = "Tukey"))
  paircomp(glhtR)

Example output

Loading required package: Rgraphviz
Loading required package: graph
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: 'BiocGenerics'

The following objects are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from 'package:stats':

    IQR, mad, sd, var, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, cbind, colMeans, colSums, colnames, do.call,
    duplicated, eval, evalq, get, grep, grepl, intersect, is.unsorted,
    lapply, lengths, mapply, match, mget, order, paste, pmax, pmax.int,
    pmin, pmin.int, rank, rbind, rowMeans, rowSums, rownames, sapply,
    setdiff, sort, table, tapply, union, unique, unsplit, which,
    which.max, which.min

Loading required package: grid
Warning messages:
1: In prop.test(x[c(i, j)], n[c(i, j)], ...) :
  Chi-squared approximation may be incorrect
2: In prop.test(x[c(i, j)], n[c(i, j)], ...) :
  Chi-squared approximation may be incorrect
There were 15 warnings (use warnings() to see them)
Loading required package: mvtnorm
Loading required package: survival
Loading required package: TH.data
Loading required package: MASS

Attaching package: 'TH.data'

The following object is masked from 'package:MASS':

    geyser

paircompviz documentation built on Nov. 8, 2020, 6:26 p.m.