Hi Kamila,

sounds like you want to treat the integers categorically, in which case for 
neighbour joining you could try generating a distance matrix using Gower 
dissimilarity (e.g. using function 'daisy' in Cluster). If you specify that the 
data are factors, the function automatically treats them as nominal variables.

> require(cluster)
> DATA <- matrix(data=c(0,1,2,3,3,1,2,2,4,3,2,2,5,5,4,1,2,5,5,5), nrow=4, 
> ncol=5, byrow=TRUE)
> rownames(DATA) <- c("species1", "species2", "species3", "species4")
> colnames(DATA) <- c("f1", "f2", "f3", "f4", "f5")
> DATA
         f1 f2 f3 f4 f5
species1  0  1  2  3  3
species2  1  2  2  4  3
species3  2  2  5  5  4
species4  1  2  5  5  5
> FUNCx <- function(x) as.factor(x)
> DATA2 <- as.data.frame(apply(DATA, 2, FUNCx))
> DAISY <- daisy(DATA2)
> DAISY
Dissimilarities :
         species1 species2 species3
species2      0.6                  
species3      1.0      0.8         
species4      1.0      0.6      0.4

Metric :  mixed ;  Types = N, N, N, N, N 
Number of objects : 4
> require(ape)
> plot(nj(DAISY))


Cheers,
Greg Guerin

----------------------------------------------------------------------

Message: 1
Date: Wed, 29 May 2013 15:21:07 +0000
From: "Naxerova, Kamila" <[email protected]>
To: "[email protected]" <[email protected]>
Subject: [R-sig-phylo] "equal or not" distance function for NJ
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="us-ascii"

Dear list,

I would like to construct a neighbor-joining tree from a data set in which each 
taxon is characterized by a vector of integers ranging from 0 to 5. I would 
like to treat these as unordered characters, i.e. assuming that the likelihood 
of transitioning from 0 to 1 is the same as transitioning from 0 to 5. For 
this, I would need some kind of "equal or not" distance function which 
increases the distance between two taxa by one for each dimension that differs, 
regardless of its magnitude.

Is such a distance function already implemented anywhere or is it easiest to 
create one for myself?

Many thanks.
Kamila


------------------------------

_______________________________________________
R-sig-phylo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo


End of R-sig-phylo Digest, Vol 64, Issue 20
*******************************************

_______________________________________________
R-sig-phylo mailing list - [email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/[email protected]/

Reply via email to