Search code examples
rpsych

error.bars.by{psych} Multiple variables


Hello Stack Community,

My question is in regards to the command

error.bars.by()

from the package error.bars.by{psych}.

I am familiar with how the command works:

 error.bars.by(
    mydata[3],
    mydata[1],
    by.var=TRUE,
    x.cat=TRUE,
    legend=5,
    eyes=FALSE,
    pch=10,
    cex=2,
    alpha=.05,
    density=10,
    )

My question is whether or not this command can handle two grouping variables.

If so, how would I code it?

The data table

   Group Subgroup  Measure
1      A        1 0.234213
2      A        1 0.046248
3      A        1 0.391376
4      A        2 0.911849
5      A        2 0.729955
6      A        2 0.991110
7      A        2 0.378422
8      A        3 0.898037
9      A        3 0.258884
10     A        3       NA
11     A        3 0.057631
12     A        3 0.745202
13     A        3 0.121376
14     B        1 0.385198
15     B        1 0.484399
16     B        1 0.115034
17     B        1 0.073629
18     B        1 0.456150
19     B        2 0.336108
20     B        2 0.845458
21     B        2 0.267494
22     B        3 0.536123
23     B        3 1.331731
24     B        3 0.505114
25     B        3 0.843348
26     B        3 0.827932
27     B        3 0.813351
28     C        1 0.095587
29     C        1 0.158822
30     C        1 0.392376
31     C        1 0.284625
32     C        2 0.898819
33     C        2 0.743428
34     C        2 0.298989
35     C        2 0.423961
36     C        3 0.868351
37     C        3 0.181547
38     C        3 1.146131
39     C        3 0.234941

Solution

  • Try <something like>(TM):

    error.bars.by( mydata[[3]], interaction(mydata[[1]], mydata[[other_col_name]]), by.var=TRUE,
                 x.cat=TRUE, legend=5, eyes=FALSE, pch=10, cex=2, alpha=.05, density=10, )
    

    The interaction function creates a new single column that can be used when you want a "long" version of a cross-classification. Edit: I took out the by.var=TRUE since it wasn't documented on the help page for the function and you didn't describe what it was doing.