spgarbet / tangram

Table Grammar package for R
66 stars 3 forks source link

Ability to specify specific statistical test for a particular variable #63

Closed kylerove closed 4 years ago

kylerove commented 4 years ago

While for most analyses, using default statistical tests (or those we designate on our own) for a single tangram-generated table is fine, I have run into a particular instance where I want a different, specific statistical test run for a variable.

This enhancement could use some additional syntax or existing [] syntax after variable to specify a test (like [test=mytest]). Would depend on having mytest declared in a similar fashion to custom statistical tests for the whole table.

Thoughts?

spgarbet commented 4 years ago

This request has always been a primary goal of the project.

For any set of transforms, the extra argument '...' are passed to the transform. For the 'hmisc' style transform, there is an additional argument "test"

The code internal looks like this: if(inherits(test, "function")) { stat <- test(row, column, cell_style, ...) test <- TRUE }

So one can pass a test function to the entire table, and it will be given the row, column and cell_style function that will be used by that transform. However, the downside of this is that now if rows and column types are mixed and one wants different tests, etc, then the burden falls on the user.

Adding a test= directive for a single variable in the formula is possible, but as it stands the formulas still follow R syntax (but not semantics).

Does the existing functionality work for you? Or is this something really necessary?

spgarbet commented 4 years ago

Please see this example: http://htmlpreview.github.io/?https://raw.githubusercontent.com/spgarbet/tangram-vignettes/master/matched-cohort.html