# [R] Pairwise testing with pairwise.prop.test

David L Carlson dc@r|@on @end|ng |rom t@mu@edu
Mon Apr 1 17:53:37 CEST 2019

```Inline

----------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77843-4352

-----Original Message-----
> From: R-help <r-help-bounces using r-project.org> On Behalf Of Jenny Liu
> Sent: Sunday, March 31, 2019 6:10 PM
> To: r-help using r-project.org
> Subject: [R] Pairwise testing with pairwise.prop.test
>
> Hi all,
>
> I have a few questions about the pairwise.prop.test function.
> I run the test using on the attached dataset (EggMortNoTemp) using the following
> code:
> EggMatrix<-as.matrix(EggMortNoTemp) #making the egg mortality data a matrix.
> pairwise.prop.test needs it to be a matrix
> EggResults<-pairwise.prop.test(EggMatrix) EggResults
> I get the attached result (EggResults).
> My questions:1) Why is there a "-" instead of a numerical result for pairs 1-2,
> 1-16, and 2-16?

When the difference between the pair is zero, the p.value is NaN (not a number).

> 2) Is there an easy way to export/convert the result to a list with two columns
> instead of the matrix? Column 1 would be the pair being compared, and column 2
> would be the p-value. For example, Column 1 would say "6-8" so column 2 would
> say "0.9532".

Fairly easy:

idx <- expand.grid(2:16, 1:15)
pair <- as.matrix(idx[idx[,1] > idx[,2], ])
mode(pair) <- "character"
comp <- apply(pair, 1, paste0, collapse="-")
tbl <- data.frame(comp, p.value=EggResults\$p.value[pair])
#   comp      p.value
# 1  2-1          NaN
# 2  3-1 2.706354e-24
# 3  4-1 1.487240e-23
# 4  5-1 1.946384e-31
# 5  6-1 4.888537e-25
# 6  7-1 7.683167e-41

> 3) Is there a way to assign the numbers to the treatment group that they were
> originally in? For example, "1" in the result should be "3", indicating that
> that was the temperature the experiment took place at. Pairwise.prop.test
> doesn't seem to accept matrices with more than 2 columns.

No. The test is to do the pairwise comparisons between the samples. The treatment group is not considered. You would have to use another test that compared the samples by treatment group (instead of pairwise comparisons).

> Any help would be greatly appreciated! Thank you in advance.
> Cheers,Jenny

```