How to calculate p value for continuous variable
Use this interactive calculator to estimate a p value for a continuous outcome using either a z test or a one-sample t test. Enter your sample mean, hypothesized mean, sample size, variability, and tail type. The tool calculates the test statistic, p value, confidence-style interpretation, and a chart that visualizes the probability distribution and extreme regions.
P value calculator
Expert guide: how to calculate p value for continuous variable
When researchers work with a continuous variable such as blood pressure, cholesterol, reaction time, body mass index, hemoglobin A1c, exam score, or daily energy intake, one of the most common inferential questions is whether the observed mean differs enough from a reference value to be considered statistically significant. That is where the p value comes in. A p value measures how compatible your observed data are with the null hypothesis. In practical terms, it tells you how unusual your sample result would be if the null hypothesis were actually true.
For continuous data, the p value is usually calculated from a test statistic derived from the difference between an observed sample mean and a null or hypothesized mean, scaled by the amount of variability in the data. The most common settings are the one-sample z test, the one-sample t test, the independent samples t test, and regression-based tests. This calculator focuses on a very common introductory case: a one-sample test for a continuous outcome.
Core idea: for a continuous variable, calculate a test statistic first, then convert that statistic into a p value using the appropriate probability distribution. If the population standard deviation is known, a z test may be used. If it is unknown, a t test is usually preferred.
What is a p value?
A p value is the probability of observing a test statistic at least as extreme as the one you obtained, assuming the null hypothesis is true. It is not the probability that the null hypothesis is true, and it is not the probability that your findings happened “by chance” in a casual sense. Instead, it is a model-based tail probability.
- Small p value: your observed result would be relatively unusual under the null hypothesis.
- Large p value: your observed result is reasonably compatible with the null hypothesis.
- Common threshold: many studies use alpha = 0.05, but that threshold should be chosen based on study design, field norms, and consequences of errors.
When continuous variables require a z test or t test
Suppose you measured systolic blood pressure in a sample of adults and want to know whether the average differs from 120 mmHg. Because blood pressure is continuous, you would typically compare the sample mean with the hypothesized population mean. The test you use depends mainly on what you know about the standard deviation:
- One-sample z test: use when the population standard deviation is known and assumptions are met.
- One-sample t test: use when the population standard deviation is unknown and you estimate it with the sample standard deviation.
In real research, the t test is more common because the true population standard deviation is rarely known. The t distribution is wider than the normal distribution for small samples, which properly reflects added uncertainty from estimating variability.
The formulas you need
For a one-sample test with a continuous variable, define the following:
- x̄ = sample mean
- μ₀ = hypothesized mean under the null hypothesis
- s = sample standard deviation
- σ = population standard deviation
- n = sample size
Z statistic:
z = (x̄ – μ₀) / (σ / √n)
T statistic:
t = (x̄ – μ₀) / (s / √n)
Once the test statistic is computed, the p value comes from either the standard normal distribution or the t distribution with n – 1 degrees of freedom.
Step by step: how to calculate p value for continuous variable
- State hypotheses. For example, H₀: μ = 110 and H₁: μ ≠ 110 for a two-tailed test.
- Choose tail type. Use two-tailed if you care about any difference, right-tailed if you only care whether the mean is greater, and left-tailed if you only care whether the mean is smaller.
- Compute the standard error. This is the standard deviation divided by the square root of the sample size.
- Compute the test statistic. Divide the mean difference by the standard error.
- Convert the statistic to a p value. Use the standard normal distribution for z or the t distribution for t.
- Compare p with alpha. If p is less than alpha, reject the null hypothesis.
- Interpret in context. Explain the finding in terms of the actual continuous variable.
Worked example with a continuous health variable
Imagine a clinic wants to test whether mean fasting glucose in a sample of adults differs from a reference value of 100 mg/dL. Suppose the sample mean is 106, the sample standard deviation is 18, and the sample size is 49. Because population standard deviation is unknown, use a one-sample t test.
- Null hypothesis: H₀: μ = 100
- Alternative hypothesis: H₁: μ ≠ 100
- Standard error = 18 / √49 = 18 / 7 = 2.571
- t statistic = (106 – 100) / 2.571 = 2.333
- Degrees of freedom = 49 – 1 = 48
- Two-tailed p value is about 0.024
Because 0.024 is less than 0.05, the sample provides evidence that the mean fasting glucose differs from 100 mg/dL. Notice that the p value does not tell you whether the difference is clinically meaningful. It only quantifies statistical evidence against the null model.
Comparison table: z test versus t test for continuous variables
| Feature | One-sample z test | One-sample t test |
|---|---|---|
| When used | Population standard deviation is known | Population standard deviation is unknown |
| Reference distribution | Standard normal distribution | t distribution with n – 1 degrees of freedom |
| Test statistic | z = (x̄ – μ₀) / (σ / √n) | t = (x̄ – μ₀) / (s / √n) |
| Effect of small sample size | Can underestimate uncertainty if σ is not truly known | Accounts for added uncertainty with heavier tails |
| Example statistic | z = 1.96 gives two-tailed p about 0.050 | t = 2.01 with df = 20 gives two-tailed p about 0.058 |
Real-world benchmark statistics used in health research
Many continuous biomedical variables are summarized with means and standard deviations before formal hypothesis testing. The examples below use commonly reported reference-style values from public health and clinical literature contexts to illustrate how continuous variables are interpreted. Exact study-specific p values depend on the sample and design, but these numbers show the kinds of scales analysts work with.
| Continuous variable | Illustrative adult reference or observed statistic | Why p value testing may be used |
|---|---|---|
| Systolic blood pressure | Clinical threshold often discussed around 120 mmHg for normal range context | Test whether a sample mean differs from a benchmark or pre-intervention level |
| Fasting plasma glucose | Normal fasting glucose commonly referenced below 100 mg/dL | Assess whether a sample mean is elevated compared with a clinical target |
| Total cholesterol | Desirable total cholesterol often referenced below 200 mg/dL | Determine whether a program changed average lipid levels |
| Body mass index | Overweight threshold begins at 25 kg/m² | Test if a sample mean differs across population groups or time points |
How tail choice changes the p value
The same test statistic can lead to different p values depending on the hypothesis direction. If your result is in the expected direction and you specified a one-sided hypothesis before looking at the data, the one-tailed p value can be about half the two-tailed p value. However, choosing a one-tailed test after seeing the data is not good practice. Tail choice should be justified in advance.
- Two-tailed: asks whether the mean is different in either direction.
- Right-tailed: asks whether the mean is greater than the null value.
- Left-tailed: asks whether the mean is less than the null value.
Assumptions behind p value calculations for continuous data
Any p value is only as trustworthy as the assumptions behind the test. For one-sample tests on a continuous variable, common assumptions include:
- The observations are independent.
- The variable is measured on a continuous or approximately continuous scale.
- The sample distribution is approximately normal, especially for smaller sample sizes.
- For a z test, the population standard deviation is known.
With larger samples, the central limit theorem often makes the sampling distribution of the mean approximately normal even if raw data are somewhat skewed. But severe skewness, heavy outliers, clustering, or repeated measures can make a simple p value misleading unless you use a more appropriate model.
Common mistakes when calculating a p value for a continuous variable
- Using the wrong standard deviation. A z test needs the population standard deviation, not the sample standard deviation.
- Ignoring the sample size. The standard error shrinks as sample size grows, which can make small mean differences statistically significant.
- Confusing significance with importance. A tiny p value can correspond to a trivial effect if the sample is large enough.
- Using one-tailed tests without justification. Directional hypotheses must be set before examining results.
- Violating independence. Repeated measurements on the same person require paired or longitudinal methods, not a simple one-sample test.
How to report results clearly
A polished write-up should include the mean difference, standard deviation or standard error, test statistic, degrees of freedom if relevant, p value, and substantive interpretation. For example:
The sample mean fasting glucose was 106 mg/dL, which was higher than the hypothesized reference value of 100 mg/dL. A one-sample t test showed that this difference was statistically significant, t(48) = 2.33, p = 0.024.
Whenever possible, also report a confidence interval and an effect size, because a p value alone does not describe the magnitude or precision of the effect.
Useful authoritative resources
For deeper statistical guidance and public health context, review these trusted sources:
- NIST Engineering Statistics Handbook
- NCBI Bookshelf statistical methodology resources
- Boston University School of Public Health probability and inference materials
Bottom line
If you want to know how to calculate p value for continuous variable data, the workflow is straightforward: identify the null mean, compute the standard error, calculate a z or t statistic, and convert that statistic into a tail probability using the appropriate distribution. The final p value helps you judge how unusual your sample mean would be if the null hypothesis were correct. Used properly, it is a valuable inferential tool, especially when combined with confidence intervals, effect sizes, and subject-matter knowledge.