Giter Site home page Giter Site logo

nice_t_test for specific mean? about rempsyc HOT 7 CLOSED

rempsyc avatar rempsyc commented on June 20, 2024
nice_t_test for specific mean?

from rempsyc.

Comments (7)

philpav avatar philpav commented on June 20, 2024 1

Amazing!
Thank you for the quick fix!

I have also tried with alternative = "less" and alternative = "greater" and it's also working.

My workaround was to use the report package:

model = t.test(mtcars$mpg, mu = 10)
tbl = as.data.frame(report::report(model))
nice_table(tbl, report = "t.test")

from rempsyc.

rempsyc avatar rempsyc commented on June 20, 2024

Hi, thank you for opening an issue!

You are correct that in the current version, doing a one-sample t-test provides an error because the group argument is currently mandatory:

nice_t_test(data = mtcars,
            response = "mpg",
            mu = 10)

Error in (function(x, i, exact) if (is.matrix(i)) as.matrix(x)[[i]] else .subset2(x, : 
  argument "group" is missing, with no default

With version 0.0.3.2, it is now possible:

nice_t_test(data = mtcars,
            response = "mpg",
            mu = 10)

Dependent Variable        t df                  p        d CI_lower CI_upper
               mpg 9.470995 31 0.0000000001154598 3.333466 2.472257 4.291719

We can confirm it yields identical results to t.test:

t.test(mtcars$mpg, mu = 10)

	One Sample t-test
data:  mtcars$mpg
t = 9.471, df = 31, p-value = 0.0000000001155
alternative hypothesis: true mean is not equal to 10

For the sake of simplicity I have ignored the alternative = "two.sided" argument as it is the default (though feel free to specify it for clarity in your own code).

It can be used with several variables as well:

nice_t_test(data = mtcars,
            response = names(mtcars)[1:7],
            mu = 10)
 
  Dependent Variable          t df                                           p        d CI_lower  CI_upper
1                mpg   9.470995 31 0.00000000011545976649382190319615901219485 3.333466 2.472257  4.291719
2                cyl -12.075982 31 0.00000000000029571269126768929345894232341 3.464598 2.575163  4.455521
3               disp  10.074267 31 0.00000000002684882863765266898178896148863 1.861581 1.299482  2.471701
4                 hp  11.277551 31 0.00000000000168302581052159496506799574167 2.139460 1.524730  2.811460
5               drat -67.747809 31 0.00000000000000000000000000000000002932045 6.726586 5.101919  8.516288
6                 wt -39.213794 31 0.00000000000000000000000000055204152227267 3.288084 2.436733  4.235071
7               qsec  24.846472 31 0.00000000000000000000049639366365302937307 9.988426 7.515941 12.616879

I have also updated the documentation. Thank you for your contribution in pointing out this issue.

from rempsyc.

philpav avatar philpav commented on June 20, 2024

Hi!

I am afraid I found an issue.

t.test(mtcars$mpg, mu=10)
nice_t_test(data = mtcars, response = "mpg", mu = 10, warning = FALSE)

t.test(mtcars$cyl, mu=10)
nice_t_test(data = mtcars, response = "cyl", mu = 10, warning = FALSE)

The confidence intervals differ.

from rempsyc.

rempsyc avatar rempsyc commented on June 20, 2024

There is an explanation for that. The confidence interval from nice_t_test is for the effect size, Cohen's d, whereas the one from t.test is for the mean. Usually people are more interested in the effect size and its interval than the mean. You can validate that by looking at the values: for t.test the mean should fall within the interval, whereas for nice_t_test the d should fall within the interval.

from rempsyc.

rempsyc avatar rempsyc commented on June 20, 2024

I am closing this issue for now but don't hesitate to reopen it if I have not answered your question.

from rempsyc.

rempsyc avatar rempsyc commented on June 20, 2024

I think I now better understand the issue you were describing. I have decided to compare the effect size CI with that of the report package and noticed that they differed because the Cohen's d actually differed.

Demo here:

effectsize::cohens_d(mtcars$mpg, mu=10)$Cohens_d
[1] 1.674251
rempsyc::nice_t_test(data = mtcars, response = "mpg", mu = 10, warning = FALSE)$d
[1] 3.333466

effectsize::cohens_d(mtcars$cyl, mu=10)$Cohens_d
[1] -2.134752
rempsyc::nice_t_test(data = mtcars, response = "cyl", mu = 10, warning = FALSE)$d
[1] 3.464598

I believed that mu was passed automatically to the effectsize::cohens_d() function from the t.test object, but it was not (so it used the default value of 0).

This is fixed in version 0.0.3.5:

effectsize::cohens_d(mtcars$mpg, mu=10)$Cohens_d
[1] 1.674251
rempsyc::nice_t_test(data = mtcars, response = "mpg", mu = 10, warning = FALSE)$d
 [1] 1.674251

effectsize::cohens_d(mtcars$cyl, mu=10)$Cohens_d
[1] -2.134752
rempsyc::nice_t_test(data = mtcars, response = "cyl", mu = 10, warning = FALSE)$d
 [1] -2.134752

Thanks for reporting the issue.

from rempsyc.

rempsyc avatar rempsyc commented on June 20, 2024

I am closing this issue for now but don't hesitate to reopen it if I have not answered your question.

from rempsyc.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.