# Fear conditioning freezing statistics: per-tone t-tests, extinction curves and what counts as n

> Analyse percent freezing with one value per mouse: a mean or an extinction slope per mouse, or a repeated-measures model with a sphericity correction. A t-test at every tone, or tones as n, gives false positives. Python and R code.

Canonical: https://www.licklider.ai/guides/fear-conditioning-freezing/
Section: Guides › Repeated measurements over time
Author: Licklider · Published 2026-11-12 · Last reviewed 2026-11-12 (UTC)

> **Quick answer.** Freezing is scored many times per mouse, but the **mouse** received the genotype or treatment, so each mouse should give one number. Decide the question first: **mean freezing** per mouse for "do the groups freeze differently?", or each mouse's **extinction slope** (how fast its freezing falls across tones) for "do they extinguish at different rates?", and compare groups with a Welch t-test. Or fit a **repeated-measures ANOVA** with the **Greenhouse–Geisser correction**, or a mixed model with a random intercept and slope per mouse and small-sample degrees of freedom. In a simulation of 10 vs 10 mice and 20 tones with no real difference, a **t-test at each tone** found at least one "significant" tone in 36.0% of studies and **tones as n** found a difference in 51.9%; mean freezing per mouse gave 4.9% and the slope per mouse 5.2%.

**Terms used below.** *Fear conditioning*: a tone (or context) is paired with a mild foot shock; afterwards the animal freezes to the tone. *Freezing*: absence of movement except breathing, scored as the percentage of time. *Percentage points*: differences between percentages (60% to 50% is 10 points). *Extinction*: the decline in freezing when the tone is presented repeatedly without shock. *Tone (trial)*: one presentation, here 30 s. *Extinction slope*: the straight-line change in a mouse's freezing per tone, in points per tone (negative when freezing falls). *Repeated measures*: several measurements on the same animal. *Repeated-measures ANOVA*: an analysis of variance that separates differences between animals from changes within them. *Sphericity*: the assumption of repeated-measures ANOVA that the differences between every pair of tones have the same variance; the assumption fails when nearby tones are more alike than distant ones. *Interaction (genotype × tone)*: the genotype difference changes across tones, as it does when one genotype extinguishes faster. *Greenhouse–Geisser correction*: shrinks the degrees of freedom when sphericity fails; its *epsilon* is 1 when sphericity holds. *Degrees of freedom (df)*: the numbers in F(19, 342), which set how the test is read. *Log-odds*: log(p ÷ (1 − p)) for a proportion p, a scale on which values cannot run past 0% or 100%. *Covariate*: a measured value added to a model to adjust the comparison. *Mixed model*: a regression with random effects for each animal (a random intercept for its level, a random slope for its rate). *Welch t-test*: a two-group t-test that does not assume equal spread. *95% confidence interval (CI)*: the range of values compatible with the data. *Power*: the chance of detecting an effect that is really there. *False positive*: a "significant" result when there is no real effect.

## Which analysis for your question

| Question | Analysis | Report |
| --- | --- | --- |
| Do groups differ in freezing during a test (context or cued recall)? | Mean freezing per mouse over the test period (or the tones), Welch t-test or ANOVA across mice | Difference in percentage points with 95% CI, n mice |
| Do groups extinguish at different rates? | Slope of freezing against tone per mouse, Welch t-test; or repeated-measures ANOVA genotype × tone with Greenhouse–Geisser; or a mixed model with a random intercept and slope per mouse | Difference in slopes with 95% CI, or the corrected interaction test |
| Is extinction retained the next day? | Mean freezing per mouse in the retention test, compared between groups; report end-of-extinction freezing alongside (adjusting for it changes the question, because genotype may affect it) | Difference with 95% CI |
| Do groups differ before conditioning? | Baseline (pre-tone) freezing and activity, plus the response to shock, per mouse | Group means with spread |
| Does the readout capture fear in both sexes? | Score other conditioned responses (such as darting in rats) alongside freezing | Both measures per animal |

