Michael
Michael

Reputation: 2566

t-distribution in R

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?

Upvotes: 6

Views: 6902

Answers (2)

thothal
thothal

Reputation: 20329

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

Upvotes: 9

user2974951
user2974951

Reputation: 10375

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.

Upvotes: 4

Related Questions