djnavarro / lsr

R package associated with "Learning Statistics with R"
https://lsr.djnavarro.net
Other
12 stars 5 forks source link

Some checks fail when applied to tibbles #2

Open jmgirard opened 3 years ago

jmgirard commented 3 years ago

Because tibbles return tibbles when indexed with [ ], but data frames return vectors, some of the checks are throwing false positives. Here is an example:

library(tibble)
library(lsr)

df <- data.frame(
  y = rnorm(30, 0, 1),
  x = factor(sample(0:1, 30, TRUE))
)

dft <- as_tibble(df)

independentSamplesTTest(y ~ x, df)
#> 
#>    Welch's independent samples t-test 
#> 
#> Outcome variable:   y 
#> Grouping variable:  x 
#> 
#> Descriptive statistics: 
#>                 0      1
#>    mean     0.174 -0.263
#>    std dev. 0.868  0.845
#> 
#> Hypotheses: 
#>    null:        population means equal for both groups
#>    alternative: different population means in each group
#> 
#> Test results: 
#>    t-statistic:  1.396 
#>    degrees of freedom:  27.659 
#>    p-value:  0.174 
#> 
#> Other information: 
#>    two-sided 95% confidence interval:  [-0.205, 1.079] 
#>    estimated effect size (Cohen's d):  0.51
independentSamplesTTest(y ~ x, dft)
#> Error in independentSamplesTTest(y ~ x, dft): outcome variable must be numeric

Created on 2021-09-18 by the reprex package (v2.0.1)

This assertion paradigm seems to be the culprit: https://github.com/djnavarro/lsr/blob/69c959e311e2591b2641b597d1cba49af03a2fb1/R/independentSamplesTTest.R#L80

djnavarro commented 3 years ago

Ah, thank you for this. I'm not sure when I'll get to it, but I do want to revisit this. The lsr package is old and in severely need of some maintenance. I was not a very good R programmer at the time I wrote it, unfortunately. I'll try to clear time to fix this... sometime

jmgirard commented 3 years ago

Would you be open to help/pull requests on some of these things? I'm also pretty busy, but teaching from the book right now and therefore on my mind.

djnavarro commented 3 years ago

That would be awesome, yes!

I've just sent version 0.5.1 to CRAN to update maintainer details, port the documentation to roxygen2 and fix the notes the package was throwing on CRAN. I think the way to proceed would be for me to add some minimal testthat infrastructure to make sure don't break expected behaviour per the book. It won't be fancy or thorough, but even some basic tests are better than none! I'll ping you once it's up (should be able to get it done today if the kids are kind to me!), at which point a PR would be very welcome

jmgirard commented 3 years ago

Sounds great. It would be great to be able to give back - the book has saved a LOT of effort for me in terms of teaching prep this term.