[R] Descriptive statistics for tables
Dave Roberts
droberts at montana.edu
Fri Sep 30 19:33:52 CEST 2005
If I understand the request, he wants to take a large number of matrices
of identical size and stack them into a three dimentional array, and
then calculate statistics on the the third dimension. If the multiple
arrays have object names they can be combined into a 3-d array
> a <- matrix(rep(1,9),ncol=3)
> b <- matrix(rep(2,9),ncol=3)
> c <- matrix(rep(3,9),ncol=3)
> z <- array(c(a,b,c),dim=c(3,3,3))
> z
, , 1
[,1] [,2] [,3]
[1,] 1 1 1
[2,] 1 1 1
[3,] 1 1 1
, , 2
[,1] [,2] [,3]
[1,] 2 2 2
[2,] 2 2 2
[3,] 2 2 2
, , 3
[,1] [,2] [,3]
[1,] 3 3 3
[2,] 3 3 3
[3,] 3 3 3
and then specific dimensions can be summarized
> mean(z[1,1,])
[1] 2
> sd(z[1,1,])
[1] 1
I don't know of any easy way to combine all the 2-d matrices other than
listing them by name in a c() function in the array statement. If they
were cleverly names perhaps a for loop could be used.
Dave
Jean Eid wrote:
> I do not totally understand your question as well. You seem to want a
> descriptive statistic about a unitary number. What is the sd of a number?
> or any other descriptive statictic. Maybe you mean for the columns or rows
> or it could be that these are t-stats or z-stats that you need to get
> p_values for them. In any case what I would do assuming that these tables
> are in your env is the following
>
> sapply(ls(), function(x){
> nam <- paste(x,"_summary", sep="")
> tt <- colMeans(get(x))
> assign(nam, tt, pos=1)})
>
> The function above will output a number of tables with their original name
> an extension _summary which contains the column means of the tables.
>
> If you have the tables in different files on your box you need to add a
> read.table line above. and the function becomes
>
> sapply(dir(), function(x){
>
> nam <- paste(x,"_summary", sep="")
> assign(x, read.table(x))
> tt <- colMeans(x)
> assign(nam, tt, pos=1)})
>
>
> HTH
>
>
> On Fri, 30 Sep 2005, DAVID CAMACHO wrote:
>
>
>>Thanks for your response,
>>
>>What I need is extremely simple. And I suppose there
>>are so many way to do it.
>>But as I have so many files to do it, I am looking for
>>the simplest way (if possible)
>>
>>What I meant was that I have tables with the same
>>numbers of rows and columns, (square form, should I
>>say?) like:
>>
>>2,5,7
>>3,4,8
>>2,9,3
>>
>>5,3,8
>>2,5,5
>>5,7,8
>>
>>But I have hundreds of this onces, (bigger once).
>>Every one of this tables have the same size (columns,
>>rows). And I want to obtain the sd, z-score, and
>>p-value for the position [1,1], [1,2]....
>>[2,1],[2,2]... etc etc. That is, to obtain a table
>>with some simple descriptive statistics about all this
>>tables.
>>I have try different methods, but I am no familiar
>>with R. (by the way, I could not find the way to do
>>loops with R)
>>Any suggestion is welcome.
>>David
>>
>>
>>
>>
>>
>>--- Berton Gunter <gunter.berton at gene.com> wrote:
>>
>>
>>>I don't know what a "quadratic, same size" table is
>>>or what you mean. If you
>>>do not get a satisfactory reply I suggest:
>>>
>>>1. Read and follow the posting guide at the end of
>>>this message.
>>>
>>>2. In particular, provide a simple, reproducible
>>>example to show what you
>>>want to do and perhaps any error messages that you
>>>may have received.
>>>
>>>
>>>-- Bert Gunter
>>>Genentech Non-Clinical Statistics
>>>South San Francisco, CA
>>>
>>>
>>>
>>>>-----Original Message-----
>>>>From: r-help-bounces at stat.math.ethz.ch
>>>>[mailto:r-help-bounces at stat.math.ethz.ch] On
>>>
>>>Behalf Of DAVID CAMACHO
>>>
>>>>Sent: Thursday, September 22, 2005 9:10 AM
>>>>To: r-help at stat.math.ethz.ch
>>>>Subject: [R] Descriptive statistics for tables
>>>>
>>>>
>>>>I have a lot (more than one hundred) of files with
>>>
>>>tables of
>>>
>>>>the same kind (quadratic, same size) and I want to
>>>
>>>obtain
>>>
>>>>some statistics for every position on them.
>>>
>>>Therefore, as a
>>>
>>>>result I want another table. I import every table,
>>>
>>>and create
>>>
>>>>an object read.table for it, then I have try to
>>>
>>>create a
>>>
>>>>list or a data frame and directly utilize some
>>>
>>>functions
>>>
>>>>like sd( ) without success, because it calculate
>>>
>>>sd for the
>>>
>>>>columns . Which kind of object should I create
>>>
>>>in order to
>>>
>>>>utilize directly this kind of functions? Should I
>>>
>>>program it
>>>
>>>>throw for loops?
>>>>
>>>>David
>>>>
>>>
>>______________________________________________
>>R-help at stat.math.ethz.ch mailing list
>>https://stat.ethz.ch/mailman/listinfo/r-help
>>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>>
>
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>
More information about the R-help
mailing list