Note that there are some explanatory texts on larger screens.

plurals
  1. POR: t-test over all subsets over all columns
    primarykey
    data
    text
    <p>This is a follow up question from <a href="https://stackoverflow.com/q/9661469/612191">R: t-test over all columns</a></p> <p>Suppose I have a huge data set, and then I created numerous subsets based on certain conditions. The subsets should have the same number of columns. Then I want to do t-test on two subsets at a time (outer loop) and then for each combination of subsets go through all columns one column at a time (inner loop).</p> <p>Here is what I have come up with based on previous answer. This one stops with an error.</p> <pre><code>C &lt;- c("c1","c1","c1","c1","c1", "c2","c2","c2","c2","c2", "c3","c3","c3","c3","c3", "c4","c4","c4","c4","c4", "c5","c5","c5","c5","c5", "c6","c6","c6","c6","c6", "c7","c7","c7","c7","c7", "c8","c8","c8","c8","c8", "c9","c9","c9","c9","c9", "c10","c10","c10","c10","c10") X &lt;- rnorm(n=50, mean = 10, sd = 5) Y &lt;- rnorm(n=50, mean = 15, sd = 6) Z &lt;- rnorm(n=50, mean = 20, sd = 5) Data &lt;- data.frame(C, X, Y, Z) Data.c1 = subset(Data, C == "c1",select=X:Z) Data.c2 = subset(Data, C == "c2",select=X:Z) Data.c3 = subset(Data, C == "c3",select=X:Z) Data.c4 = subset(Data, C == "c4",select=X:Z) Data.c5 = subset(Data, C == "c5",select=X:Z) Data.Subsets = c("Data.c1", "Data.c2", "Data.c3", "Data.c4", "Data.c5") library(plyr) combo1 &lt;- combn(length(Data.Subsets),1) adply(combo1, 1, function(x) { combo2 &lt;- combn(ncol(Data.Subsets[x]),2) adply(combo2, 2, function(y) { test &lt;- t.test( Data.Subsets[x][, y[1]], Data.Subsets[x][, y[2]], na.rm=TRUE) out &lt;- data.frame("Subset" = rownames(Data.Subsets[x]), , "Row" = colnames(x)[y[1]] , "Column" = colnames(x[y[2]]) , "t.value" = round(test$statistic,3) , "df"= test$parameter , "p.value" = round(test$p.value, 3) ) return(out) } ) } ) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload