# Calculate p value

taking stat 101, I was wondering how I could figure out the p-value, with the hypothesis mean being equal to -4 given the data below. Could someone explain the p-value?

-

The $p$ value of a test is the probability of seeing a result at least as extreme as the one that you actually saw, assuming the null hypothesis is true.

In your example the null hypothesis is that $\mu=-4$. The standard test here is a two-sided $t$ test, where we first compute the $t$-statistic:

$$t = \frac{\bar{x} - \mu}{s / \sqrt{n}}$$

where $\bar{x}$ is the sample mean, $s$ is the sample standard deviation and $n$ is the number of observations in your sample. In your data $\bar{x}=-5.033$, $s=3.567$ and $n=90$, so

$$t = \frac{-5.033 + 4}{3.567/\sqrt{90}} = -2.747$$

This is then compared to a $t$ distribution with $n-1$ degrees of freedom to calculate a $p$ value. We want the probability that the result is at least as extreme as the one we saw, so we use a two-sided $t$ test, since $t<-2.747$ and $t>2.747$ are both considered equally extreme.

Let $T_{89}$ be a $t$-distributed random variable with 89 degrees of freedom. We have $$P(T_{89} \leq -2.747) = 0.00364$$ and $P(T_{89}\geq2.747)$ will be the same since the $t$ distribution is symmetric, which means that your $p$-value is

$$p = 2 \times 0.00364 = 0.00727$$

so your null hypothesis is rejected at the 1% significance level.

To calculate these $p$ values I used the free software package R, where I simply loaded it up and began typing at the prompt, and it returned a $p$ value:

> pt(-2.747,89)
[1] 0.003639470


If you don't have access to R but you do have access to a distribution table like this one you could use that. That table only carries degrees of freedom up to 30, and after that it has 'Inf' which represents the normal approximation.

The relevant part of the table for us is

df\p   0.005    0.0005
30     2.750    3.646
Inf    2.579    3.291


As cardinal says in the comments, with such a large number of degrees of freedom you might think of using the normal approximation, so we look at the 'inf' row. Our $t$ statistic is 2.747, which is

$$\frac{2.747-2.579}{3.291-2.579}=0.236$$

or 23.6% of the way between the entries 2.579 and 3.291. Therefore it's reasonable to think that the $p$ value is 23.6% of the way between 0.005 and 0.0005, which would put it at

$$p \approx 0.005 + (0.0005-0.005)\times 0.236 = 0.00394$$

which we can see is an absolute error of $0.0003$ compared to the true value, and a relative error of $0.00394/0.00364-1 = 0.082$, or about 8.2%.

In applications the error arising from your measurements is nearly always going to dwarf the numerical error that enters when you approximate the $p$ value like this, so it's not something that you need to worry about.

-
It is actually unclear in the question whether a one-sided or two-sided test is being asked for. Your answer spells out nicely the two-sided version. A normal approximation might often be used with such large degrees of freedom. Interestingly, the absolute error of the normal approximation is small in this case, as expected, but the relative error is a little over 20%. – cardinal Nov 10 '11 at 15:23
How did you get 0.00364? I couldn't find the value from the table. – Mark Nov 12 '11 at 7:40
I used the free software package R to calculate the $p$ value after I'd worked out the value of the $t$ statistic by hand, in which I simply had to type pt(-2.747,89). If you were using a table, you would find the closest matching values in the table and use linear interpolation. Alternatively you could use Wolfram Alpha. I'll add the linear interpolation method to my answer. – Chris Taylor Nov 12 '11 at 9:42