Choose one primary outcome per question in advance; the other rows answer different questions and are reported as secondary. A straight-line slope in percentage points works while freezing stays clear of 0% and 100%. When many mice reach 0% by the last tones, the line flattens at the floor; compare freezing in the last block of tones, or fit the slope on the log-odds scale (for example a binomial model of seconds freezing out of seconds scored).

Freezing "is measured as percent time freezing for a given test period, which can be measured continuously with a stopwatch, or by instantaneous time sampling every 3–10 s"; for automated scoring, "computer-derived freezing scores were systematically compared to hand scored freezing", and the authors "encourage similar validation of other automated systems"; "baseline activity, prior to any tone or shock on the training day, can be a useful measure of general activity effects" ([Anagnostaras et al. 2010](https://doi.org/10.3389/fnbeh.2010.00158)). Shoji and colleagues calculated freezing "every 60 sec in each test", compared groups "using two-way repeated measures ANOVA", and advised that each parameter of the automated program "should be calibrated using the data scored through human observations in each testing environment" ([Shoji et al. 2014](https://doi.org/10.3791/50871)). In rats, Gruene and colleagues identified "a novel, active fear response ('darting') that occurs primarily in female rats", in which "over 40% of females qualified as Darters" against about 10% of males, and found that "Darters froze less than Non-darters" ([Gruene et al. 2015](https://doi.org/10.7554/eLife.11352)).

## Worked example: a knockout with no real effect

Constructed data: an extinction session of 20 tones, freezing scored in each of the 30 seconds of every tone, in **10 wild-type and 10 knockout mice** (400 tone scores). Freezing starts near 70% and declines across the tones. Mice differ in their overall level of freezing and, a little, in how fast they extinguish, and each tone's score scatters around the mouse's curve. By design, **the knockout changes neither freezing nor extinction**. The data's random seed was the first one tried and was not chosen for its result. Stored code and data: [freezing.csv](/guides/fear-conditioning-freezing/freezing.csv), [model.py](/guides/fear-conditioning-freezing/model.py), [make_data.py](/guides/fear-conditioning-freezing/make_data.py), [analysis.py](/guides/fear-conditioning-freezing/analysis.py), [analysis.R](/guides/fear-conditioning-freezing/analysis.R) and [the analysis output](/guides/fear-conditioning-freezing/analysis_output.txt); analysis.py and analysis.R print the same output, including the repeated-measures ANOVA.

Freezing fell from 66.0% at tone 1 to 19.7% at tone 20 in wild-type mice, and from 64.3% to 18.3% in knockouts.

| Analysis, knockout vs wild-type | Result |
| --- | --- |
| A. A t-test at each of the 20 tones | none with p < 0.05; smallest p = 0.3 |
| B. All tones pooled, tones as n (200 vs 200), t-test | −2.0 points, p = 0.43 |
| **C. Mean freezing per mouse (10 vs 10), Welch t-test** | **−2.0 points (95% CI −19.9 to 15.9), p = 0.82** |
| **D. Extinction slope per mouse, Welch t-test** | **wild-type −2.40, knockout −2.28 points per tone; difference (knockout − wild-type; positive = slower decline) 0.12 (95% CI −0.81 to 1.05), p = 0.79** |
| E. Repeated-measures ANOVA, genotype × tone | F(19, 342) = 0.80, p = 0.71; Greenhouse–Geisser epsilon 0.36, corrected p = 0.59 |

With this data set even the shortcuts (A and B) came out non-significant; the simulation below shows how often they do not. The width of the interval in C (about ±18 percentage points) shows how much mice differ from each other, and why 200 tone scores per group are not 200 independent observations. The epsilon of 0.36 shows that sphericity fails: tones close together are more alike than tones far apart. (When F is below 1, as here, the correction can make p smaller; it matters when F is large.) Across 5,000 simulated studies of this design ([simulation.py](/guides/fear-conditioning-freezing/simulation.py), [the simulation output](/guides/fear-conditioning-freezing/simulation_output.txt)):

| Scenario | A. Any of 20 per-tone t-tests (invalid) | B. Tones as n (invalid) | C. Mean per mouse | D. Slope per mouse | E. Repeated-measures ANOVA, genotype × tone | E with Greenhouse–Geisser |
| --- | --- | --- | --- | --- | --- | --- |
| No effect (false positives) | **36.0%** | **51.9%** | 4.9% | 5.2% | 7.1% | 1.9% |
| Knockout extinguishes more slowly (power) | 76.8% | 80.0% | 26.6% | **70.2%** | 67.5% | 50.0% |

These percentages describe this simulated design (10 mice per group, 20 tones, the mouse-to-mouse variation in model.py), not every fear-conditioning study; with 5 tones, for example, per-tone testing gives fewer chances for a false positive. Testing every tone separately gives 20 chances to find a "significant" tone, and pooling tones counts each mouse 20 times; both find differences that are not there, so their high "power" means nothing. The uncorrected repeated-measures ANOVA is also slightly too liberal (7.1%) because sphericity fails; the Greenhouse–Geisser correction fixes that but is conservative here (1.9%) and detected slower extinction in 50.0% of studies instead of 67.5%. For a difference in extinction rate, the slope per mouse kept false positives near 5% and had the most power among the valid analyses simulated here (70.2%; a mixed model was not simulated); the mean per mouse answers a different question (overall freezing) and rarely detects a change in rate. In the second scenario both genotypes start at the same level, and the knockout's decline per tone is half the wild-type's on the log-odds scale.

A mixed model is an alternative to E, with two conditions: give each mouse a random slope as well as a random intercept (a random intercept alone assumes all tones are equally correlated, which this design breaks), and use small-sample degrees of freedom such as Satterthwaite's (for example lme4 with lmerTest in R). With 20 mice, tests that use the normal distribution, as statsmodels' MixedLM does, give p-values that are too small ([repeated-measures ANOVA vs mixed model](/guides/repeated-measures-anova-vs-mixed-model/)).

The code expects one row per mouse and tone with columns genotype (wild-type or knockout), mouse, tone, seconds_freezing and seconds_scored. Mouse IDs must be unique across genotypes (W1 and K1, not 1 and 1), and data exported per second or per bin must first be summed to one row per tone; if you score by instantaneous sampling, use samples freezing and samples scored in the two columns. Rename your columns and labels to match, and run the code in the folder that holds the CSV file. Python needs NumPy, pandas 2.2 or later and SciPy; the R code uses base R only. The repeated-measures ANOVA with the Greenhouse–Geisser correction is in analysis.py and analysis.R.

```python
import numpy as np, pandas as pd
from scipy import stats

d = pd.read_csv("freezing.csv"); d["pct"] = 100 * d.seconds_freezing / d.seconds_scored
m = d.groupby(["genotype", "mouse"]).apply(lambda x: pd.Series({"mean": x.pct.mean(),
        "slope": np.polyfit(x.tone, x.pct, 1)[0]}), include_groups=False).reset_index()
for v in ("mean", "slope"):                                     # one value per mouse, Welch t-test
    ko, wt = m[v][m.genotype == "knockout"], m[v][m.genotype == "wild-type"]
    t = stats.ttest_ind(ko, wt, equal_var=False); ci = t.confidence_interval()
    print(f"{v}: knockout - wild-type {ko.mean() - wt.mean():.2f} (95% CI {ci.low:.2f} to {ci.high:.2f}), p = {t.pvalue:.2g}")
# mean: -2.00 (-19.93 to 15.93), p = 0.82; slope: 0.12 (-0.81 to 1.05), p = 0.79
```

```r
d <- read.csv("freezing.csv"); d$pct <- 100 * d$seconds_freezing / d$seconds_scored
m <- do.call(rbind, lapply(split(d, list(d$genotype, d$mouse), drop = TRUE), function(x) data.frame(genotype = x$genotype[1],
       mean = mean(x$pct), slope = coef(lm(pct ~ tone, data = x))[[2]])))   # one row per mouse
t.test(mean ~ genotype, data = m)     # Welch; knockout - wild-type: -2.0 points, p = 0.82
t.test(slope ~ genotype, data = m)    # p = 0.79
```

## Before you analyse

1. **Decide the question and its one-per-mouse summary before the experiment**: mean freezing for a recall test, the extinction slope (or freezing in the last block) for extinction.
2. **Validate automated scoring against hand scoring in your own setup**, and keep the same thresholds for every animal.
3. **Record baseline freezing, activity and the response to shock** for every mouse, so a difference in freezing can be separated from a difference in movement or pain sensitivity.
4. **If you use repeated-measures ANOVA, report the Greenhouse–Geisser epsilon and corrected p**; if you use a mixed model, include a random slope per mouse and small-sample degrees of freedom.
5. **Plan the number of mice for the question**: in our simulation, 10 per group detected a halved extinction rate 70.2% of the time with the slope test, so 80% power needs more mice.
6. **In rats, especially females, score darting as well as freezing**, so that an active fear response is not read as less fear.

## Check what an AI assistant ran

1. **The assistant ran a t-test at every tone and marked the significant ones.** Ask for one test of the planned summary, or the genotype × tone test.
2. **The assistant used every tone as a data point.** Ask for one value per mouse.
3. **The assistant reported a repeated-measures ANOVA without a sphericity correction.** Ask for the Greenhouse–Geisser epsilon and corrected p; in our simulation the correction was conservative (1.9% false positives) and cost power, so the slope per mouse is a good companion.
4. **The assistant compared overall freezing when the question was extinction.** Ask for the slope per mouse or the interaction.

## Report it

> Freezing was scored [automatically; validated against hand scoring of n sessions, r = 0.97] in each of [20] tones of [30] s during extinction, from [10] wild-type and [10] knockout mice. For each mouse, mean freezing over the tones and the slope of freezing against tone were calculated, and genotypes were compared with Welch t-tests (R [4.3.3]).

> [Example values from constructed data with no effect built in:] knockout and wild-type mice did not clearly differ in freezing (difference [−2.0] percentage points, 95% CI [−19.9] to [15.9]; p = [0.82]) or in extinction rate (difference in slope, knockout − wild-type, [0.12] points per tone, 95% CI [−0.81] to [1.05]; p = [0.79]; n = [10] mice per genotype); the intervals are compatible with differences of up to about [18] percentage points in freezing either way.

Replace the bracketed values with your own; the values shown come from the constructed example, in which the knockout has no effect by design.

## References

- Anagnostaras SG, Wood SC, Shuman T, et al. (2010). Automated assessment of Pavlovian conditioned freezing and shock reactivity in mice using the Video Freeze system. *Frontiers in Behavioral Neuroscience* 4:158. [doi:10.3389/fnbeh.2010.00158](https://doi.org/10.3389/fnbeh.2010.00158)
- Shoji H, Takao K, Hattori S, Miyakawa T (2014). Contextual and cued fear conditioning test using a video analyzing system in mice. *Journal of Visualized Experiments* (85):e50871. [doi:10.3791/50871](https://doi.org/10.3791/50871)
- Gruene TM, Flick K, Stefano A, Shea SD, Shansky RM (2015). Sexually divergent expression of active and passive conditioned fear responses in rats. *eLife* 4:e11352. [doi:10.7554/eLife.11352](https://doi.org/10.7554/eLife.11352)

## Related

- [Repeated measures ANOVA vs mixed model](https://www.licklider.ai/guides/repeated-measures-anova-vs-mixed-model/)
- [Two-way ANOVA vs separate t-tests](https://www.licklider.ai/guides/two-way-anova-vs-multiple-t-tests/)
- [What counts as n?](https://www.licklider.ai/guides/what-counts-as-n/)
- [Comparing percentages between groups](https://www.licklider.ai/guides/comparing-percentages-between-groups/)

## How this page was made

- Written and published by Licklider. Recommendations cite peer-reviewed methods papers listed under References; cited passages were checked against the source text.
- The worked example uses constructed data. Its numbers were produced by stored code (Python 3.13 with SciPy 1.18.1 and pandas 2.2 or later; R 4.3.3, base R), and the two languages print identical output; the simulation was run in Python.
- Separate review passes checked the statistics, the citations and readability before publication.
