Birgitle
2008-Sep-02 10:02 UTC
[R] cluster a distance(analogue)-object using agnes(cluster)
I try to perform a clustering using an existing dissimilarity matrix that I calculated using distance (analogue) I tried two different things. One of them worked and one not and I don`t understand why. Here the code: not working example library(cluster) library(analogue) iris2<-as.data.frame(iris) str(iris2) 'data.frame': 150 obs. of 5 variables: $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ... $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ... $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ... $ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ... Test.Gower <- distance(iris2, method ="mixed") Test.Gower.agnes<-agnes(Test.Gower, diss=T) Fehler in agnes(Test.Gower, diss = T) : (list) Objekt kann nicht nach 'logical' umgewandelt werden Error in agnes(Test.Gower, diss=T). (list) object can`t be transformed to "logical" working example only numerics used: library(cluster) library(analogue) irisPart<-subset(iris, select= Sepal.Length:Petal.Width) Dist.Gower <- distance(irisPart, method ="mixed") AgnesA <- agnes(Dist.Gower, method="average", diss=TRUE) Would be great if somebody could help me. The dataset that I would like to use for the clustering also contains factors. and gives me the same Error message as in the not working example. Thanks in advance B. ----- The art of living is more like wrestling than dancing. (Marcus Aurelius) -- View this message in context: http://www.nabble.com/cluster-a-distance%28analogue%29-object-using-agnes%28cluster%29-tp19267349p19267349.html Sent from the R help mailing list archive at Nabble.com.
Birgitle
2008-Sep-03 12:33 UTC
[R] cluster a distance(analogue)-object using agnes(cluster)
Hello R-User! I still would be happy about an answer. Further explanation: I use distance(analogue), because I can give there a different weighting to my used variables. I would be interested, if there is the information in my Dissimilarity matrix, that I used also factors and if this prevents agnes(cluster) to perform a clustering? Thanks again B. Birgitle wrote:> > I try to perform a clustering using an existing dissimilarity matrix that > I calculated using distance (analogue) > I tried two different things. One of them worked and one not and I don`t > understand why. > Here the code: > > not working example > > library(cluster) > library(analogue) > > iris2<-as.data.frame(iris) > str(iris2) > 'data.frame': 150 obs. of 5 variables: > $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... > $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ... > $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ... > $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ... > $ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 > 1 1 1 1 ... > > Test.Gower <- distance(iris2, method ="mixed") > Test.Gower.agnes<-agnes(Test.Gower, diss=T) > Fehler in agnes(Test.Gower, diss = T) : > (list) Objekt kann nicht nach 'logical' umgewandelt werden > Error in agnes(Test.Gower, diss=T). > (list) object can`t be transformed to "logical" > > working example only numerics used: > > library(cluster) > library(analogue) > > irisPart<-subset(iris, select= Sepal.Length:Petal.Width) > Dist.Gower <- distance(irisPart, method ="mixed") > AgnesA <- agnes(Dist.Gower, method="average", diss=TRUE) > > Would be great if somebody could help me. > The dataset that I would like to use for the clustering also contains > factors. > and gives me the same Error message as in the not working example. > > Thanks in advance > > B. > > > > > >----- The art of living is more like wrestling than dancing. (Marcus Aurelius) -- View this message in context: http://www.nabble.com/cluster-a-distance%28analogue%29-object-using-agnes%28cluster%29-tp19267349p19288302.html Sent from the R help mailing list archive at Nabble.com.
Martin Maechler
2008-Sep-04 09:28 UTC
[R] cluster a distance(analogue)-object using agnes(cluster)
>>>>> "B" == Birgitle <birgit.lemcke at systbot.uzh.ch> >>>>> on Tue, 2 Sep 2008 03:02:31 -0700 (PDT) writes:B> I try to perform a clustering using an existing dissimilarity matrix that I B> calculated using distance (analogue) B> I tried two different things. One of them worked and one not and I don`t B> understand why. B> Here the code: B> not working example B> library(cluster) B> library(analogue) B> iris2 <- as.data.frame(iris) why that? After the above, iris2 is identical() to iris ! B> str(iris2) B> 'data.frame': 150 obs. of 5 variables: B> $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... B> $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ... B> $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ... B> $ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ... B> $ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 B> 1 1 1 ... B> Test.Gower <- distance(iris2, method ="mixed") why not just daisy(iris2, metric = "gower") daisy() is in cluster which has been a recommended R package "forever". So the solution (here, not in general!) is to stay with package 'cluster' and use daisy() before agnes(). Regards, Martin Maechler, ETH Zurich {same city! feel free to phone me..} B> Test.Gower.agnes<-agnes(Test.Gower, diss=T) B> Fehler in agnes(Test.Gower, diss = T) : B> (list) Objekt kann nicht nach 'logical' umgewandelt werden B> Error in agnes(Test.Gower, diss=T). B> (list) object can`t be transformed to "logical" B> working example only numerics used: B> library(cluster) B> library(analogue) B> irisPart<-subset(iris, select= Sepal.Length:Petal.Width) B> Dist.Gower <- distance(irisPart, method ="mixed") B> AgnesA <- agnes(Dist.Gower, method="average", diss=TRUE) B> Would be great if somebody could help me. B> The dataset that I would like to use for the clustering also contains B> factors. B> and gives me the same Error message as in the not working example. B> Thanks in advance B> B.