An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20101230/6163539f/attachment.pl>
Silhouette function problem
5 messages · David Winsemius, jim holtman, ADias
ADias wrote:
Hi, I am using the code below to get a plot that will show me on the X axis the number of clusters and on the Y axis the cluster average widths. However I am getting this error: Error in summary(silhouette(cutree(d, x), dist(iris[, -5])))$si.summary : $ operator is invalid for atomic vectors the code I am using is: avgs<-sapply(1:20,function(x) summary(silhouette(cutree(d,x), dist(iris[,-5])))$si.summary[4]) I think the problem is on the si.summary. What can I do to solve this problem? thank you Regards, A Dias.
Hi, I have made this script library(cluster) d<-hclust(dist(iris[,-5])) avgs<-sapply(1:20,function(x) summary(silhouette(cutree(d,x), dist(iris[,-5])))) str(avgs) I need $ avg.width but I don't know how to take that out from the object avgs. The mode from avgs is "list" but it does not work as a normal list. Any help would be apreciated. thanks A. Dias
View this message in context: http://r.789695.n4.nabble.com/Silhouette-function-problem-tp3169027p3169522.html Sent from the R help mailing list archive at Nabble.com.
On Dec 31, 2010, at 10:34 AM, ADias wrote:
ADias wrote:
Hi, I am using the code below to get a plot that will show me on the X axis the number of clusters and on the Y axis the cluster average widths. However I am getting this error: Error in summary(silhouette(cutree(d, x), dist(iris[, -5]))) $si.summary : $ operator is invalid for atomic vectors the code I am using is: avgs<-sapply(1:20,function(x) summary(silhouette(cutree(d,x), dist(iris[,-5])))$si.summary[4]) I think the problem is on the si.summary. What can I do to solve this problem? thank you Regards, A Dias.
Hi, I have made this script library(cluster) d<-hclust(dist(iris[,-5])) avgs<-sapply(1:20,function(x) summary(silhouette(cutree(d,x), dist(iris[,-5])))) str(avgs) I need $ avg.width but I don't know how to take that out from the object avgs.
Do these examples of accessing <something> resembling what you are
asking in that object help?
> avgs[[2]]$clus.avg.widths
1 2
0.3861393 0.6566469
> avgs[[7]]$clus.avg.widths
1 2 3 4 5 6 7
0.3489107 0.2389611 0.2380363 0.3753805 0.6617769 0.4456561 0.3185074
The mode from avgs is "list" but it does not work as a normal list.
What do you meant when you write "it does not work as a normal list"?
Admittedly it is a name-less list, which seems a bit non-traditional,
but accessing as avgs[[1]] or avgs[[2]] gives appropriate values. (And
_you_ are the one responsible for creating this nameless object.) If
you just look at the beginning of the str results:
> str(avgs)
List of 20
$ :Classes 'summaryDefault', 'table' Named chr [1:2] "logical" "1"
.. ..- attr(*, "names")= chr [1:2] "Mode" "NA's"
$ :List of 7
..$ si.summary :Classes 'summaryDefault', 'table' Named num
[1:6] -0.435 0.561 0.657 0.516 0.687 ...
.. .. ..- attr(*, "names")= chr [1:6] "Min." "1st Qu." "Median"
"Mean" ...
<snipped remainder of output>
You can then access the first leaf of the second element:
avgs[[2]]$si.summary
Min. 1st Qu. Median Mean 3rd Qu. Max.
-0.4349 0.5615 0.6574 0.5160 0.6867 0.7525
David. > > Any help would be apreciated. > > thanks > A. Dias > -- > View this message in context: http://r.789695.n4.nabble.com/Silhouette-function-problem-tp3169027p3169522.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. David Winsemius, MD West Hartford, CT
Is this what you want:
library(cluster) d<-hclust(dist(iris[,-5])) avgs<-sapply(1:20,function(x)
+ summary(silhouette(cutree(d,x), + + dist(iris[,-5]))))
# str(avgs)
# print out the average widths
for (i in 2:length(avgs)){ # ignore first item
+ cat('i=', i, 'average=', avgs[[i]]$avg.width, '\n')
+ }
i= 2 average= 0.515983
i= 3 average= 0.5135953
i= 4 average= 0.4998128
i= 5 average= 0.346174
i= 6 average= 0.3382031
i= 7 average= 0.3297649
i= 8 average= 0.324025
i= 9 average= 0.3191681
i= 10 average= 0.3028503
i= 11 average= 0.3072648
i= 12 average= 0.2834498
i= 13 average= 0.2776717
i= 14 average= 0.2855396
i= 15 average= 0.2745142
i= 16 average= 0.2578903
i= 17 average= 0.2531909
i= 18 average= 0.2473504
i= 19 average= 0.2484205
i= 20 average= 0.2545357
On Fri, Dec 31, 2010 at 10:34 AM, ADias <diasandre at gmail.com> wrote:
ADias wrote:
Hi, I am using the code below to get a plot that will show me on the X axis the number of clusters and on the Y axis the cluster average widths. However I am getting this error: Error in summary(silhouette(cutree(d, x), dist(iris[, -5])))$si.summary : ? $ operator is invalid for atomic vectors the code I am using is: avgs<-sapply(1:20,function(x) summary(silhouette(cutree(d,x), dist(iris[,-5])))$si.summary[4]) I think the problem is on the si.summary. What can I do to solve this problem? thank you Regards, A Dias.
Hi, I have made this script library(cluster) d<-hclust(dist(iris[,-5])) avgs<-sapply(1:20,function(x) summary(silhouette(cutree(d,x), dist(iris[,-5])))) str(avgs) I need $ avg.width ?but I don't know how to take that out from the object avgs. The mode from avgs is "list" but it does not work as a normal list. Any help would be apreciated. thanks A. Dias -- View this message in context: http://r.789695.n4.nabble.com/Silhouette-function-problem-tp3169027p3169522.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ 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.
Jim Holtman Data Munger Guru What is the problem that you are trying to solve?
Hello, thank you all. I have been able to solve my problem with your help. The problem I am trying to solve is: I am working on a clustering method to group a data base. At the moment I am using the clustering hierarchical method and trying to get to the best K group value via the silhouette function. My database has 569 observations and the dendogram is not readable as you can see on the picture attached. So I am trying to find a way to get to a conclusion without the use of the dendogram. thanks again, Regards, A.Dias http://r.789695.n4.nabble.com/file/n3169962/dendogram.jpeg
View this message in context: http://r.789695.n4.nabble.com/Silhouette-function-problem-tp3169027p3169962.html Sent from the R help mailing list archive at Nabble.com.