user2817329
user2817329

Reputation: 93

Tables of t-test results in R: Most Efficient Way?

All,

I'm looking for the most efficient way to generate a table that compares two groups on a number of variables, summarizing t-test results. The goal is to easily change or edit the number of comparison variables. Is there an easy way to use dplyr or some other tidy tool to do this? I would like the table to look like that below. Most efficient way? Elegant solution?

       M.Male  M.Fem SD.Male SD.Fem 95LL  95UL     t    p     d
 var1   28.54   27.60  6.92   8.74 -0.62  2.51  1.19 0.23  0.12
 var2   33.22   37.36  7.29   8.35 -4.42 -1.80 -4.66 0.00 -0.47
 var3   44.25   47.35  6.74   6.57 -5.69 -2.59 -5.25 0.00 -0.53
 var4   31.97   35.48  9.77  11.21 -5.60 -1.44 -3.33 0.00 -0.34

When I experimented with the summarize commands, I had difficulty wrangling the t.test() function.

Upvotes: 1

Views: 1627

Answers (1)

Adam Quek
Adam Quek

Reputation: 7163

Here's a solution with broom package:

m1 <- t.test(1:10, y = c(7:20))
glance(m1)
  estimate estimate1 estimate2 statistic      p.value parameter conf.low conf.high
1       -8       5.5      13.5  -5.43493 1.855282e-05  21.98221 -11.0528 -4.947198
                   method alternative
1 Welch Two Sample t-test   two.sided

Upvotes: 1

Related Questions