Skip to content

Display of 3d arrays

5 messages · Ben Bolker, Malerba Giovanni, Peter Dalgaard +1 more

#
Hi!

Is it possible to display a 3d array as
an RGB image? For example, given the following 
array:
, , 1

     [,1] [,2] [,3] [,4] [,5]
[1,]  170  174  173  172  161
[2,]  171  178  174  166  149
[3,]  168  174  173  166  156
[4,]  171  170  173  166  164
[5,]  167  170  170  171  169

, , 2

     [,1] [,2] [,3] [,4] [,5]
[1,]  138  131  128  128  125
[2,]  138  127  129  122  134
[3,]  144  131  130  127  132
[4,]  142  138  130  131  129
[5,]  146  141  135  129  131

, , 3

     [,1] [,2] [,3] [,4] [,5]
[1,]  124  123  127  125  125
[2,]  125  126  126  126  123
[3,]  127  123  125  128  128
[4,]  123  121  125  125  126
[5,]  118  122  124  126  125

the first row would be diplayed with rgb colors matriz3d[1,1:5,]

(170 138 124) (174 131 123) (173 128 127) (172 128 125) (161 125 125)


Thanks

Agus

Dr. Agustin Lobo
Instituto de Ciencias de la Tierra (CSIC)
Lluis Sole Sabaris s/n
08028 Barcelona SPAIN
tel 34 93409 5410
fax 34 93411 0012
alobo at ija.csic.es


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
This isn't quite a perfect solution but you might be able to make it
work:

## data
x <- c(170,174,173,172,161,
171,178,174,166,149,
168,174,173,166,156,
171,170,173,166,164,
167,170,170,171,169,
138,131,128,128,125,
138,127,129,122,134,
144,131,130,127,132,
142,138,130,131,129,
146,141,135,129,131,
124,123,127,125,125,
125,126,126,126,123,
127,123,125,128,128,
123,121,125,125,126)

## reshape data to your specifications
y <- array(x,dim=c(5,5,3))
z <- aperm(y,c(2,1,3))

## color matrix from array
colmat <- apply(z/256,c(1,2),function(z)do.call("rgb",as.list(z)))


## hack -- fake image() into plotting specific colors
cols <- as.vector(colmat)
image(matrix(1:length(colmat),nrow=nrow(colmat)),col=cols)

## test
tstarr <- array(c(256,256,0,0,0,0,256,256,0,256,256,0),
                dim=c(2,2,3))
tstarr
colmat <- apply(tstarr/256,c(1,2),function(z)do.call("rgb",as.list(z)))
cols <- as.vector(colmat)
image(matrix(1:length(colmat),nrow=nrow(colmat)),col=cols)
On Sun, 26 Aug 2001, Agustin Lobo wrote:

            

  
    
#
Hi all,
I would like to estimate the sample size I need to perform some
studies. I 'll will compare 2 groups (A and B) for several quantitative
traits. I saw that R has power.t.test() function to compute the
estimation. My concern is that I know that N_group_A = 3 * N_group_B in
terms of size (and not N_group_A = N_group_B). Is there a way, using R, to
estimate the sample size I need, given that I know the ratio between size of group
A and group B?
Thank you,
Giovanni Malerba



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Malerba Giovanni <bobo at medgen.univr.it> writes:
There's no trivial way, but it wouldn't be hard to modify the existing
power.t.test to do it. The crucial bit is

    p.body <- quote({
        nu <- (n - 1) * tsample
        pt(qt(sig.level/tside, nu, lower = FALSE), nu, ncp = sqrt(n/tsample) * 
            delta/sd, lower = FALSE)
    })

for your purposes, nu should be (n-1+3*n-1) == (4*n - 2)
and the noncentrality in the ncp argument is sqrt(1/(1/n+1/(3*n)))*delta/sd
== sqrt(3*n/4)*delta/sd

(Make sure you check this on paper first. It is terribly easy to get
it slightly wrong in an email.)

For reasonably large groups, the exact calculation of degrees of
freedom is unimportant, and it should work to increase the delta by a
factor of sqrt(3/2) and get a conservative estimate of n (which will
be the number in the smaller group then).
#
Thanks Ben,

An improvement would be indexing the colors,
as often there will be fewer colors than cells.

For example:

tstarr <-
array(rep(c(0,0,0,0,200,200,200,200,250,250,250,250),12*3*3),dim=c(8,3,3))
colmat <- apply(tstarr/256,c(1,2),function(z)do.call("rgb",as.list(z)))
cols <- as.vector(unique(colmat))
                  ^^^^^^
and use (for this example):
cbind(c(rep(1,4),rep(2,4)),c(rep(3,4),rep(1,4)),c(rep(2,4),rep(3,4)))

in  image() instead of:
matrix(1:length(colmat),nrow=nrow(colmat))

The question now is to find a general way of selecting and 
indexing the unique triplets.

Agus

Dr. Agustin Lobo
Instituto de Ciencias de la Tierra (CSIC)
Lluis Sole Sabaris s/n
08028 Barcelona SPAIN
tel 34 93409 5410
fax 34 93411 0012
alobo at ija.csic.es
On Mon, 27 Aug 2001 ben at zoo.ufl.edu wrote:

            
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._