hypothesis testing data type how to statistics
What Hypothesis Testing Actually Is
Hypothesis testing is a statistical method for making decisions about a population based on sample data. You start with a claim, collect evidence, and determine whether that evidence is strong enough to reject your initial assumption.
The process sounds simple. Most tutorials make it complicated. Here's what actually matters:
- You assume nothing is happening (null hypothesis)
- You check if your data shows something unlikely under that assumption
- If it's unlikely enough, you reject the null
That's it. Everything else—p-values, significance levels, test statistics—is just machinery for executing this logic.
Why Your Data Type Determines Everything
The type of data you have dictates which hypothesis test you can use. Pick the wrong test because you misidentified your data type, and your results are garbage.
This isn't a minor technicality. It's the most common reason statistical analysis fails in practice.
The Four Fundamental Data Types
Nominal data is just names or categories with no inherent order. Gender, blood type, country of origin. You can count frequencies, but you can't do math on these values.
Ordinal data has categories with a meaningful order, but the gaps between ranks aren't necessarily equal. Education level, satisfaction ratings, military rank. You know one value is higher than another, but you can't say how much higher.
Interval data has ordered categories with equal intervals between values, but no true zero point. Temperature in Celsius or Fahrenheit is the classic example. Zero degrees doesn't mean "no temperature."
Ratio data has all the properties of interval data plus a true zero point. Weight, height, time, income. Zero means the absence of the quantity. You can calculate meaningful ratios—something that weighs 100kg is twice as heavy as something that weighs 50kg.
Discrete vs. Continuous: The Other Classification
You also need to know whether your data is discrete or continuous.
Discrete data takes specific values, often whole numbers. Number of children, dice rolls, number of defects in a batch.
Continuous data can take any value within a range. Height can be 170.1234cm. Time can be measured to infinite precision.
This distinction matters because many statistical tests assume continuous data or behave differently with discrete counts.
Matching Data Types to Hypothesis Tests
Here's where most people get lost. You have data, you need a test—what do you do?
Tests for Continuous Data
When your data is continuous, you typically use parametric tests. These tests assume your data follows a specific distribution, usually normal.
- t-tests — Compare means between one or two groups. One-sample t-test checks if a sample mean differs from a known value. Two-sample t-test compares means between two independent groups. Paired t-test compares means when the same subjects are measured twice.
- ANOVA — Compares means across three or more groups. One-way ANOVA tests one categorical variable. Two-way ANOVA tests two categorical variables and their interaction.
- Correlation and regression — Measure relationships between continuous variables. Pearson correlation assumes normal distribution. Spearman correlation works with ordinal or non-normal continuous data.
- Chi-square tests — Can work with categorical data but also apply to goodness-of-fit tests for distributions.
Tests for Categorical Data
Categorical data requires non-parametric tests. These don't assume any particular distribution.
- Chi-square test of independence — Tests whether two categorical variables are related. Does smoking status relate to lung cancer diagnosis?
- Fisher's exact test — Like chi-square but better for small sample sizes. Use when expected cell counts are below 5.
- McNemar's test — Compares proportions in paired nominal data. Did a treatment change the proportion of patients who recovered?
- Cochran's Q test — Extension of McNemar's for more than two time points.
Tests for Ordinal Data
Ordinal data sits in an awkward middle ground. You can rank values, but the intervals aren't equal. Use tests that work with ranks.
- Mann-Whitney U test — Non-parametric alternative to the independent t-test. Compares whether one group tends to have larger values than another.
- Wilcoxon signed-rank test — Non-parametric alternative to the paired t-test.
- Kruskal-Wallis test — Non-parametric alternative to one-way ANOVA.
- Spearman's rank correlation — Measures monotonic relationships between ordinal variables.
Test Selection Cheat Sheet
| Your Data | Groups/Variables | Best Test |
|---|---|---|
| Continuous, normal | 1 group vs. known value | One-sample t-test |
| Continuous, normal | 2 independent groups | Independent t-test |
| Continuous, normal | 2 paired measurements | Paired t-test |
| Continuous, normal | 3+ independent groups | One-way ANOVA |
| Ordinal or non-normal continuous | 2 independent groups | Mann-Whitney U test |
| Ordinal or non-normal continuous | 2 paired measurements | Wilcoxon signed-rank test |
| Categorical | 2 categorical variables | Chi-square test |
| Categorical, small samples | 2 categorical variables | Fisher's exact test |
How to Run a Hypothesis Test: Step by Step
Let's walk through the actual process. I'll use a practical example: you're comparing conversion rates between two landing page designs.
Step 1: State Your Hypotheses
The null hypothesis (H₀) represents the default assumption—no effect, no difference, no relationship. The alternative hypothesis (H₁ or Hₐ) is what you're trying to prove.
In our example:
- H₀: The conversion rates are the same for both designs
- H₁: The conversion rates are different
Choose your alternative carefully. A two-tailed test checks for any difference. A one-tailed test checks if one value is specifically greater than or less than the other. One-tailed tests are more powerful for detecting effects in one direction, but you better have a strong theoretical reason for that direction.
Step 2: Choose Your Significance Level
The significance level (α) is your threshold for rejecting the null. The standard is 0.05, meaning you'll reject H₀ if there's less than a 5% chance of seeing your results if H₀ were true.
0.05 isn't magic. It's just convention. In fields like pharmaceutical trials, 0.01 or 0.001 might be required. In exploratory research, 0.10 might be acceptable. Know your field's standards.
Step 3: Collect Data and Check Assumptions
Before running any test, verify your data meets the test's assumptions. This step is where most people cut corners, and it costs them.
For a two-proportion z-test comparing conversion rates:
- Random sampling or assignment
- Independent observations
- Large enough sample size (typically n × p > 10 and n × (1-p) > 10 for each group)
For t-tests and ANOVA:
- Approximately normal distribution (or large enough sample size that CLT kicks in)
- Homogeneity of variance (or use Welch's version if violated)
- Independence of observations
Step 4: Calculate the Test Statistic
Run the calculation. With software like R, Python, or even a good calculator, this is straightforward. The test statistic converts your data into a single number that represents how far your sample estimate is from what you'd expect under the null hypothesis.
For our conversion rate example, you'd calculate:
z = (p₁ - p₂) / √(p(1-p)(1/n₁ + 1/n₂))
Where p₁ and p₂ are your sample proportions, and p is the pooled proportion.
Step 5: Find the P-Value
The p-value tells you the probability of seeing your results (or more extreme results) if the null hypothesis were actually true.
Small p-value = surprising data under H₀ = evidence against H₀.
A p-value of 0.03 means there's a 3% chance of observing what you observed if the null were true. That's low enough that most people reject H₀.
Stop here and address a common misconception: the p-value is not the probability that H₀ is true. It is not the probability you made a mistake. It tells you nothing about practical significance, only statistical significance.
Step 6: Make Your Decision
Compare p-value to α:
- p ≤ α: Reject H₀. Your data provides sufficient evidence against the null.
- p > α: Fail to reject H₀. Your data doesn't provide sufficient evidence to reject the null.
Note: "Fail to reject H₀" is not the same as "prove H₀ is true." Absence of evidence is not evidence of absence.
Common Mistakes That Kill Your Analysis
Ignoring assumptions. Running a t-test on highly skewed data without checking. Using chi-square when expected frequencies are too low. These violations don't just reduce accuracy—they can completely invalidate your results.
Multiple comparisons without correction. Running 20 tests at α = 0.05 means you'd expect one significant result purely by chance. Use Bonferroni correction or other methods when testing multiple hypotheses.
Confusing statistical and practical significance. With a large enough sample, you'll detect tiny, meaningless differences. A 0.1% increase in conversion rate might be statistically significant but practically useless if it costs $2 million to implement.
Misunderstanding what p-values mean. They don't tell you the probability your hypothesis is correct. They don't measure effect size. They don't prove causation. They're just one piece of evidence in a larger decision process.
Ignoring effect size. Statistical significance without effect size is incomplete. Cohen's d, odds ratios, R²—pick a measure that tells you how big the effect actually is, not just that it exists.
Getting Started with Implementation
You don't need expensive software. Here's what actually works:
In Python
from scipy import stats
# Two-sample t-test
t_stat, p_value = stats.ttest_ind(group1, group2)
# Mann-Whitney U test
stat, p_value = stats.mannwhitneyu(group1, group2)
# Chi-square test
chi2, p_value, dof, expected = stats.chi2_contingency(contingency_table)
# ANOVA
f_stat, p_value = stats.f_oneway(group1, group2, group3)
In R
# Two-sample t-test
t.test(group1 ~ group2, data = mydata)
# Chi-square test
chisq.test(contingency_table)
# ANOVA
anova(lm(outcome ~ group, data = mydata))
In Excel or Google Sheets
For basic tests, the Data Analysis ToolPak (Excel) or built-in functions work:
- t-test: =TTEST(array1, array2, tails, type)
- Chi-square: CHITEST(actual_range, expected_range)
- Correlation: =CORREL(array1, array2)
Excel is fine for simple analyses. For anything complex, move to R or Python.
When to Use Which Approach
Start with visualization. Plot your data before running any test. Histograms, box plots, scatter plots. Most assumption violations and data problems are obvious when you look.
Then check assumptions formally if you have time, or at least acknowledge when you're violating them and why you think it's acceptable to proceed anyway.
When in doubt about which test to use, work through this decision tree:
- How many variables are you analyzing? One, two, or more?
- What type of data does each variable contain?
- Are you comparing groups, measuring relationships, or checking fit to a distribution?
- What are your assumptions about the data distribution?
Your answers narrow down the possibilities to one or two appropriate tests.
The Bottom Line
Hypothesis testing isn't complicated. The machinery is straightforward. The hard part is:
- Knowing your data type before you start
- Choosing a test that matches your data and your question
- Checking assumptions rather than assuming they're met
- Interpreting results correctly—p-values don't do what most people think they do
Master those four things, and you can run circles around people who've memorized dozens of test names without understanding when to use them.