ANCOVA Explained: Uses, Assumptions, Best Practices, Python
ANCOVA helps researchers compare group outcomes while adjusting for variables such as baseline scores, age, or prior performance. This guide explains when to use ANCOVA, how to check its assumptions, interpret adjusted means, choose the right software, and avoid common statistical mistakes.
ANCOVA Explained: Uses, Assumptions, Best Practices, Python & More
A practical guide to Analysis of Covariance with simple explanations, assumptions, adjusted means, Python and R code, plots, and reporting tips.
- What Is ANCOVA?
- What Is a Covariate?
- Why Is ANCOVA Used?
- How ANCOVA Works
- ANCOVA Formula
- The Most Important Assumption: Similar Regression Slopes
- A Practical ANCOVA Example
- How to Perform ANCOVA in Python
- How to Perform ANCOVA in R
- How to Perform ANCOVA in SPSS
- ANCOVA in jamovi
- Best Practices for ANCOVA
- Common ANCOVA Mistakes
- How to Report ANCOVA Results
- Frequently Asked Questions About ANCOVA
What Is ANCOVA?
ANCOVA stands for Analysis of Covariance. It is a statistical method used to compare the average values of two or more groups while also taking one or more numerical variables into account.
In simple terms, ANCOVA combines ideas from ANOVA and regression. ANOVA compares group means. Regression describes how a numerical variable is related to an outcome. ANCOVA does both at the same time. It compares groups after accounting for a numerical variable that may also influence the outcome. That numerical variable is called a covariate.
A common example is an education study. Researchers may compare final exam scores across three teaching methods while adjusting for students' baseline test scores. The adjustment helps make the group comparison fairer when starting ability is related to the final result.
What Is a Covariate?
A covariate is a numerical variable that is related to the outcome but is not usually the main factor being studied. Baseline measurements are common covariates because they describe where participants started before a treatment or intervention.
Useful covariates should have a clear scientific or practical reason for inclusion. Adding variables simply because they reduce a p-value can make the analysis harder to trust.
| Research area | Outcome | Main group | Possible covariate |
|---|---|---|---|
| Education | Final test score | Teaching method | Baseline score |
| Medicine | Blood pressure after treatment | Treatment group | Initial blood pressure |
| Marketing | Customer spending | Campaign | Previous spending |
| Agriculture | Crop yield | Fertilizer | Initial soil quality |
| Psychology | Final performance score | Intervention | Pre-test score |
Why Is ANCOVA Used?
ANCOVA is mainly used for statistical adjustment and precision. Statistical adjustment lets researchers compare groups at the same covariate value. Precision can improve when the covariate explains part of the variation in the outcome, leaving less unexplained variation in the model.
This does not mean that more covariates are always better. Weak or unnecessary covariates can make the model harder to explain and can use valuable degrees of freedom.
How ANCOVA Works
Imagine two training programs. People with higher starting skills are likely to get higher final scores regardless of the program they receive. If one program happens to contain more highly skilled people at the beginning, comparing the raw final averages may give that program an unfair advantage.
ANCOVA estimates the relationship between starting score and final score, then compares the programs while holding the starting score at a common value. The resulting group estimates are often called adjusted means or estimated marginal means.

ANCOVA Formula
For a simple ANCOVA with one group variable and one covariate, the model can be written as:
Here, Y is the outcome, X is the covariate, beta0 is the intercept, beta1 describes the covariate-outcome relationship, the group effect represents differences between groups, and the error term represents unexplained variation.
This is why ANCOVA is closely related to multiple linear regression. The group variable is represented as a categorical predictor and the covariate enters as a numerical predictor.
The Most Important Assumption: Similar Regression Slopes
A standard ANCOVA assumes that the relationship between the covariate and the outcome is reasonably similar across groups. This is often called the homogeneity of regression slopes assumption.
A practical way to check it is to fit a group by covariate interaction. If that interaction is important, the effect of the covariate changes by group. In that case, one common adjusted group difference may hide the real pattern and the interaction should usually remain in the model.

