An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090603/34162f42/attachment-0001.pl>
Using WinBUGS from R: A Multi-Way Array Problem
2 messages · Khurram Nadeem, Greg Snow
Your output example below looks the same as the input. But I think the 'aperm' function may be what you are looking for, read its help page and run the example to see if that will work for you.
Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111 > -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Khurram Nadeem > Sent: Wednesday, June 03, 2009 11:37 PM > To: r-help at r-project.org > Subject: [R] Using WinBUGS from R: A Multi-Way Array Problem > > Please suggest a way out to the following problem. > > I have a T by n data matrix (say Y) where coulmns are time series of > length > T. > To do some analysis in WinBUGS I need to construct my data as follows. > > yy<-rep(Y,k) ## this will be a vector > Yk<-array(yy,dim=c(T,n,k)) ## data array > > Here the definition of dim indices is > > first index: T rows > second index: n columns > third index: for kth T by n array > > EXAMPLE > T=3 > n=2 > k=2 > Y<-matrix(c(1,2,3,4,5,6), ncol=n) ## my data matrix > yy<-rep(Y,k) > Yk<-array(yy,dim=c(T,n,k)) > Yk # this produces the following R output. > > , , 1 > [,1] [,2] > [1,] 1 4 > [2,] 2 5 > [3,] 3 6 > , , 2 > [,1] [,2] > [1,] 1 4 > [2,] 2 5 > [3,] 3 6 > > That is, I have copied the orignal data k=2 times. WinBUGS will be > supplied > the following data > > d<-list(Yk=Yk, T=T,n=n,k=k). > > Now in WinBUGS I have to define a multivariate stochastic node as as > follows > > e[i,1:n,kk]~dmnorm( , ) ## i= 1,2,...,T ; kk = 1,2,...,k > > But Winbugs accepts only something like > > e[ , , 1:n]~dmnorm( , ). > > That is "1:n" has to be given at the leftmost position. > > This means that I need to change the definition of dim indices in R as > follows. > > first index: for kth T by n array > second index: T rows > third index: n columns. > > Specifically, I want the above output as > > 1, , > [,1] [,2] > [1,] 1 4 > [2,] 2 5 > [3,] 3 6 > > 2, , > [,1] [,2] > [1,] 1 4 > [2,] 2 5 > [3,] 3 6 > > I would appriciate any help in this regard. > > > Khurram Nadeem > PhD Student > Department of Math. & Stat. Sciences > University of Alberta > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.