t-distribution in R
Asked Answered
C

2

6

I would like to find the t-value for 90% confidence interval with 17 observation.

In Excel, I can do this calculation with t=T.INV.2T(.10, 16)=1.75 however in R I cannot find the correct way to get the same result.

qt(p = 1-.9, df = 17-1) = -1.34

qt(p = (1-.9)/2, df = 17-1) = -1.75 # trying with two-tailed?

What is the function R doing the same computation as T.INV.2T in Excel.

Similarly, we have also T.DIST.2T in Excel, what is the same function in R?

Counterwork answered 26/8, 2019 at 10:43 Comment(0)
F
9

You need the 1 - .1 / 2 = 0.95 quantile from the t-distribution with 17 - 1 = 16 degrees of freedom:

qt(0.95, 16)
# [1] 1.745884

Explanation

Excel describes T.INV.2T as

Returns the two-tailed inverse of the Student's t-distribution

which is the quantile in math talk (though I would never use the term 2 tailed quantile). The p% quantile q is defined as the point which satisfies P(X <= q) >= p%.

In R we get that with the function qt (q for quantile, t for t-distribution). Now we just have to sort out what is meant by a two-tailed inverse. It turns out we are looking for the point q which satisfies P(X <= -|q| | X >= |q|) >= .1. Since the t-distribution is symmetrical this simplifies to P(X >= |q|) >= .1 / 2.

You can easily verify that in R with the use of the probability function pt:

pt(qt(0.05, 16), 16, lower.tail = TRUE) + 
pt(qt(0.95, 16), 16, lower.tail = FALSE)
# [1] 0.1
Flocculate answered 26/8, 2019 at 11:9 Comment(3)
Thanks for your great answer, one other complement to my question, if we now pretend that we know the t-value (in this case 1.75) and the number of observations (16) - how can we get the CI ? I did try pt(t_value, 16) however, I am getting 95%Counterwork
I guess this is 1 - (pt(qt(0.05, 16), 16, lower.tail = TRUE) + pt(qt(0.95, 16), 16, lower.tail = FALSE)) but I was wondering if there is a shorter form to get this value ?Counterwork
pt(t_value, 16) gives you the lower tail. pt(t_value, 16, lower.tail = FALSE) would give you 0.05. It is 0.05 (and not 0.1) because we asked for the 2 sided quantile (again not a term i would use).Flocculate
M
4

As you correctly guessed, you do it by estimating the two-sided interval (alpha/2 = 0.1/2 = 0.05)

> qt(p = 0.95, df = 16)
[1] 1.745884

So 5 % off the upper and lower interval. I don't know Excel, but I am guessing that's what that function is doing.

As for dist, that is I assume the two-sided CDF

pt(-1.745884, df=16, lower.tail=T) +
pt(1.745884, df=16, lower.tail=F)

which is equal to 0.09999994.

Malt answered 26/8, 2019 at 11:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.