briandk / granovaGG

Bob Pruzek and Jim Helmreich's implementation of Elemental Graphics for Analysis of Variance
Other
15 stars 4 forks source link

The t-test for 1w fails when groups are of unequal size #149

Open WilDoane opened 12 years ago

WilDoane commented 12 years ago
> read.csv("data.txt", h=TRUE) -> xx

> head(xx)
          Measure Location          Region
1 0.008758994    1 1
2 0.041469850    1 1
3 0.096344340    1 1
4 0.055998090    1 1
5 0.037924000    1 1
6 0.031402760    1 1

> granovagg.1w(data = xx[, 1], group = xx[, 3])

By-group summary statistics for your input data (ordered by group means)
             group group.mean trimmed.mean contrast variance standard.deviation group.size
2   2       0.03         0.02    -0.01        0               0.03         35
1   1       0.04         0.04     0.01        0               0.03         47

Below is a t-test summary of your input data
Error in unstacked.data[, 1] : incorrect number of dimensions

Where the data is:

Measure,Location,Region 0.008758994,1,1 0.04146985,1,1 0.09634434,1,1 0.05599809,1,1 0.037924,1,1 0.03140276,1,1 0.03273692,1,1 0.06603438,1,1 0.02213142,1,1 0.1269441,1,1 0.06632624,1,1 0.1459606,1,1 0.01983643,2,1 0.001162292,2,1 0.02383746,2,1 0.04751318,2,1 0.09128601,2,1 0.01343654,2,1 0.03953939,2,1 0.03656027,2,1 0.04845837,2,1 0.08883967,2,1 0.03523059,2,1 0.03066298,2,1 0.06648093,2,1 0.0183183,2,1 0.01520962,2,1 0.03833972,2,1 0.06648921,2,1 0.05706215,3,1 0.0805001,3,1 0.05470866,3,1 0.02154668,3,1 0.02068727,3,1 0.008289484,3,1 0.01736224,3,1 0.04599525,3,1 0.08238185,3,1 0.00363438,3,1 0.002015544,3,1 0.02456306,3,1 0.03481855,3,1 0.004820532,3,1 0.03355581,3,1 0.004518231,3,1 0.03186453,3,1 0.1035173,3,1 0.003618154,4,2 0.01150031,4,2 0.01474353,4,2 0.0235951,4,2 0.0007341859,4,2 0.02354026,4,2 0.01441165,4,2 0.01989785,4,2 0.02549262,4,2 0.006510455,4,2 0.008447188,4,2 0.02630929,5,2 0.01982208,5,2 0.09092932,5,2 0.05234133,5,2 0.0587467,5,2 0.01677552,5,2 0.03881078,5,2 0.01848181,5,2 0.01661278,5,2 0.002073064,5,2 0.019118,5,2 0.002729673,5,2 0.004473235,5,2 0.004090857,5,2 0.003130976,6,2 0.1200847,6,2 0.02694234,6,2 0.02227644,6,2 0.01123704,6,2 0.1369699,6,2 0.03986247,6,2 0.006040578,6,2 0.006735805,6,2 0.00233625,6,2

WilDoane commented 12 years ago

Per Brian

All of the examples with t-test data that I test for the 1w function are—I believe—cases where there are equal numbers of samples in each group. From the man page for "unstack":

unstack produces a list of columns according to the formula form. If all the columns have the same length, the resulting list is coerced to a data frame.

My code for executing the t-test uses selection operators that assume the input data is a dataframe.

I debugged this by:

briandk commented 12 years ago

Yeah, the problem is in these lines of the .1w function:

t.test(unstacked.data[, 1], 
       unstacked.data[, 2],
       var.equal = TRUE
)

If unstacked.data is a list (which is what unstack() returns when group sizes are unequal), the selection operators will fail.

WilDoane commented 12 years ago

So, some check like

if (typeof(unstacked.data) == "list") { ... }

would be needed, then?

gjpstrain commented 3 years ago

I'm still having this issue - anyone know of a workaround? The granovaGG package documentation says that it works with unequal group sizes, but I'm getting the exact same error; I have one group of 64 and another of 500