Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introducing n_Obs column to htest summary outputs #621

Closed
IndrajeetPatil opened this issue Oct 22, 2021 · 6 comments
Closed

introducing n_Obs column to htest summary outputs #621

IndrajeetPatil opened this issue Oct 22, 2021 · 6 comments
Labels
Feature idea 🔥 New feature or request What's your opinion 🙉 Collectively discuss something

Comments

@IndrajeetPatil
Copy link
Member

I am wondering if it will be a good idea to add a column to the summary outputs for htest objects containing sample size or number of observations information.

Although this might be straightforward for some tests, it's not so for others. Or at least I can't think of a straightforward way to extract this information in certain contexts.

# t-test ----------------------

mod1 <- t.test(mtcars$wt, mu = 3)
mod1$parameter[[1]] + 1
#> [1] 32

# but what about when var.equal = FALSE for two-sample test?
mod2 <- t.test(formula = wt ~ am, data = mtcars)
mod2$parameter[[1]] # sample size no longer parameter + 1
#> [1] 29.23352

# chi-squared test ------------

mod3 <- chisq.test(table(mtcars$am, mtcars$cyl))
#> Warning in chisq.test(table(mtcars$am, mtcars$cyl)): Chi-squared approximation
#> may be incorrect
sum(mod3$observed)
#> [1] 32

mod4 <- chisq.test(table(mtcars$cyl))
sum(mod4$observed)
#> [1] 32

# correlation ------------------

# no need, correlation package does this already
dplyr::select(mtcars, wt, mpg, drat) |>
  correlation::correlation() |>
  as.data.frame()
#>   Parameter1 Parameter2          r   CI     CI_low    CI_high         t
#> 1         wt        mpg -0.8676594 0.95 -0.9338264 -0.7440872 -9.559044
#> 2         wt       drat -0.7124406 0.95 -0.8499795 -0.4839784 -5.560807
#> 3        mpg       drat  0.6811719 0.95  0.4360484  0.8322010  5.096042
#>   df_error            p              Method n_Obs
#> 1       30 3.881876e-10 Pearson correlation    32
#> 2       30 9.568520e-06 Pearson correlation    32
#> 3       30 1.776240e-05 Pearson correlation    32

# etc.

Created on 2021-10-22 by the reprex package (v2.0.1)

@IndrajeetPatil IndrajeetPatil added Feature idea 🔥 New feature or request What's your opinion 🙉 Collectively discuss something labels Oct 22, 2021
@vincentarelbundock
Copy link
Contributor

FWIW, I don't think nobs is a parameter or something we estimate, so it should be out of scope for this package.

@bwiernik
Copy link
Contributor

htest objects are such a mess, and there are too many cases where guesses would be wrong, that I think we don't do this

@vincentarelbundock
Copy link
Contributor

Cool. Will close now to clean the repo up a bit, but @IndrajeetPatil should of course feel free to re-open if he has strong views or an implementation in mind.

@iago-pssjd
Copy link

iago-pssjd commented Apr 12, 2023

I believe it would be a great idea, even not only that (/yet, better), but including the whole observed (and the expected?) table for a chi-squared test , like in summarytools::ctable (https://cran.r-project.org/web/packages/summarytools/vignettes/introduction.html#chi-square-%F0%9D%9B%982-odds-ratio-and-risk-ratio) or (with a more similar display) in compareGroups::createTable (https://cran.r-project.org/web/packages/compareGroups/vignettes/compareGroups_vignette.html#odds-ratios-and-hazard-ratios)

@strengejacke
Copy link
Member

I think this is something we could realize in report, @rempsyc, what do you think?

@rempsyc
Copy link
Member

rempsyc commented Apr 14, 2023

Should be doable yeah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature idea 🔥 New feature or request What's your opinion 🙉 Collectively discuss something
Projects
None yet
Development

No branches or pull requests

6 participants