Generate summary table and comparison p values then export to word

Hi everyone,
Coming from SAS, there are some excellent Macros in SAS that made life much easier.
One such Marco helped create a "demographics table"... Basically the macro needs the following info

  1. Dataset
  2. List of continuous variables in the dataset
  3. List of categorical variables in the dataset
  4. A "group by" variable

The macro then generates a table (and exports it to word with a very nice format) the table containing:

  1. The min, p25, mean, median, p75, max for each continuous variable for the two levels of the "group by" variable
  2. The number and percentage of each categorical variable for the two levels of the "by group" variable
  3. t-test or Mann-Whitney comparison between the two levels of the "by group" for each continuous variable
  4. Fisher exact or Chi-square between the two levels of the "by group" for each categorical variable

You can see what I mean by looking at the output in the following link under figure 2:
https://analytics.ncsu.edu/sesug/2013/PO-05.pdf

Could anyone please point me to a function or a similar way of doing this in R??

Thanks
AM

1 Like

I am not aware of a package that creates those numbers, and if you have very specific requirements, then you'll almost certainly have to write your own function. For the presentation, you can use formattable (see the thread here).

You can search GitHub and you'll probably find some code to start with.

Hi @ammarhm

Further to @Stephen answer, You could use the describeby function in the psych package to do the majority of this. Another method is taken up in this blog which shows t.tests being created per group. You could expand it to your test statistic of choice. For the presentation you could then use kable and kableExtra for the formatting for pdf table. Im not sure if it works with MS Word

I hope this is useful

1 Like