Diogo Bastos Diogo Bastos - 1 month ago 13
R Question

Caculating probability using normal distribution. and t-distribution in R

I have this sample:

x=c(92L, 9L, 38L, 43L, 74L, 16L, 75L, 55L, 39L, 77L, 76L, 52L,
100L, 85L, 62L, 60L, 49L, 28L, 6L, 27L, 63L, 22L, 23L, 99L, 61L,
25L, 19L, 48L, 91L, 57L, 97L, 84L, 31L, 87L, 1L, 21L, 30L, 41L,
13L, 72L, 68L, 95L, 47L, 11L, 24L, 58L, 18L, 67L, 33L, 8L, 50L,
4L, 40L, 12L, 73L, 78L, 86L, 69L, 44L, 83L, 94L, 65L, 37L, 70L,
54L, 46L, 15L, 53L, 89L, 98L, 90L, 3L, 14L, 17L, 42L, 45L, 79L,
20L, 32L, 34L, 64L, 88L, 81L, 96L, 59L, 71L, 56L, 26L, 51L, 29L,
80L, 7L, 36L, 93L, 82L, 35L, 5L, 2L, 10L, 66L)


I want to calculate this probability:
P(x) > Mean(x) + 3
assuming that data have normal distribution.

So I do this:
mean(x) = 50.5 ; sd(x)=29.01


I generate the density distribution and calculate my probability, which now is:

P(x) > 53.5

pnorm(53.5, mean=mean(x), sd=sd(x), lower.tail=FALSE)


If I want calculating using Standard Distribution:

P(x)>(53.5) = P(z=(x-mean(x)/sd(x))) > ((53.5 - 50.5)/29.01) = P(z)>(3/29.01)

pnorm(3/29.01149, mean=0, sd=1, lower.tail=FALSE)


But when I want to use the T-Student Distribution, how can I proceed?

Answer

It is more legitimate to use t distribution here, as standard error is estimated from data.

pt(3 / sd(x), df = length(x) - 1, lower.tail = FALSE)
# [1] 0.4589245

We have length(x) number of data, but also estimate 1 parameter (standard error), so the degree of freedom for t-distribution is length(x) - 1.

There is not much difference compared with using normal distribution, though, given that length(x) is 100 (which is large enough):

pnorm(3 / sd(x), lower.tail = FALSE)
# [1] 0.4588199