bikemike42
2009-Nov-10 19:05 UTC
[R] All possible combinations of functions within a function
Dear All, I wrote a function for cluster analysis to compute cophenetic correlations between dissimilarity matrices (using the VEGAN library) and cluster analyses of every possible clustering algorithm (SEE ATTACHED) http://old.nabble.com/file/p26288610/cor.coef.R cor.coef.R . As it is now, it is extremely long, and for the future I was hoping to find a more efficient way of doing this sort of thing. To give you an outline of the function, first I create the dissimiarity matrices using all possible methods in the VEGAN command "vegdist", then create the clusters using all possible algorithms in "hclust" and the dissimilarity matrices I crated, then create a table, and in one column, list all combinations, and in the other, compute and put the cophenetic correlation. Any help would be appreciated! I'm pretty new to writing my own functions but I see great time-saving potential. Thanks! Mike -- View this message in context: http://old.nabble.com/All-possible-combinations-of-functions-within-a-function-tp26288610p26288610.html Sent from the R help mailing list archive at Nabble.com.
jim holtman
2009-Nov-10 19:21 UTC
[R] All possible combinations of functions within a function
Here is a hint of how you might want to do the first part. You might want to study the 'lappy' function vegList <- lapply(c('bray', ..., 'binomial'), function(.method){ vegdist(x, method=.method) }) clustList <- lapply(vegList, function(.dist){ lapply(c('average', ..., 'centroid'), function(.dist){ hclust(.veg, .dist) }) }) rest left as exercise for the reader. On Tue, Nov 10, 2009 at 2:05 PM, bikemike42 <mlt35 at tamu.edu> wrote:> > Dear All, > > I wrote a function for cluster analysis to compute cophenetic correlations > between dissimilarity matrices (using the VEGAN library) and cluster > analyses of every possible clustering algorithm (SEE ATTACHED) > http://old.nabble.com/file/p26288610/cor.coef.R cor.coef.R . ?As it is now, > it is extremely long, and for the future I was hoping to find a more > efficient way of doing this sort of thing. > > To give you an outline of the function, first I create the ?dissimiarity > matrices using all possible methods in the VEGAN command "vegdist", then > create the clusters using all possible algorithms in "hclust" and the > dissimilarity matrices I crated, then create a table, and in one column, > list all combinations, and in the other, compute and put the cophenetic > correlation. > > Any help would be appreciated! ?I'm pretty new to writing my own functions > but I see great time-saving potential. > > Thanks! > Mike > -- > View this message in context: http://old.nabble.com/All-possible-combinations-of-functions-within-a-function-tp26288610p26288610.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 Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
baptiste auguie
2009-Nov-10 19:23 UTC
[R] All possible combinations of functions within a function
Hi,>From what I understand of your code, you might find the followingconstruct useful, funs <- c("mean", "sum", "sd", "diff") x <- 1:10 lapply(funs, do.call, args=list(x)) and then working with lists rather than naming every object individually. You might find mapply useful too when you have to pass several parameters. HTH, baptiste 2009/11/10 bikemike42 <mlt35 at tamu.edu>:> > Dear All, > > I wrote a function for cluster analysis to compute cophenetic correlations > between dissimilarity matrices (using the VEGAN library) and cluster > analyses of every possible clustering algorithm (SEE ATTACHED) > http://old.nabble.com/file/p26288610/cor.coef.R cor.coef.R . ?As it is now, > it is extremely long, and for the future I was hoping to find a more > efficient way of doing this sort of thing. > > To give you an outline of the function, first I create the ?dissimiarity > matrices using all possible methods in the VEGAN command "vegdist", then > create the clusters using all possible algorithms in "hclust" and the > dissimilarity matrices I crated, then create a table, and in one column, > list all combinations, and in the other, compute and put the cophenetic > correlation. > > Any help would be appreciated! ?I'm pretty new to writing my own functions > but I see great time-saving potential. > > Thanks! > Mike > -- > View this message in context: http://old.nabble.com/All-possible-combinations-of-functions-within-a-function-tp26288610p26288610.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. >