[R] pairwise.var.test

Deepayan Sarkar deep@y@n@@@rk@r @end|ng |rom gm@||@com
Wed Nov 2 08:48:22 CET 2022


On Mon, Oct 31, 2022 at 5:30 AM Thomas Subia via R-help
<r-help using r-project.org> wrote:
>
> Colleagues,
>
> Thank you all for the timely suggestions. That is appreciated.
>
> What I am really looking for a way to identify difference in group level variance by using multiple comparison intervals. Minitab displays those results in a graph.
>
> This method is described in:
> https://support.minitab.com/en-us/minitab/20/media/pdfs/translate/Multiple_Comparisons_Method_Test_for_Equal_Variances.pdf
>
> I was hoping that R had something similar.

Perhaps you are looking for something like the plot produced by

example(TukeyHSD)

For this you would need confidence intervals for each pairwise
comparison, not just the p-values. Once you have those, recreating the
plot should not be difficult, but I don't know if there is any package
that already does this for you. E.g., car::leveneTest() etc. are
designed for multiple groups and won't give you confidence intervals.

Best,
-Deepayan

>
> I tried a Google search on this but to no avail.
>
> Thomas Subia
>
>
>
>
>
>
> On Sunday, October 30, 2022 at 03:44:54 PM PDT, Rui Barradas <ruipbarradas using sapo.pt> wrote:
>
>
>
>
>
> À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
>
> ______________________________________________
> 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.



More information about the R-help mailing list