| Assumption | What it means | Practical check |
|---|---|---|
| Continuous outcome | The dependent variable is numerical | Confirm measurement scale |
| Independent observations | One observation should not improperly determine another | Review study design |
| Linear relationship | Covariate and outcome are approximately linearly related | Grouped scatter plot |
| Similar regression slopes | Covariate-outcome slopes are similar across groups | Group × covariate interaction |
| Reasonably constant error variance | Residual spread is not dramatically different across groups | Residual plots |
| Reasonably normal residuals | Model errors are approximately normal for standard inference | Q-Q plot |
| Reliable covariate | Covariate is measured with acceptable quality | Review measurement method |
| Adequate overlap | Groups cover similar covariate ranges | Grouped scatter plot |
Covariate Overlap Matters
ANCOVA works best when the groups contain observations across similar ranges of the covariate. If one group contains only low covariate values and another contains only high values, an adjusted comparison may rely heavily on extrapolation.
A grouped scatter plot is one of the best early checks. It can reveal poor overlap, unusual values, nonlinearity, and different slopes before the formal model is fitted.

Types of ANCOVA
The right ANCOVA structure depends on the number of categorical factors, the number of covariates, and whether measurements are independent or repeated.
| Type | Structure | Example |
|---|---|---|
| One-way ANCOVA | One factor + covariate | Compare teaching methods while adjusting for pre-test score |
| Two-way ANCOVA | Two factors + covariate | Compare treatment and sex while adjusting for age |
| Factorial ANCOVA | Two or more factors + covariates | Study treatment, age group, and site together |
| Multiple-covariate ANCOVA | Factor(s) + several covariates | Adjust for baseline, age, and BMI |
| Repeated-measures ANCOVA | Repeated observations + covariate(s) | Compare time points while adjusting for baseline |
ANCOVA vs ANOVA
ANOVA compares group means. ANCOVA also compares group means, but it includes one or more numerical covariates. For example, ANOVA might ask whether final weights differ across three diets, while ANCOVA might ask whether final weights differ after adjusting for starting weight.
| Feature | ANOVA | ANCOVA |
|---|---|---|
| Compares group means | Yes | Yes |
| Categorical factors | Yes | Yes |
| Numerical covariates | Usually no | Yes |
| Adjusted group comparison | No | Yes |
| General linear model | Yes | Yes |
ANCOVA vs Regression
ANCOVA and multiple linear regression use the same general linear model framework. The name ANCOVA is often used when the main goal is to compare categorical groups after adjusting for continuous variables. Regression language is often used when the focus is on estimating relationships among predictors and an outcome.
ANCOVA vs Change Scores
When data are measured before and after treatment, researchers sometimes compare change scores instead of using ANCOVA. A change-score analysis focuses on how much participants changed. A baseline-adjusted ANCOVA focuses on post-treatment differences after accounting for the baseline value.
These approaches do not always answer exactly the same question. The best choice depends on the study design and the scientific question.
A Practical ANCOVA Example
Suppose a researcher compares a control group with two training programs. Every participant has a baseline score and a final score. Baseline ability predicts the final result, so the researcher includes it as a covariate.
After checking that the group by baseline interaction is not important, the researcher fits a common-slope ANCOVA. The adjusted means show the expected final score for each group at the same baseline value. The example below is illustrative rather than data from a real experiment.
| Group | Mean baseline | Raw final mean | Adjusted mean |
|---|---|---|---|
| Control | 63.0 | 62.9 | 63.0 |
| Treatment A | 63.2 | 68.2 | 68.1 |
| Treatment B | 63.3 | 72.5 | 72.4 |

