Nevil Amos
2011-Dec-03 07:26 UTC
[R] partial mantel tests in ecodist with intential NA values.
I would like to perform partial mantel tests on only within group values, with "between group" values assigned to NA. This is possible in package ncf partial.mantel.test, however this sues a different permutation to that used in ecodist.ecodist will not accept data with NA values, returning a "matrix is not square error. is it possible to perform this test in ecodist? many thanks Nevil Amos> library(ecodist) > library(ncf) > x<-sample(1:1000,20) > y<-sample(1:1000,20) > z<-sample(1:1000,20) > M1<-as.matrix( distance(x)) > M2 <-as.matrix( distance(y )) > M3<-as.matrix( distance(z )) > D1<-(lower(M1)) > D2<-(lower(M2)) > D3<-(lower(M3)) > mantel(D1 ~ D2+D3, nperm=1000)mantelr pval1 pval2 pval3 llim.2.5% ulim.97.5% 0.09014696 0.10300000 0.89800000 0.18400000 0.01857311 0.18468621> partial.mantel.test(M1,M2,M3,quiet=T)$MantelR r12 r13 r23 r12.3 r13.2 0.08977575 0.02170997 -0.01561346 0.09014696 0.02320821 $p [1] 0.09590410 0.30769231 0.47552448 0.09490509 0.30169830 $call [1] "partial.mantel.test(M1 = M1, M2 = M2, M3 = M3, quiet = T)" attr(,"class") [1] "partial.Mantel"> M1[1:10,11:20]<-NA > M1[11:20,1:10]<-NA > D1<-(lower(M1)) > mantel(D1 ~ D2+D3, nperm=1000)Error in mantel(D1 ~ D2 + D3, nperm = 1000) : Matrix not square.> partial.mantel.test(M1,M2,M3,quiet=T)$MantelR r12 r13 r23 r12.3 r13.2 0.054906562 0.003446670 -0.015613460 0.054967403 0.004310979 $p [1] 0.2837163 0.4275724 0.4555445 0.2857143 0.4235764 $call [1] "partial.mantel.test(M1 = M1, M2 = M2, M3 = M3, quiet = T)" attr(,"class") [1] "partial.Mantel" Warning message: In partial.mantel.test(M1, M2, M3, quiet = T) : Missing values exist; Pairwise deletion will be used
Sarah Goslee
2011-Dec-03 12:01 UTC
[R] partial mantel tests in ecodist with intential NA values.
It is not possible in ecodist, and I'd be wary of doing it in other packages. Instead, I would consider the model matrix approach described in Legendre and Fortin 1989. Sarah On Saturday, December 3, 2011, Nevil Amos <nevil.amos@gmail.com> wrote:> I would like to perform partial mantel tests on only within groupvalues, with "between group" values assigned to NA.> This is possible in package ncf partial.mantel.test, however this sues adifferent permutation to that used in ecodist.ecodist will not accept data with NA values, returning a "matrix is not square error.> > is it possible to perform this test in ecodist? > > many thanks > > Nevil Amos > >> library(ecodist) >> library(ncf) >> x<-sample(1:1000,20) >> y<-sample(1:1000,20) >> z<-sample(1:1000,20) >> M1<-as.matrix( distance(x)) >> M2 <-as.matrix( distance(y )) >> M3<-as.matrix( distance(z )) >> D1<-(lower(M1)) >> D2<-(lower(M2)) >> D3<-(lower(M3)) >> mantel(D1 ~ D2+D3, nperm=1000) > mantelr pval1 pval2 pval3 llim.2.5% ulim.97.5% > 0.09014696 0.10300000 0.89800000 0.18400000 0.01857311 0.18468621 >> partial.mantel.test(M1,M2,M3,quiet=T) > $MantelR > r12 r13 r23 r12.3 r13.2 > 0.08977575 0.02170997 -0.01561346 0.09014696 0.02320821 > > $p > [1] 0.09590410 0.30769231 0.47552448 0.09490509 0.30169830 > > $call > [1] "partial.mantel.test(M1 = M1, M2 = M2, M3 = M3, quiet = T)" > > attr(,"class") > [1] "partial.Mantel" >> M1[1:10,11:20]<-NA >> M1[11:20,1:10]<-NA >> D1<-(lower(M1)) >> mantel(D1 ~ D2+D3, nperm=1000) > Error in mantel(D1 ~ D2 + D3, nperm = 1000) : Matrix not square. >> partial.mantel.test(M1,M2,M3,quiet=T) > $MantelR > r12 r13 r23 r12.3 r13.2 > 0.054906562 0.003446670 -0.015613460 0.054967403 0.004310979 > > $p > [1] 0.2837163 0.4275724 0.4555445 0.2857143 0.4235764 > > $call > [1] "partial.mantel.test(M1 = M1, M2 = M2, M3 = M3, quiet = T)" > > attr(,"class") > [1] "partial.Mantel" > Warning message: > In partial.mantel.test(M1, M2, M3, quiet = T) : > Missing values exist; Pairwise deletion will be used > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. >-- Sarah Goslee http://www.stringpage.com http://www.sarahgoslee.com http://www.functionaldiversity.org [[alternative HTML version deleted]]