How to calculate p value from distribution of test statistic

I was wondering how I can calculate p-value from a distribution of test statistic manually?

Regards,

• Are you familiar with the definition of a p-value? [If not, see the first sentence here.] That pretty much explains how to obtain it - you find the probability (under the null) of obtaining a test statistic at least as extreme as the sample test statistic, so if you have the null distribution, you find the relevant area. What counts as "at least as extreme" depends on your alternative. It's easier to explain if you ask about a specific example. – Glen_b Nov 4 '14 at 4:30
• @ Glen_b how null distribution can be calculated for a given test statistic? – Alph Nov 4 '14 at 14:35
• Your question above assumes you have the distribution. If you want to explore the very different issue of obtaining it, that would be a new question. – Glen_b Nov 5 '14 at 1:25
• @ Glen_b so if the distribution is given then it always be null distribution ? – Alph Nov 5 '14 at 1:53
• When you say in your question "from a distribution of test statistic", it's up to you to define what, exactly you mean by that. I took you to be talking about the null distribution because otherwise the question makes no sense (you can't work out p-values from things that aren't the null distribution!). You tell me what you're asking about in the original question, and then I can answer relative to what you're specifying. So is the question asking about the null distribution or not? – Glen_b Nov 5 '14 at 2:47

If your statistics is given by a probability density function $f(x)$ and you observe statistics $x_0$, then your p-value is typically $$\int_{x_0}^{\infty} f(x)~\mathrm{d}x$$ or $$\int_{-\infty}^{x_0} f(x)~\mathrm{d}x$$ depending on which side of the tail you're looking.
If instead your statistics is given as a sample, the p-value will be the quantile of $x_0$ in that sample.
• @Phil2014: In R, for example, if your test statistics are in the vector X, you would do something like quantile (X, c(0.025, 0.975)) (two-sided) or quantile (X, 0.95) (one-sided). – Wayne Nov 4 '14 at 16:49