ocbe-uio / contingencytables

Statistical Analysis of Contingency Tables
https://ocbe-uio.github.io/contingencytables/
GNU General Public License v3.0
3 stars 2 forks source link

Inconsistent names of output elements #35

Closed huftis closed 6 months ago

huftis commented 2 years ago

It would be nice with some (or preferably, complete) consistency in the values returned by the various functions.

Here’s an example, with three similar functions, where the first one returns a data.frame, the second returns a numeric vector, and the third returns a list. And the elements of the data.frame and the list even have different names. For the data.frame, the p-value is called p.value, while for the list, it’s called P.

library(contingencytables)
x = matrix(c(9, 12, 11, 8), ncol = 2)
x_paired = matrix(c(6, 6, 3, 5), ncol = 2) # Similar data, giving the same estimated proportions

str(Pearson_chi_squared_test_2x2(x))
#> [1] The Pearson chi-squared test: P = 0.34218, T = 0.902 (df = 1)
#> 'data.frame':    1 obs. of  3 variables:
#>  $ p.value  : num 0.342
#>  $ statistic: num 0.902
#>  $ df       : num 1

str(McNemar_midP_test_paired_2x2(x_paired))
#> [1] The McNemar mid-P test: P = 0.343750
#>  num 0.344

str(McNemar_asymptotic_test_paired_2x2(x_paired))
#> [1] The McNemar asymptotic test: P = 0.317311, Z = -1.000
#> List of 2
#>  $ P: num 0.317
#>  $ Z: num -1

If the functions instead returned an object with a consistent structure and element names, they would be much easier to use, e.g., in simulations.

And if the returned objects had a fixed class assigned, a print method could be defined for this class, so the annoying printresults argument could be removed from all functions in the package. For an example of how this would work, see how the t.test() and prop.test() functions use the htest class for their output. The output is printed by stats:::print.htest(), which is automatically called when when you print() the object (which is automatically done when you run the original function without assigning the result to a variable).

wleoncio commented 2 years ago

Hi,

Thank you for your suggestions! Standardization of output is on the roadmap for our next feature release, see here and issue #31 in particular. Glad to know there are users looking forward to it.

Changing the printing behavior is proposed by issue #27, but currently not on any roadmap (can't really remember why). I agree this is all part of the same topic, but keeping things separate makes work more manageable. :)

Closing this as duplicate, but keeping it linked to the aforementioned issues for the valuable examples.

wleoncio commented 2 years ago

On second thought, I'll reinstate and rename this so we can analyse the novel proposal of standardizing the output names (e.g. "P" vs. "p.value") and keep issue #31 only handling the output class of the functions themselves.

wleoncio commented 1 year ago

Hi @huftis,

contingencytables 2.0.0 has just been uploaded to CRAN with several fixes, including a standardization of the printing behavior you mentioned (see issue #31). Sorry it took this long; we went through a few iterations until we found a design that worked well enough (not to mention there were 150+ functions to refactor).

Regarding the aforementioned inconsistencies in the names of the output elements, we'll address this on a future release.

Thank you once again for your feedback.

wleoncio commented 6 months ago

Done. Fix available on develop branch, coming to CRAN very soon.