IDEMSInternational / R-Instat

A statistics software package powered by R
http://r-instat.org/
GNU General Public License v3.0
38 stars 103 forks source link

Changing the Describe > Combine Graphs to Combine Graphs/Tables dialogue? #7082

Open rdstern opened 2 years ago

rdstern commented 2 years ago

One of the features of the new mmtable2 package is (I think) an ability to combine tables. I wonder what this means? I suggest it is more like Genatat, that has a table structure. So you can do operations on tables and produce new ones. That's different to the combine graphs. Here is one thing I would like, that I think we can't do in a single table. It is when I have different summary statistics for different variables. Then I want them in a table together. This relates to the current store table, that stores the data - possibly with summaries below - in a data frame. If I produce and store more, then does it add to the existing store (as it does with the usual summary dialogue). If so, then that is most of what I need? Can that be the new starting point for a presentation table? Separately from that I assume the combine tables would be for the situation where I have a table of totals, and also a table of counts and I could divide the tables to get the means? Or I could add counts from 2 districts say?

lilyclements commented 2 years ago

It seems there are two different combine options you are interested in:

  1. On the design aspect
  2. On the calculations aspect

To point 1 - The design aspect is outlined nicely in the vignette here. Tables can be placed:

If they do not have columns in common, then it just gives a blank cell.

e.g., using the code on the link above but changing the t1 and t2 tables:

library(gapminder)
library(dplyr)
library(tidyr)
library(stringr)
library(purrr)
library(gt)
library(mmtable2)

gm_df <- gapminder_mm %>% filter(var != "Life expectancy")

gm_table <- 
  gm_df %>% 
  mmtable(cells = value) +
  header_left(year) +
  header_top(country) +
  header_left_top(var)  +
  header_top_left(continent)

t1 <- gm_df %>% 
  filter(country == "Australia") %>%
  mmtable(cells = value) +
  header_left(year) +
  header_top(country) +
  header_left_top(var)  +
  header_top_left(continent)

t2 <- gm_df %>% 
  filter(country == "Ireland") %>%
  mmtable(cells = value) +
  heae bder_left(year) +
  header_top(country) +ble"
  header_left_top(var)  +
  header_top_left(continent)

t1 + t2
t1 / t2  
t1 * t2

To point 2 - The calculations aspect will need more thinking. It is not as easy to "undo" mmtable2 back into a long format data set - although I could be missing something.

At the moment, we only save the "mmtable2" object in the summaries dialog. One way to do a calculation of two or more tables would be if we save the data set resulting from the summary_table R code. (This data set is currently used to create mmtable2 table from).

On the coding side - on the summaries dialog we currently save just the mmtable2 object. Could we instead save a list containing: [[1]] the data set that results from the summary_table R code (i.e., the calculation part of the tables) [[2]] the mmtable2 object (i.e., that display part of the tables) On the summaries dialog, we just display the second item in the list (the mmtable2 table).

If we saved both [[1]] and [[2]] in a list, then on a "calculation combine" dialog, the user reads in the saved objects that they wish to combine. We then take the first item in the list for each table they wish to combine (that is, the data set that resulted from the summary_table R code) We can do the calculation on those data sets that the user wants. And then we create a new mmtable2 object and display that.

Someone else (@dannyparsons) may have a better suggestion though.

lilyclements commented 2 years ago

Following todays meeting, perhaps we should split this into two issues:

The former can be done quite easily and quickly, but the latter might need a bit more work. Perhaps the latter should be put as a separate issue to focus on later. What do you think?