[R] pairwise.var.test

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Sun Oct 30 23:44:46 CET 2022


Às 21:47 de 30/10/2022, Jim Lemon escreveu:
> Hi Thomas,
> I have assumed the format of your p-value matrix. This may require
> some adjustment.
> 
>    A          B          C         D           E           F
> A 1          0.7464     0.0187    0.0865      0.0122      0.4693
> B 0.7464     1          0.0358    0.1502      0.0173      0.3240
> C 0.0187     0.0358     1         0.5131      0.7185      0.0050
> D 0.0865     0.1502     0.5131    1           0.3240      0.0173
> E 0.0122     0.0173     0.7185    0.3240      1           0.0029
> F 0.4693     0.3240     0.0050    0.0173      0.0029      1
> 
> pvar.mat<-as.matrix(read.table(text=
>   "1          0.7464     0.0187    0.0865      0.0122      0.4693
>   0.7464     1          0.0358    0.1502      0.0173      0.3240
>   0.0187     0.0358     1         0.5131      0.7185      0.0050
>   0.0865     0.1502     0.5131    1           0.3240      0.0173
>   0.0122     0.0173     0.7185    0.3240      1           0.0029
>   0.4693     0.3240     0.0050    0.0173      0.0029      1",
>   stringsAsFactors=FALSE))
> rownames(pvar.mat)<-colnames(pvar.mat)<-LETTERS[1:6]
> pvar.col<-matrix(NA,nrow=6,ncol=6)
> pvar.col[pvar.mat < 1]<-"red"
> pvar.col[pvar.mat < 0.05]<-"orange"
> pvar.col[pvar.mat < 0.01]<-"green"
> library(plotrix)
> par(mar=c(6,4,4,2))
> color2D.matplot(pvar.mat,cellcolors=pvar.col,
>   main="P-values for matrix",axes=FALSE)
> axis(1,at=seq(0.5,5.5,by=1),labels=LETTERS[1:6])
> axis(2,at=seq(0.5,5.5,by=1),labels=rev(LETTERS[1:6]))
> color.legend(0,-1.3,2.5,-0.7,c("NA","NS","<0.05","<0.01"),
>   rect.col=c(NA,"red","orange","green"))
> 
> Jim
> 
> On Mon, Oct 31, 2022 at 6:34 AM Thomas Subia via R-help
> <r-help using r-project.org> wrote:
>>
>> Colleagues,
>>
>> The RVAideMemoire package has a pairwise variance test which one can use to identify variance differences between group levels.
>>
>> Using the example from this package, pairwise.var.test(InsectSprays$count,InsectSprays$spray), we get this output:
>>
>>      Pairwise comparisons using F tests to compare two variances
>>
>> data:  InsectSprays$count and InsectSprays$spray
>>
>>     A              B             C             D            E
>> B 0.7464     -               -              -              -
>> C 0.0187     0.0358     -      -       -
>> D 0.0865     0.1502     0.5131     -             -
>> E 0.0122     0.0173     0.7185     0.3240    -
>> F 0.4693     0.3240     0.0050     0.0173     0.0029
>>
>> P value adjustment method: fdr
>>
>> Is there a way to graph the pairwise variance differences so that users can easily identify the statistically significant variance differences between group levels?
>>
>> I can do this using Minitab but I'd prefer using R for this.
>>
>> Thomas Subia
>>
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Hello,

With Jim's data creation code, here is a ggplot graph.

First coerce to data.frame, then reshape to long format.
Now bin the p-values with the cutpoints 0.01, 0.05 and 1. This is dne 
with ?findInterval.

The colors are assigned in the plot code, based on the binned p.values 
above.


library(ggplot2)

pvar.mat |> as.data.frame() -> pvar.df
pvar.df$id <- row.names(pvar.df)

pvar.df |> tidyr::pivot_longer(-id, values_to = "p.value") -> pvar.long
i <- findInterval(pvar.long$p.value, c(0, 0.01, 0.05, 1))
pvar.long$p.value <- c("<0.01", "<0.05", "NS", "NA")[i]
clrs <- setNames(c("green", "blue", "lightgrey", "white"),
                  c("<0.01", "<0.05", "NS", "NA"))

ggplot(pvar.long, aes(id, name, fill = p.value)) +
   geom_tile() +
   scale_y_discrete(limits = rev) +
   scale_fill_manual(values = clrs) +
   theme_bw()


Hope this helps,

Rui Barradas



More information about the R-help mailing list