How to Perform ANCOVA in Python
Python offers several good options for ANCOVA. statsmodels is useful when you want full control over model formulas, diagnostics, and interactions. Pingouin provides a shorter interface for common ANCOVA tasks.
statsmodels example
import statsmodels.api as sm
from statsmodels.formula.api import ols
# Check the equal-slopes assumption
interaction_model = ols(
'post_score ~ C(group) * baseline_score',
data=df
).fit()
print(sm.stats.anova_lm(interaction_model, typ=2))
# Common-slope ANCOVA if appropriate
model = ols(
'post_score ~ C(group) + baseline_score',
data=df
).fit()
print(sm.stats.anova_lm(model, typ=2))
Pingouin example
import pingouin as pg
result = pg.ancova(
data=df,
dv='post_score',
between='group',
covar='baseline_score'
)
print(result)
Getting Adjusted Means in Python
Adjusted means can be obtained by predicting each group at a common covariate value, often the overall mean of the covariate. This makes the group comparison easier to understand than reporting only a p-value.
mean_baseline = df['baseline_score'].mean()
new_data = pd.DataFrame({
'group': ['Control', 'Treatment A', 'Treatment B'],
'baseline_score': [mean_baseline] * 3
})
new_data['adjusted_mean'] = model.predict(new_data)
print(new_data)
Checking ANCOVA Assumptions in Python
Useful checks include a grouped scatter plot, the group by covariate interaction, a residual versus fitted plot, and a Q-Q plot of residuals. The goal is not to mechanically pass a checklist. The goal is to understand whether the model is a reasonable description of the data.
import matplotlib.pyplot as plt
import statsmodels.api as sm
sm.qqplot(model.resid, line='45')
plt.show()
plt.scatter(model.fittedvalues, model.resid)
plt.axhline(0)
plt.xlabel('Fitted values')
plt.ylabel('Residuals')
plt.show()
How to Perform ANCOVA in R
R can fit ANCOVA directly with lm(). A common workflow is to test the group by covariate interaction first, then fit the simpler common-slope model if that is appropriate. Packages such as emmeans can be used to obtain adjusted means and pairwise comparisons.
# Check the interaction first
interaction_model <- lm(
post_score ~ group * baseline_score,
data = df
)
anova(interaction_model)
# Fit the common-slope model if appropriate
model <- lm(
post_score ~ group + baseline_score,
data = df
)
anova(model)
summary(model)
library(emmeans)
emmeans(model, ~ group)
How to Perform ANCOVA in SPSS
In SPSS, ANCOVA is normally run through Analyze > General Linear Model > Univariate. Put the outcome in Dependent Variable, the group variable in Fixed Factor(s), and the numerical adjustment variable in Covariate(s). Include the factor by covariate interaction when checking whether slopes are homogeneous.
ANCOVA in jamovi
jamovi provides a menu-based ANCOVA procedure that can include categorical factors and numerical covariates. It can also produce effect sizes, assumption checks, estimated marginal means, and plots, which makes it useful for teaching and smaller research projects.

