Re: Map function with 2 variables
- To: mathgroup at smc.vnet.net
- Subject: [mg114967] Re: Map function with 2 variables
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Fri, 24 Dec 2010 04:13:35 -0500 (EST)
- References: <201012230856.DAA05031@smc.vnet.net>
On 23 Dec 2010, at 09:56, Jagra wrote: > I have a problem that comes up in a couple of situations and I've > never found the right solution. I hoped I could get an idea of how to > generally address these kinds of things. > > Say I have a function with two variables, something like a > SpearmanRankCorrelation[] from the MultiVariate Statistics package: > > I also have matrix "m" with dimensions {3, 100} > > m = RandomReal[{0, 1}, {3, 100}]; > > Now, say I want to create a correlation matrix using the > SpearmanRankCorrelation function. > > I can get the rank correlations between a single vector of the matrix > and all the other vectors like this: > > SpearmanRankCorrelation[m[[1]], #] & /@ m > > This would give me a single row in a correlation matrix. Pretty > straightforward, but now I want all 3 rows like I would get with this: > > {SpearmanRankCorrelation[m[[1]], #] & /@ m, > SpearmanRankCorrelation[m[[2]], #] & /@ m, > SpearmanRankCorrelation[m[[3]], #] & /@ m} > > There must be a way I can do this more directly. > I must be missing something simple. > > Thanks. > Needs["MultivariateStatistics`"] m = RandomReal[{0, 1}, {3, 100}]; then Function[z, (SpearmanRankCorrelation[z, #1] & ) /@ m] /@ m {{1, -(4441/27775), 763/83325}, {-(4441/27775), 1, -(7553/83325)}, {763/83325, -(7553/83325), 1}} or Outer[SpearmanRankCorrelation[#1, #2] & , m, m, 1] {{1, -(4441/27775), 763/83325}, {-(4441/27775), 1, -(7553/83325)}, {763/83325, -(7553/83325), 1}} Andrzej Kozlowski
- References:
- Map function with 2 variables
- From: Jagra <jagra24891@mypacks.net>
- Map function with 2 variables