djnavarro / lsr

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

`conf.level` argument for oneSampleTTest is not responsive #9

Open czopluoglu opened 2 years ago

czopluoglu commented 2 years ago

Hi,

Thank you for the package and textbook. Students enjoy it very much.

We realized that the conf.level argument for the oneSampleTTest() function is not responsive to what is requested. The following code returns the same interval.

likert <- c(3,1,4,1,4,6,7,2,6,6,7)
oneSampleTTest( x = likert, mu = 4, conf.level=.99)
oneSampleTTest( x = likert, mu = 4, conf.level=.95)

I checked the code for this function https://github.com/djnavarro/lsr/blob/master/R/oneSampleTTest.R

It looks like it doesn't pass the input to the t.test function at Line 98.

 # run the ttest
  htest <- stats::t.test( x=x, mu=mu, alternative=one.sided )

So, regardless of what the user says, it always uses the default confidence interval for the t.test() function, which is 0.95.

I think a modification for Line 98 should fix the problem.

 # run the ttest
  htest <- stats::t.test( x=x, mu=mu, alternative=one.sided , conf.level = conf.level)