Hello and sorry that I still haven?t found a solution for my problem. I need to extract the lower and upper triangle from a square matrix including the diagonal. This diagonal is not zero in that special case. I tried with as.dist w<-as.dist(w, diag = TRUE) > w 1 2 3 4 5 1 0 2 2 0 3 3 8 0 4 4 9 14 0 5 5 10 15 20 0 but found no way to keep the diagonal that is in the matrix. I also tried this but as I expected it makes no difference: w<-matrix(1:25, ncol=5, nrow=5) > upperTriangle(w)<-NA > w [,1] [,2] [,3] [,4] [,5] [1,] 1 NA NA NA NA [2,] 2 7 NA NA NA [3,] 3 8 13 NA NA [4,] 4 9 14 19 NA [5,] 5 10 15 20 25 > w<-as.dist(w, diag = TRUE) > w 1 2 3 4 5 1 0 2 2 0 3 3 8 0 4 4 9 14 0 5 5 10 15 20 0 Is there perhaps a possibility to give the diagonal as a vector within as.dist? I would be glad if somebody could help me. Greetings Birgit Birgit Lemcke Institut f?r Systematische Botanik Zollikerstrasse 107 CH-8008 Z?rich Switzerland Ph: +41 (0)44 634 8351 birgit.lemcke at systbot.uzh.ch
On 10/10/07, Birgit Lemcke <birgit.lemcke at systbot.uzh.ch> wrote:> Hello and sorry that I still haven?t found a solution for my problem. > > I need to extract the lower and upper triangle from a square matrix > including the diagonal. This diagonal is not zero in that special case. > I tried with as.dist > > w<-as.dist(w, diag = TRUE) > > w > 1 2 3 4 5 > 1 0 > 2 2 0 > 3 3 8 0 > 4 4 9 14 0 > 5 5 10 15 20 0 > > but found no way to keep the diagonal that is in the matrix. > > I also tried this but as I expected it makes no difference: > > w<-matrix(1:25, ncol=5, nrow=5) > > upperTriangle(w)<-NA > > w > [,1] [,2] [,3] [,4] [,5] > [1,] 1 NA NA NA NA > [2,] 2 7 NA NA NA > [3,] 3 8 13 NA NA > [4,] 4 9 14 19 NA > [5,] 5 10 15 20 25 > > w<-as.dist(w, diag = TRUE) > > w > 1 2 3 4 5 > 1 0 > 2 2 0 > 3 3 8 0 > 4 4 9 14 0 > 5 5 10 15 20 0 > > Is there perhaps a possibility to give the diagonal as a vector > within as.dist? > > I would be glad if somebody could help me. > > Greetings > > Birgit > > Birgit Lemcke > Institut f?r Systematische Botanik > Zollikerstrasse 107 > CH-8008 Z?rich > Switzerland > Ph: +41 (0)44 634 8351 > birgit.lemcke at systbot.uzh.ch >What do you want to do with the lower triangle matrix? A distance matrix must be zero on the diagonal, since dist(a,a)==0 for all a, so it cannot be distances that you measure. best, Gustaf -- Gustaf Rydevik, M.Sci. tel: +46(0)703 051 451 address:Essingetorget 40,112 66 Stockholm, SE skype:gustaf_rydevik
This are distances but between male and female plants of the same species. species A B C D E --> male A B C D | female I would like to do a Manteltest. Birgit Am 10.10.2007 um 16:59 schrieb Gustaf Rydevik:> On 10/10/07, Birgit Lemcke <birgit.lemcke at systbot.uzh.ch> wrote: >> Hello and sorry that I still haven?t found a solution for my problem. >> >> I need to extract the lower and upper triangle from a square matrix >> including the diagonal. This diagonal is not zero in that special >> case. >> I tried with as.dist >> >> w<-as.dist(w, diag = TRUE) >>> w >> 1 2 3 4 5 >> 1 0 >> 2 2 0 >> 3 3 8 0 >> 4 4 9 14 0 >> 5 5 10 15 20 0 >> >> but found no way to keep the diagonal that is in the matrix. >> >> I also tried this but as I expected it makes no difference: >> >> w<-matrix(1:25, ncol=5, nrow=5) >>> upperTriangle(w)<-NA >>> w >> [,1] [,2] [,3] [,4] [,5] >> [1,] 1 NA NA NA NA >> [2,] 2 7 NA NA NA >> [3,] 3 8 13 NA NA >> [4,] 4 9 14 19 NA >> [5,] 5 10 15 20 25 >>> w<-as.dist(w, diag = TRUE) >>> w >> 1 2 3 4 5 >> 1 0 >> 2 2 0 >> 3 3 8 0 >> 4 4 9 14 0 >> 5 5 10 15 20 0 >> >> Is there perhaps a possibility to give the diagonal as a vector >> within as.dist? >> >> I would be glad if somebody could help me. >> >> Greetings >> >> Birgit >> >> Birgit Lemcke >> Institut f?r Systematische Botanik >> Zollikerstrasse 107 >> CH-8008 Z?rich >> Switzerland >> Ph: +41 (0)44 634 8351 >> birgit.lemcke at systbot.uzh.ch >> > > What do you want to do with the lower triangle matrix? > A distance matrix must be zero on the diagonal, since dist(a,a)==0 for > all a, so it cannot be distances that you measure. > > best, > Gustaf > > > -- > Gustaf Rydevik, M.Sci. > tel: +46(0)703 051 451 > address:Essingetorget 40,112 66 Stockholm, SE > skype:gustaf_rydevikBirgit Lemcke Institut f?r Systematische Botanik Zollikerstrasse 107 CH-8008 Z?rich Switzerland Ph: +41 (0)44 634 8351 birgit.lemcke at systbot.uzh.ch
On Wed, 2007-10-10 at 16:42 +0200, Birgit Lemcke wrote:> Hello and sorry that I still haven?t found a solution for my problem. > > I need to extract the lower and upper triangle from a square matrix > including the diagonal. This diagonal is not zero in that special case.How can a site have a dissimilarity to itself greater than 0, when assessed on the same suite of variables? Even if you think it is valid, I don't see a way using objects of class "dist" as these don't even store the diagonal values, just the off-diagonal values, so there is nothing to replace after you've as.dist'd your matrix with the real diagonal values. As you say you need objects of class "dist" for some subsequent analysis, I think you are out of luck. But consider that this other analysis is likely to be assuming that the diagonals are 0, so even if you did find a way to do what you wanted, the results might not mean anything useful. G> I tried with as.dist > > w<-as.dist(w, diag = TRUE) > > w > 1 2 3 4 5 > 1 0 > 2 2 0 > 3 3 8 0 > 4 4 9 14 0 > 5 5 10 15 20 0 > > but found no way to keep the diagonal that is in the matrix. > > I also tried this but as I expected it makes no difference: > > w<-matrix(1:25, ncol=5, nrow=5) > > upperTriangle(w)<-NA > > w > [,1] [,2] [,3] [,4] [,5] > [1,] 1 NA NA NA NA > [2,] 2 7 NA NA NA > [3,] 3 8 13 NA NA > [4,] 4 9 14 19 NA > [5,] 5 10 15 20 25 > > w<-as.dist(w, diag = TRUE) > > w > 1 2 3 4 5 > 1 0 > 2 2 0 > 3 3 8 0 > 4 4 9 14 0 > 5 5 10 15 20 0 > > Is there perhaps a possibility to give the diagonal as a vector > within as.dist? > > I would be glad if somebody could help me. > > Greetings > > Birgit > > Birgit Lemcke > Institut f?r Systematische Botanik > Zollikerstrasse 107 > CH-8008 Z?rich > Switzerland > Ph: +41 (0)44 634 8351 > birgit.lemcke at systbot.uzh.ch > > ______________________________________________ > R-help at r-project.org mailing list > 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.-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%