| Software | Best for | Main advantage |
|---|---|---|
| Python | Data science and reproducible analysis | Combines modelling, data preparation, automation, and reporting |
| R | Statistical research | Flexible modelling and strong post-hoc tools |
| SPSS | GUI-based academic and business work | Familiar menus and extensive GLM output |
| jamovi | Beginners and teaching | Simple interface with useful assumption checks and adjusted means |
Best Practices for ANCOVA
Choose covariates before examining the final outcome results when possible. Prefer variables that have a clear scientific reason for inclusion and are measured before the treatment or exposure of interest.
Plot the outcome against each important covariate by group, test the group by covariate interaction, avoid unnecessary predictors, inspect residuals, report adjusted means with confidence intervals, and explain clearly what was adjusted for.
In observational research, use careful language. Saying 'after adjusting for age' is often more accurate than implying that age has been completely controlled. Statistical adjustment cannot guarantee that all confounding has been removed.
Randomized vs Observational Studies
In randomized studies, groups should be similar at baseline on average, although chance differences can still occur. A strong pre-treatment covariate can improve precision. In observational studies, groups may differ systematically before the analysis begins. ANCOVA can describe adjusted differences, but those differences should not automatically be interpreted as causal effects.
Factorial ANCOVA
Factorial ANCOVA includes two or more categorical factors together with one or more numerical covariates. For example, a study might examine treatment, sex, age, and blood pressure in one model. The model can estimate main effects and interactions while adjusting for the covariate.
Multiple Covariates in ANCOVA
ANCOVA can include several covariates, such as baseline score, age, and body mass index. Every additional variable should have a clear purpose. Too many weak covariates can make interpretation harder, increase missing-data problems, and overfit small datasets.
What If the Group by Covariate Interaction Is Significant?
If the interaction is important, the group difference changes as the covariate changes. Removing the interaction and reporting a single overall adjusted difference can be misleading.
A better approach is to keep the interaction and report group differences at meaningful covariate values, such as low, average, and high baseline scores.
Effect Size in ANCOVA
A p-value tells you whether the data provide evidence of an effect, but it does not show how large that effect is. Partial eta squared is commonly reported for ANCOVA. Adjusted mean differences and confidence intervals are also useful because they show the size of the effect in the original measurement units.
When ANCOVA Is Not the Best Choice
ANCOVA is designed for a continuous outcome in a general linear model. Binary outcomes may require logistic regression, counts may require Poisson or negative binomial regression, clustered data may require multilevel models, and repeated measurements may be better handled by mixed-effects models. Strongly nonlinear relationships may require nonlinear terms or splines.
| Situation | Possible alternative |
|---|---|
| Binary outcome such as yes/no | Logistic regression |
| Count outcome | Poisson or negative binomial regression |
| Repeated observations from the same participant | Mixed-effects model |
| Participants clustered within schools or hospitals | Multilevel model |
| Strongly nonlinear covariate relationship | Regression with nonlinear terms or splines |
| Time-to-event outcome | Survival analysis |
Common ANCOVA Mistakes
Common mistakes include choosing covariates after seeing which model gives the smallest p-value, ignoring the group by covariate interaction, interpreting adjusted observational results as causal, comparing groups far outside their overlapping covariate range, and reporting only a p-value without adjusted means or effect sizes.
How to Report ANCOVA Results
A useful report should identify the outcome, group factor, covariate, slope check, F-statistic, degrees of freedom, p-value, effect size, adjusted means, and confidence intervals when available.
Example: A one-way ANCOVA compared final scores across three training groups while adjusting for baseline score. The group by baseline interaction was not statistically important, supporting a common-slope model. After adjustment, final scores differed across groups. Adjusted means and confidence intervals should be reported to show the direction and size of those differences.
Final Thoughts
ANCOVA is useful when raw group averages do not tell the whole story. It compares groups while accounting for numerical variables that are also related to the outcome.
The calculation itself is usually easy in Python, R, SPSS, or jamovi. The important work is choosing meaningful covariates, checking the group by covariate relationship, confirming adequate overlap, examining residuals, and interpreting adjusted means carefully.
Used well, ANCOVA can make comparisons more precise and informative. Used without these checks, adjustment can make a result look more convincing than the data actually support.
Frequently Asked Questions About ANCOVA
What does ANCOVA stand for?
ANCOVA stands for Analysis of Covariance. It combines group comparison with regression-style adjustment for numerical variables.
What is ANCOVA used for?
It is used to compare group means while accounting for one or more covariates that are related to the outcome.
What is the difference between ANOVA and ANCOVA?
ANOVA compares group means. ANCOVA compares group means while also including one or more numerical covariates.
Can ANCOVA be done in Python?
Yes. statsmodels and Pingouin are common Python choices. statsmodels is especially useful when you need interactions and detailed model control.
Can ANCOVA include more than one covariate?
Yes. Several covariates can be included when each has a clear purpose and the sample size supports the model.
What is the most important ANCOVA assumption?
One of the key additional assumptions is that the covariate-outcome relationship is reasonably similar across groups when a common-slope model is used.
What happens if slopes are different?
The group effect depends on the covariate value. The interaction should usually be kept and interpreted instead of forcing one common adjusted difference.
Does ANCOVA remove confounding?
No. It adjusts for measured variables in the model, but it cannot guarantee that all confounding has been removed, especially in observational studies.
Does ANCOVA increase statistical power?
It can when the covariate strongly predicts the outcome. A weak or unnecessary covariate may add little benefit.
References and Further Reading
- QCBS R Workshop - Analysis of Covariance (ANCOVA)
- Frontiers in Psychology - ANCOVA tutorial and methodological discussion
- R-bloggers - How to Perform ANCOVA with R
- Statistics Solutions - Factorial ANCOVA
- NCSS PASS - Analysis of Covariance (ANCOVA)
- ScienceDirect Topics - Analysis of Covariance
- statsmodels - anova_lm
- Pingouin - ANCOVA
- jamovi ANCOVA documentation

