r - How to load arrays with 3 dimension using R2WinBUGS? -
since winbugs , r have different ways of organizing data arrays, how should organize data when using r2winbugs order correct? thanks!
you shouldn't have worry r2winbugs if specify data named list of objects (see ?bugs - data argument). r2winbugs reorganize data structure in winbugs same in r.
for example, if specify array in r:
y <- array(1:24,dim=c(2,3,4))
which looks like
> y , , 1 [,1] [,2] [,3] [1,] 1 3 5 [2,] 2 4 6 , , 2 [,1] [,2] [,3] [1,] 7 9 11 [2,] 8 10 12 , , 3 [,1] [,2] [,3] [1,] 13 15 17 [2,] 14 16 18 , , 4 [,1] [,2] [,3] [1,] 19 21 23 [2,] 20 22 24
and specify in data argument of bugs
function (e.g., bugs(data=list(y=y)...
) data winbugs (data.txt) is:
list(y= structure(.data= c(1.00000e+00, 7.00000e+00, 1.30000e+01, 1.90000e+01, 3.00000e+00, 9.00000e+00, 1.50000e+01, 2.10000e+01, 5.00000e+00, 1.10000e+01, 1.70000e+01, 2.30000e+01, 2.00000e+00, 8.00000e+00, 1.40000e+01, 2.00000e+01, 4.00000e+00, 1.00000e+01, 1.60000e+01, 2.20000e+01, 6.00000e+00, 1.20000e+01, 1.80000e+01, 2.40000e+01), .dim=c(2, 3, 4)))
which looks in winbugs:
y[1,1,1] 1.0 y[1,1,2] 7.0 y[1,1,3] 13.0 y[1,1,4] 19.0 y[1,2,1] 3.0 y[1,2,2] 9.0 y[1,2,3] 15.0 y[1,2,4] 21.0 y[1,3,1] 5.0 y[1,3,2] 11.0 y[1,3,3] 17.0 y[1,3,4] 23.0 y[2,1,1] 2.0 y[2,1,2] 8.0 y[2,1,3] 14.0 y[2,1,4] 20.0 y[2,2,1] 4.0 y[2,2,2] 10.0 y[2,2,3] 16.0 y[2,2,4] 22.0 y[2,3,1] 6.0 y[2,3,2] 12.0 y[2,3,3] 18.0 y[2,3,4] 24.0
Comments
Post a Comment