The functions 'toWide()', 'toLong()', and 'toCompiled()' converts the data into various formats.

toWide(w)

toLong(w)

toCompiled(w)

Arguments

w

An instance of an ANOPA object.

Value

A data frame in the requested format.

Details

The proportions of success of a set of n participants can be given using many formats. In what follows, n is the number of participants, p is the number of between-subject factor(s), $q$ is the number of repeated-measure factor(s).

  • One basic format, called wide, has one line per participants, with a 1 if a "success" is observed or a 0 if no success is observed. What a succes is is entirely arbitrary. The proportion of success is then the number of 1s divided by the number of participants in each group. The data frame has $n$ lines and $p+q$ columns.

  • A second format, called long, has, on a line, the factor name(s) and 1s or 0s to indicate success or not. The data fame has $n x q$ lines and 4 columns (a Id column to identify the particpant; $p$ columns to identify the groups, one column to identify which whitin-subject measure is given and finally, a 1 or 0 for the score of that measurement.

  • A third format, called compiled, is to have a list of all the between-subject factors and the number of success and the total number of participants. This format is more compact as if there are 6 groups, the data are all contained in six lines (one line per group). This format however is only valid for between-subject design as we cannot infer the correlation between successes/failure.

See the vignette DataFormatsForProportions for more.

Examples


# The minimalBSExample contains $n$ of 175 participants categorized according
# to one factor $f = 1$, namely `State of residency` (with three levels) 
# for 3 possible cells.
minimalBSExample
#>      state  s  n
#> 1  Florida 31 57
#> 2 Kentucky 25 73
#> 3  Montana  9 45

# Lets incorporate the data in an ANOPA data structure
w <- anopa( {s;n} ~ state, minimalBSExample )

# The data presented using various formats looks like
toWide(w)
#>        state s
#> 1    Florida 1
#> 2    Florida 1
#> 3    Florida 1
#> 4    Florida 1
#> 5    Florida 1
#> 6    Florida 1
#> 7    Florida 1
#> 8    Florida 1
#> 9    Florida 1
#> 10   Florida 1
#> 11   Florida 1
#> 12   Florida 1
#> 13   Florida 1
#> 14   Florida 1
#> 15   Florida 1
#> 16   Florida 1
#> 17   Florida 1
#> 18   Florida 1
#> 19   Florida 1
#> 20   Florida 1
#> 21   Florida 1
#> 22   Florida 1
#> 23   Florida 1
#> 24   Florida 1
#> 25   Florida 1
#> 26   Florida 1
#> 27   Florida 1
#> 28   Florida 1
#> 29   Florida 1
#> 30   Florida 1
#> 31   Florida 1
#> 32   Florida 0
#> 33   Florida 0
#> 34   Florida 0
#> 35   Florida 0
#> 36   Florida 0
#> 37   Florida 0
#> 38   Florida 0
#> 39   Florida 0
#> 40   Florida 0
#> 41   Florida 0
#> 42   Florida 0
#> 43   Florida 0
#> 44   Florida 0
#> 45   Florida 0
#> 46   Florida 0
#> 47   Florida 0
#> 48   Florida 0
#> 49   Florida 0
#> 50   Florida 0
#> 51   Florida 0
#> 52   Florida 0
#> 53   Florida 0
#> 54   Florida 0
#> 55   Florida 0
#> 56   Florida 0
#> 57   Florida 0
#> 58  Kentucky 1
#> 59  Kentucky 1
#> 60  Kentucky 1
#> 61  Kentucky 1
#> 62  Kentucky 1
#> 63  Kentucky 1
#> 64  Kentucky 1
#> 65  Kentucky 1
#> 66  Kentucky 1
#> 67  Kentucky 1
#> 68  Kentucky 1
#> 69  Kentucky 1
#> 70  Kentucky 1
#> 71  Kentucky 1
#> 72  Kentucky 1
#> 73  Kentucky 1
#> 74  Kentucky 1
#> 75  Kentucky 1
#> 76  Kentucky 1
#> 77  Kentucky 1
#> 78  Kentucky 1
#> 79  Kentucky 1
#> 80  Kentucky 1
#> 81  Kentucky 1
#> 82  Kentucky 1
#> 83  Kentucky 0
#> 84  Kentucky 0
#> 85  Kentucky 0
#> 86  Kentucky 0
#> 87  Kentucky 0
#> 88  Kentucky 0
#> 89  Kentucky 0
#> 90  Kentucky 0
#> 91  Kentucky 0
#> 92  Kentucky 0
#> 93  Kentucky 0
#> 94  Kentucky 0
#> 95  Kentucky 0
#> 96  Kentucky 0
#> 97  Kentucky 0
#> 98  Kentucky 0
#> 99  Kentucky 0
#> 100 Kentucky 0
#> 101 Kentucky 0
#> 102 Kentucky 0
#> 103 Kentucky 0
#> 104 Kentucky 0
#> 105 Kentucky 0
#> 106 Kentucky 0
#> 107 Kentucky 0
#> 108 Kentucky 0
#> 109 Kentucky 0
#> 110 Kentucky 0
#> 111 Kentucky 0
#> 112 Kentucky 0
#> 113 Kentucky 0
#> 114 Kentucky 0
#> 115 Kentucky 0
#> 116 Kentucky 0
#> 117 Kentucky 0
#> 118 Kentucky 0
#> 119 Kentucky 0
#> 120 Kentucky 0
#> 121 Kentucky 0
#> 122 Kentucky 0
#> 123 Kentucky 0
#> 124 Kentucky 0
#> 125 Kentucky 0
#> 126 Kentucky 0
#> 127 Kentucky 0
#> 128 Kentucky 0
#> 129 Kentucky 0
#> 130 Kentucky 0
#> 131  Montana 1
#> 132  Montana 1
#> 133  Montana 1
#> 134  Montana 1
#> 135  Montana 1
#> 136  Montana 1
#> 137  Montana 1
#> 138  Montana 1
#> 139  Montana 1
#> 140  Montana 0
#> 141  Montana 0
#> 142  Montana 0
#> 143  Montana 0
#> 144  Montana 0
#> 145  Montana 0
#> 146  Montana 0
#> 147  Montana 0
#> 148  Montana 0
#> 149  Montana 0
#> 150  Montana 0
#> 151  Montana 0
#> 152  Montana 0
#> 153  Montana 0
#> 154  Montana 0
#> 155  Montana 0
#> 156  Montana 0
#> 157  Montana 0
#> 158  Montana 0
#> 159  Montana 0
#> 160  Montana 0
#> 161  Montana 0
#> 162  Montana 0
#> 163  Montana 0
#> 164  Montana 0
#> 165  Montana 0
#> 166  Montana 0
#> 167  Montana 0
#> 168  Montana 0
#> 169  Montana 0
#> 170  Montana 0
#> 171  Montana 0
#> 172  Montana 0
#> 173  Montana 0
#> 174  Montana 0
#> 175  Montana 0
# ... has 175 lines, one per participants ($n$) and 2 columns (state, success or failure)

toLong(w)
#>        Id    state Variable Value
#> 1.s     1  Florida        s     1
#> 2.s     2  Florida        s     1
#> 3.s     3  Florida        s     1
#> 4.s     4  Florida        s     1
#> 5.s     5  Florida        s     1
#> 6.s     6  Florida        s     1
#> 7.s     7  Florida        s     1
#> 8.s     8  Florida        s     1
#> 9.s     9  Florida        s     1
#> 10.s   10  Florida        s     1
#> 11.s   11  Florida        s     1
#> 12.s   12  Florida        s     1
#> 13.s   13  Florida        s     1
#> 14.s   14  Florida        s     1
#> 15.s   15  Florida        s     1
#> 16.s   16  Florida        s     1
#> 17.s   17  Florida        s     1
#> 18.s   18  Florida        s     1
#> 19.s   19  Florida        s     1
#> 20.s   20  Florida        s     1
#> 21.s   21  Florida        s     1
#> 22.s   22  Florida        s     1
#> 23.s   23  Florida        s     1
#> 24.s   24  Florida        s     1
#> 25.s   25  Florida        s     1
#> 26.s   26  Florida        s     1
#> 27.s   27  Florida        s     1
#> 28.s   28  Florida        s     1
#> 29.s   29  Florida        s     1
#> 30.s   30  Florida        s     1
#> 31.s   31  Florida        s     1
#> 32.s   32  Florida        s     0
#> 33.s   33  Florida        s     0
#> 34.s   34  Florida        s     0
#> 35.s   35  Florida        s     0
#> 36.s   36  Florida        s     0
#> 37.s   37  Florida        s     0
#> 38.s   38  Florida        s     0
#> 39.s   39  Florida        s     0
#> 40.s   40  Florida        s     0
#> 41.s   41  Florida        s     0
#> 42.s   42  Florida        s     0
#> 43.s   43  Florida        s     0
#> 44.s   44  Florida        s     0
#> 45.s   45  Florida        s     0
#> 46.s   46  Florida        s     0
#> 47.s   47  Florida        s     0
#> 48.s   48  Florida        s     0
#> 49.s   49  Florida        s     0
#> 50.s   50  Florida        s     0
#> 51.s   51  Florida        s     0
#> 52.s   52  Florida        s     0
#> 53.s   53  Florida        s     0
#> 54.s   54  Florida        s     0
#> 55.s   55  Florida        s     0
#> 56.s   56  Florida        s     0
#> 57.s   57  Florida        s     0
#> 58.s   58 Kentucky        s     1
#> 59.s   59 Kentucky        s     1
#> 60.s   60 Kentucky        s     1
#> 61.s   61 Kentucky        s     1
#> 62.s   62 Kentucky        s     1
#> 63.s   63 Kentucky        s     1
#> 64.s   64 Kentucky        s     1
#> 65.s   65 Kentucky        s     1
#> 66.s   66 Kentucky        s     1
#> 67.s   67 Kentucky        s     1
#> 68.s   68 Kentucky        s     1
#> 69.s   69 Kentucky        s     1
#> 70.s   70 Kentucky        s     1
#> 71.s   71 Kentucky        s     1
#> 72.s   72 Kentucky        s     1
#> 73.s   73 Kentucky        s     1
#> 74.s   74 Kentucky        s     1
#> 75.s   75 Kentucky        s     1
#> 76.s   76 Kentucky        s     1
#> 77.s   77 Kentucky        s     1
#> 78.s   78 Kentucky        s     1
#> 79.s   79 Kentucky        s     1
#> 80.s   80 Kentucky        s     1
#> 81.s   81 Kentucky        s     1
#> 82.s   82 Kentucky        s     1
#> 83.s   83 Kentucky        s     0
#> 84.s   84 Kentucky        s     0
#> 85.s   85 Kentucky        s     0
#> 86.s   86 Kentucky        s     0
#> 87.s   87 Kentucky        s     0
#> 88.s   88 Kentucky        s     0
#> 89.s   89 Kentucky        s     0
#> 90.s   90 Kentucky        s     0
#> 91.s   91 Kentucky        s     0
#> 92.s   92 Kentucky        s     0
#> 93.s   93 Kentucky        s     0
#> 94.s   94 Kentucky        s     0
#> 95.s   95 Kentucky        s     0
#> 96.s   96 Kentucky        s     0
#> 97.s   97 Kentucky        s     0
#> 98.s   98 Kentucky        s     0
#> 99.s   99 Kentucky        s     0
#> 100.s 100 Kentucky        s     0
#> 101.s 101 Kentucky        s     0
#> 102.s 102 Kentucky        s     0
#> 103.s 103 Kentucky        s     0
#> 104.s 104 Kentucky        s     0
#> 105.s 105 Kentucky        s     0
#> 106.s 106 Kentucky        s     0
#> 107.s 107 Kentucky        s     0
#> 108.s 108 Kentucky        s     0
#> 109.s 109 Kentucky        s     0
#> 110.s 110 Kentucky        s     0
#> 111.s 111 Kentucky        s     0
#> 112.s 112 Kentucky        s     0
#> 113.s 113 Kentucky        s     0
#> 114.s 114 Kentucky        s     0
#> 115.s 115 Kentucky        s     0
#> 116.s 116 Kentucky        s     0
#> 117.s 117 Kentucky        s     0
#> 118.s 118 Kentucky        s     0
#> 119.s 119 Kentucky        s     0
#> 120.s 120 Kentucky        s     0
#> 121.s 121 Kentucky        s     0
#> 122.s 122 Kentucky        s     0
#> 123.s 123 Kentucky        s     0
#> 124.s 124 Kentucky        s     0
#> 125.s 125 Kentucky        s     0
#> 126.s 126 Kentucky        s     0
#> 127.s 127 Kentucky        s     0
#> 128.s 128 Kentucky        s     0
#> 129.s 129 Kentucky        s     0
#> 130.s 130 Kentucky        s     0
#> 131.s 131  Montana        s     1
#> 132.s 132  Montana        s     1
#> 133.s 133  Montana        s     1
#> 134.s 134  Montana        s     1
#> 135.s 135  Montana        s     1
#> 136.s 136  Montana        s     1
#> 137.s 137  Montana        s     1
#> 138.s 138  Montana        s     1
#> 139.s 139  Montana        s     1
#> 140.s 140  Montana        s     0
#> 141.s 141  Montana        s     0
#> 142.s 142  Montana        s     0
#> 143.s 143  Montana        s     0
#> 144.s 144  Montana        s     0
#> 145.s 145  Montana        s     0
#> 146.s 146  Montana        s     0
#> 147.s 147  Montana        s     0
#> 148.s 148  Montana        s     0
#> 149.s 149  Montana        s     0
#> 150.s 150  Montana        s     0
#> 151.s 151  Montana        s     0
#> 152.s 152  Montana        s     0
#> 153.s 153  Montana        s     0
#> 154.s 154  Montana        s     0
#> 155.s 155  Montana        s     0
#> 156.s 156  Montana        s     0
#> 157.s 157  Montana        s     0
#> 158.s 158  Montana        s     0
#> 159.s 159  Montana        s     0
#> 160.s 160  Montana        s     0
#> 161.s 161  Montana        s     0
#> 162.s 162  Montana        s     0
#> 163.s 163  Montana        s     0
#> 164.s 164  Montana        s     0
#> 165.s 165  Montana        s     0
#> 166.s 166  Montana        s     0
#> 167.s 167  Montana        s     0
#> 168.s 168  Montana        s     0
#> 169.s 169  Montana        s     0
#> 170.s 170  Montana        s     0
#> 171.s 171  Montana        s     0
#> 172.s 172  Montana        s     0
#> 173.s 173  Montana        s     0
#> 174.s 174  Montana        s     0
#> 175.s 175  Montana        s     0
# ... has 175 lines ($n x f$) and 4 columns (participant's `Id`, state name, measure name, 
# and success or failure)

toCompiled(w)
#>      state  s Count
#> 1  Florida 31    57
#> 2 Kentucky 25    73
#> 3  Montana  9    45
# ... has 3 lines and 3 columns ($f$ + 2: number of succes and number of participants).


# This second example is from a mixed-design. It indicates the 
# state of a machine, grouped in three categories (the sole between-subject
# factor) and at four different moments. 
# The four measurements times are before treatment, post-treatment, 
# 1 week later, and finally, 5 weeks later.
minimalMxExample
#>      Status bpre bpost b1week b5week
#> 1    Broken    1     1      1      0
#> 2    Broken    1     1      0      0
#> 3    Broken    0     0      1      1
#> 4    Broken    1     1      1      1
#> 5    Broken    0     0      1      1
#> 6    Broken    1     0      1      1
#> 7    Broken    1     1      0      1
#> 8    Broken    0     1      1      0
#> 9  Repaired    1     1      0      0
#> 10 Repaired    0     1      0      1
#> 11 Repaired    1     1      0      0
#> 12 Repaired    0     0      1      0
#> 13 Repaired    0     0      0      0
#> 14 Repaired    1     0      0      0
#> 15 Repaired    0     0      0      0
#> 16 Repaired    0     0      0      1
#> 17 Repaired    0     0      1      0
#> 18      New    0     0      0      1
#> 19      New    0     0      1      0
#> 20      New    0     0      0      0
#> 21      New    0     0      1      0
#> 22      New    0     0      0      0
#> 23      New    0     1      0      0
#> 24      New    0     0      1      0
#> 25      New    1     1      0      0
#> 26      New    0     0      0      1
#> 27      New    1     1      1      0

# Lets incorporate the data in an ANOPA data structure
w <- anopa( cbind(bpre,bpost,b1week,b5week) ~ Status, 
            minimalMxExample,
            WSFactors = "Moment(4)" )
#> ANOPA::fyi: Here is how the within-subject variables are understood:
#>  Moment Variable
#>       1     bpre
#>       2    bpost
#>       3   b1week
#>       4   b5week

# -- Wide format --
# Wide format is actually the format of minimalMxExample
# (27 lines with 8 subjects in the first group and 9 in the second)
toWide(w)
#>      Status bpre bpost b1week b5week
#> 1    Broken    1     1      1      0
#> 2    Broken    1     1      0      0
#> 3    Broken    0     0      1      1
#> 4    Broken    1     1      1      1
#> 5    Broken    0     0      1      1
#> 6    Broken    1     0      1      1
#> 7    Broken    1     1      0      1
#> 8    Broken    0     1      1      0
#> 9  Repaired    1     1      0      0
#> 10 Repaired    0     1      0      1
#> 11 Repaired    1     1      0      0
#> 12 Repaired    0     0      1      0
#> 13 Repaired    0     0      0      0
#> 14 Repaired    1     0      0      0
#> 15 Repaired    0     0      0      0
#> 16 Repaired    0     0      0      1
#> 17 Repaired    0     0      1      0
#> 18      New    0     0      0      1
#> 19      New    0     0      1      0
#> 20      New    0     0      0      0
#> 21      New    0     0      1      0
#> 22      New    0     0      0      0
#> 23      New    0     1      0      0
#> 24      New    0     0      1      0
#> 25      New    1     1      0      0
#> 26      New    0     0      0      1
#> 27      New    1     1      1      0

# -- Long format --
# (27 times 4 lines = 108 lines, 4 columns, that is Id, group, measurement, success or failure)
toLong(w)
#>           Id   Status Variable Value
#> 1.bpre     1   Broken     bpre     1
#> 1.bpost    1   Broken    bpost     1
#> 1.b1week   1   Broken   b1week     1
#> 1.b5week   1   Broken   b5week     0
#> 2.bpre     2   Broken     bpre     1
#> 2.bpost    2   Broken    bpost     1
#> 2.b1week   2   Broken   b1week     0
#> 2.b5week   2   Broken   b5week     0
#> 3.bpre     3   Broken     bpre     0
#> 3.bpost    3   Broken    bpost     0
#> 3.b1week   3   Broken   b1week     1
#> 3.b5week   3   Broken   b5week     1
#> 4.bpre     4   Broken     bpre     1
#> 4.bpost    4   Broken    bpost     1
#> 4.b1week   4   Broken   b1week     1
#> 4.b5week   4   Broken   b5week     1
#> 5.bpre     5   Broken     bpre     0
#> 5.bpost    5   Broken    bpost     0
#> 5.b1week   5   Broken   b1week     1
#> 5.b5week   5   Broken   b5week     1
#> 6.bpre     6   Broken     bpre     1
#> 6.bpost    6   Broken    bpost     0
#> 6.b1week   6   Broken   b1week     1
#> 6.b5week   6   Broken   b5week     1
#> 7.bpre     7   Broken     bpre     1
#> 7.bpost    7   Broken    bpost     1
#> 7.b1week   7   Broken   b1week     0
#> 7.b5week   7   Broken   b5week     1
#> 8.bpre     8   Broken     bpre     0
#> 8.bpost    8   Broken    bpost     1
#> 8.b1week   8   Broken   b1week     1
#> 8.b5week   8   Broken   b5week     0
#> 9.bpre     9 Repaired     bpre     1
#> 9.bpost    9 Repaired    bpost     1
#> 9.b1week   9 Repaired   b1week     0
#> 9.b5week   9 Repaired   b5week     0
#> 10.bpre   10 Repaired     bpre     0
#> 10.bpost  10 Repaired    bpost     1
#> 10.b1week 10 Repaired   b1week     0
#> 10.b5week 10 Repaired   b5week     1
#> 11.bpre   11 Repaired     bpre     1
#> 11.bpost  11 Repaired    bpost     1
#> 11.b1week 11 Repaired   b1week     0
#> 11.b5week 11 Repaired   b5week     0
#> 12.bpre   12 Repaired     bpre     0
#> 12.bpost  12 Repaired    bpost     0
#> 12.b1week 12 Repaired   b1week     1
#> 12.b5week 12 Repaired   b5week     0
#> 13.bpre   13 Repaired     bpre     0
#> 13.bpost  13 Repaired    bpost     0
#> 13.b1week 13 Repaired   b1week     0
#> 13.b5week 13 Repaired   b5week     0
#> 14.bpre   14 Repaired     bpre     1
#> 14.bpost  14 Repaired    bpost     0
#> 14.b1week 14 Repaired   b1week     0
#> 14.b5week 14 Repaired   b5week     0
#> 15.bpre   15 Repaired     bpre     0
#> 15.bpost  15 Repaired    bpost     0
#> 15.b1week 15 Repaired   b1week     0
#> 15.b5week 15 Repaired   b5week     0
#> 16.bpre   16 Repaired     bpre     0
#> 16.bpost  16 Repaired    bpost     0
#> 16.b1week 16 Repaired   b1week     0
#> 16.b5week 16 Repaired   b5week     1
#> 17.bpre   17 Repaired     bpre     0
#> 17.bpost  17 Repaired    bpost     0
#> 17.b1week 17 Repaired   b1week     1
#> 17.b5week 17 Repaired   b5week     0
#> 18.bpre   18      New     bpre     0
#> 18.bpost  18      New    bpost     0
#> 18.b1week 18      New   b1week     0
#> 18.b5week 18      New   b5week     1
#> 19.bpre   19      New     bpre     0
#> 19.bpost  19      New    bpost     0
#> 19.b1week 19      New   b1week     1
#> 19.b5week 19      New   b5week     0
#> 20.bpre   20      New     bpre     0
#> 20.bpost  20      New    bpost     0
#> 20.b1week 20      New   b1week     0
#> 20.b5week 20      New   b5week     0
#> 21.bpre   21      New     bpre     0
#> 21.bpost  21      New    bpost     0
#> 21.b1week 21      New   b1week     1
#> 21.b5week 21      New   b5week     0
#> 22.bpre   22      New     bpre     0
#> 22.bpost  22      New    bpost     0
#> 22.b1week 22      New   b1week     0
#> 22.b5week 22      New   b5week     0
#> 23.bpre   23      New     bpre     0
#> 23.bpost  23      New    bpost     1
#> 23.b1week 23      New   b1week     0
#> 23.b5week 23      New   b5week     0
#> 24.bpre   24      New     bpre     0
#> 24.bpost  24      New    bpost     0
#> 24.b1week 24      New   b1week     1
#> 24.b5week 24      New   b5week     0
#> 25.bpre   25      New     bpre     1
#> 25.bpost  25      New    bpost     1
#> 25.b1week 25      New   b1week     0
#> 25.b5week 25      New   b5week     0
#> 26.bpre   26      New     bpre     0
#> 26.bpost  26      New    bpost     0
#> 26.b1week 26      New   b1week     0
#> 26.b5week 26      New   b5week     1
#> 27.bpre   27      New     bpre     1
#> 27.bpost  27      New    bpost     1
#> 27.b1week 27      New   b1week     1
#> 27.b5week 27      New   b5week     0

# -- Compiled format --
# (three lines as there are three groups, 7 columns, that is, 
# the group, the 4 measurements, the number of particpants, and the
# correlation between measurements for each group measured by unitary alphas)
toCompiled(w)
#>     Status bpre bpost b1week b5week Count      uAlpha
#> 1   Broken    5     5      6      5     8 -0.15204678
#> 2      New    2     3      4      2    10 -0.03463203
#> 3 Repaired    3     3      2      2     9 -0.10416667