0

I have these information from an independent samples t-test.

p-value=0.989
sample size for group 1 (n1)= 17
sample size for group 2 (n2)= 18
mean difference= 0.30

I need the t-statistic for this test. I did trial and error with the code for p-value to get the t-statistic, that is 0.014 2*pt(0.014, 33, lower.tail=F) #p=0.989

I need a the R code that gets the p-value and df as input, and provides 0.014 as the output.

Jazmin2252
  • 11
  • 2
  • You might have success looking at https://stats.stackexchange.com/ instead of stackoverflow, they specialize in these kinds of questions. – Max May 05 '21 at 16:18

2 Answers2

1

Find the root of the indicated function assuming that it lies between 0 and 6:

giving:

uniroot(function(x, p) p - 2 * pt(x, 33, lower.tail = FALSE), c(0, 6), p = 0.989)

giving:

$root
[1] 0.01390167

$f.root
[1] 7.863003e-06

$iter
[1] 3

$init.it
[1] NA

$estim.prec
[1] 6.103516e-05

Here is another example:

2 * pt(1.901367, 19, lower.tail = FALSE)
## [1] 0.07252959

uniroot(function(x, p) p - 2 * pt(x, 19, lower.tail = FALSE), c(0, 6), p = 0.07252959)

giving:

$root [1] 1.901365

$f.root [1] -2.672236e-07

$iter [1] 9

$init.it [1] NA

$estim.prec [1] 6.103516e-05

G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341
0

There's no need of uniroot. Use qt:

> qt(0.989/2, df = 33, lower.tail = FALSE)
[1] 0.01389174
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225