Re: [R] building random matrices from vectors of random parameters

2017-09-28 Thread Evan Cooch
Makes sense, although (re-)learning what aperm does wasn't a wasted exercise. Thanks! On 9/28/2017 1:22 PM, Jeff Newmiller wrote: > The use of aperm is unnecessary if you call array() properly. > > ms <- array(c(rep(0, 5),so,sa*m,sa), c(5, 2, 2)) [[alternative HTML version deleted]]

Re: [R] building random matrices from vectors of random parameters

2017-09-28 Thread Jeff Newmiller
The use of aperm is unnecessary if you call array() properly. ms <- array(c(rep(0, 5),so,sa*m,sa), c(5, 2, 2)) -- Sent from my phone. Please excuse my brevity. On September 28, 2017 9:10:26 AM PDT, Evan Cooch wrote: >Sure -- thanks -- only took me 3-4 attempts to get

Re: [R] building random matrices from vectors of random parameters

2017-09-28 Thread Evan Cooch
Sure -- thanks -- only took me 3-4 attempts to get aperm to work (as opposed to really thinking hard about how it works ;-) On 9/28/2017 11:55 AM, Duncan Murdoch wrote: > On 28/09/2017 9:10 AM, Evan Cooch wrote: >> Thanks for both the mapply and array approaches! However, although >> intended

Re: [R] building random matrices from vectors of random parameters

2017-09-28 Thread Duncan Murdoch
On 28/09/2017 9:10 AM, Evan Cooch wrote: Thanks for both the mapply and array approaches! However, although intended to generate the same result, they don't: # mapply approach n = 3 sa <- rnorm(n,0.8,0.1) so <- rnorm(n,0.5,0.1) m <- rnorm(n,1.2,0.1) mats = mapply(function(sa1, so1, m1)

Re: [R] building random matrices from vectors of random parameters

2017-09-28 Thread Evan Cooch
> > In fact, this is what is returned by the mapply approach, while the > array approach returns the transpose. I gather the 'missing step' is > to use aperm, but haven't figured out how to get that to work...yet. ms <- array(c(rep(0, 3),sa*m,so,sa), c(3, 2, 2)) ms_new <- aperm(ms,c(1,3,2));

Re: [R] building random matrices from vectors of random parameters

2017-09-28 Thread Evan Cooch
Thanks for both the mapply and array approaches! However, although intended to generate the same result, they don't: # mapply approach n = 3 sa <- rnorm(n,0.8,0.1) so <- rnorm(n,0.5,0.1) m <- rnorm(n,1.2,0.1) mats = mapply(function(sa1, so1, m1) matrix(c(0,sa1*m1,so1,sa1),2,2,byrow=T), sa, so,

Re: [R] building random matrices from vectors of random parameters

2017-09-28 Thread Duncan Murdoch
On 27/09/2017 8:47 PM, Evan Cooch wrote: Suppose I have interest in a matrix with the following symbolic structure (specified by 3 parameters: sa, so, m): matrix(c(0,sa*m,so,sa),2,2,byrow=T) What I can't figure out is how to construct a series of matrices, where the elements/parameters are

Re: [R] building random matrices from vectors of random parameters

2017-09-27 Thread Peter Langfelder
I would try something like n = 5 a <- rnorm(n,0.8,0.1) so <- rnorm(n,0.5,0.1) m <- rnorm(n,1.2,0.1) mats = mapply(function(sa1, so1, m1) matrix(c(0,sa1*m1,so1,sa1),2,2,byrow=T), a, so, m, SIMPLIFY = FALSE) > mats [[1]] [,1] [,2] [1,] 0.000 0.9129962 [2,]