IntoMindLearn

Research methods

This chapter is part of the book from college on.

Back to the contents

Chapter 11 · College

Research methods

How do you design a study that can answer its question: a hypothesis that could be wrong, enough data to detect what you expect, an analysis fixed before the data, and a report someone else could repeat?

Hypotheses, and designs

A hypothesis is a claim precise enough that a study could show it wrong. The design names what is varied, what is held constant and what is measured, and the analysis is fixed before the data arrives: the features, the model, the folds, the test against chance, and what result would count as support.

Within-person designs, eyes open against closed in the same person, remove the differences between people from the comparison. Alternating the conditions in rounds stops slow drifts, fatigue or settling contact, from lining up with one of them.

A design, fixed in advance Eight rounds, Off and On in turn, eleven readings kept in each, the first two after every switch dropped, and each round held out in turn to test on.

Power

Power is the chance a study detects an effect that is really there. Too little data makes a real effect easy to miss, and makes any effect you do find likely to be overstated, since only the estimates that came out large pass the test.

For permutation tests and decoding pipelines, the simplest way to estimate it is simulation: generate data with the effect you expect, run the planned analysis, and count how often it succeeds.

Power The chance of detecting a real effect against people per group, for the effect size on the slider. The dashed line is 80 percent, the usual target.

Try it

Power by simulation

Alpha Flower's design used three blocks with the eyes open and three closed, so its permutation p can't go below 0.05. Simulate how often designs with 3 to 6 blocks of each detect a true difference of half, one and two times the spread between blocks.

import numpy as np
from itertools import combinations

rng = np.random.default_rng(0)

def p_value(opened, closed):
    """One-sided permutation p: every way of calling k of the 2k blocks closed."""
    both = np.r_[opened, closed]
    n, k = len(both), len(closed)
    splits = np.array(list(combinations(range(n), k)))
    inside = np.zeros((len(splits), n), bool)
    inside[np.arange(len(splits))[:, None], splits] = True
    diffs = (inside @ both) / k - (~inside @ both) / (n - k)
    return np.mean(diffs >= closed.mean() - opened.mean())

for k in (3, 4, 5, 6):                       # blocks with the eyes open, and as many closed
    row = []
    for d in (0.5, 1.0, 2.0):                # the true difference, in units of the spread between blocks
        hits = sum(p_value(rng.normal(0, 1, k), rng.normal(d, 1, k)) <= 0.05 for _ in range(500))
        row.append(f"effect {d}: {hits / 500:.2f}")
    print(f"{k} blocks of each:", ", ".join(row))

You should seePower climbing with the effect and with the blocks: about 0.6 for a large effect with three blocks of each, and about 0.95 with six.

Preregistration, and reproducibility

Preregistration records the plan before the data: the hypothesis, the design, the sample, the analysis and what counts as support. It doesn't forbid looking further, but it separates what was tested from what was found while exploring, which are reported differently.

A reproducible result comes with its code, its settings and, where consent allows, its data. The demos show what that can look like: the same training data gives the same custom AI head, byte for byte, in the browser, in Python and in Rust.

Try it

Reproduce a result

From one wearer's saved training data, with their permission, reproduce the custom AI head in Python, and in Rust if you have it, and confirm each matches the head the browser saved. Then write the methods paragraph a stranger would need to do the same.

cd python
python3 teach_it.py --from training-data.json --out python.imh
cd ../rust
cargo run --release --bin teach_it -- --from ../python/training-data.json --out rust.imh
sha256sum ../python/python.imh rust.imh the-head-you-saved.imh

You should seeThe same checksum on all three files.

Problems

  1. Your study found nothing. When does that mean there is nothing to find?

  2. Why does an underpowered study that does find an effect tend to overstate it?

  3. From the simulation, how many blocks of each give about 50 percent power for an effect the size of the spread between blocks? What would you do with that?

  4. Write the sentence a methods section needs about how a light switch score was tested.

Sources

Button, K. S., and others (2013). Power failure: why small sample size undermines the reliability of neuroscience. Nature Reviews Neuroscience.

Nosek, B. A., Ebersole, C. R., DeHaven, A. C., and Mellor, D. T. (2018). The preregistration revolution. Proceedings of the National Academy of Sciences.

Pernet, C., and others (2020). Issues and recommendations from the OHBM COBIDAS MEEG committee for reproducible EEG and MEG research. Nature Neuroscience.

Chapter 11 · Graduate

Research methods

How do you design a study of your own that can fail, decide how much data it needs, and report it so that someone else can check every number?

The estimand

A study estimates something: its estimand. Say exactly what, in whom, and against what. "The mean within-person change in alpha's power above the background from eyes open to closed, in healthy adults like those recruited" is an estimand. "Whether alpha changes" isn't. The estimand fixes the unit of analysis. Here it is people, so people are the replicates, and their blocks and windows are measurements within them, however many there are.

Designs

Within-person designs compare conditions in the same person, which removes the large differences between people from the comparison. Order effects, fatigue and drift then become the threat: alternate the conditions, counterbalance their order across people, and block them so that slow changes fall evenly on both. If the order is randomized, a permutation test is justified by the randomization itself. The light switch's rounds always start with Off and alternate, which balances drift, but its test assumes the rounds could have been labeled any way.

Power, at two levels

A person's measured effect varies around the population's mean by the person's own deviation and by measurement noise, so its variance is τ² + σ²/b with b blocks. More blocks shrink the second term, never the first, and past a point only more people help. Power for a design is simplest to get by simulating the analysis you will run on data like those you expect. Underpowered studies don't only miss effects (Button and others, 2013). The effects they do report are exaggerated, since only overestimates cross the threshold (Gelman and Carlin, 2014).

Preregistration and registered reports

A preregistration records the hypotheses, the design and the analysis before the data exist, and separates confirmatory tests from exploration, which is still welcome when it is labeled (Nosek and others, 2018). A registered report goes further: the journal reviews the question and the methods before the data, and commits to publishing whatever they show (Chambers, 2013). Deviations happen, and the report names every one.

Reporting, and reproducing

The COBIDAS MEEG recommendations list what an EEG report owes its reader, from the amplifier and the reference to every analysis parameter (Pernet and others, 2020). EEG-BIDS organizes the files so another lab's code can read them (Pernet and others, 2019). Share the code with its environment pinned, and checksums for the data. The demos make some of this concrete: every recording is saved with checksums, and a custom AI head is rebuilt byte for byte from its training data by a second program. Whether influential EEG findings replicate at all is now being tested across many labs (Pavlov and others, 2021).

Analysis

Analysis

Power and exaggeration, people against blocks

Simulate a within-person study whose effect varies between people, with 8, 16 or 32 people and 4 or 16 blocks each, and test it as you would: each person's mean difference, then a one-sided t-test across people. Record power, and how much the significant estimates overstate the true effect.

import numpy as np
from scipy import stats

rng = np.random.default_rng(11)
EFFECT, SPREAD, NOISE = 0.3, 0.3, 1.0    # the mean effect, how much it varies between people,
                                         # and the noise in one block, all in the same units

def study(people, blocks):
    """Each person's own effect, measured as the mean of their blocks' differences."""
    own = rng.normal(EFFECT, SPREAD, people)
    return own + rng.normal(0, NOISE, (people, blocks)).mean(axis=1)

print("people  blocks  power  significant estimates, over the true effect")
for people in (8, 16, 32):
    for blocks in (4, 16):
        estimates = np.array([study(people, blocks) for _ in range(4000)])
        p = stats.ttest_1samp(estimates, 0, axis=1, alternative="greater").pvalue
        found = p < 0.05
        exaggeration = estimates.mean(axis=1)[found].mean() / EFFECT
        print(f"{people:6d} {blocks:7d} {found.mean():6.2f}  {exaggeration:.2f}")

You should seePower of 0.36 with 8 people and 4 blocks each, where significant estimates overstate the effect by 61 percent. Sixteen blocks for 8 people buy about as much as twice the people with 4 blocks, 0.63 against 0.64, and with 32 people power is 0.89 at 4 blocks.

Then report: the design your capstone can afford, its power for the effect you expect, and how much its significant result would be likely to exaggerate.

Open problems

  1. Preregistering machine learning. A decoding pipeline has many choices, folds, penalties, features and windows, and how to preregister them without freezing what should be learned from the data is unsettled.
  2. How much replicates. Large replication efforts in EEG are under way (Pavlov and others, 2021), and how many established effects hold is not yet known.
  3. Effects that differ between people. When an effect varies between people, the average may describe no one. How to estimate and report the spread, with the samples a lab can afford, is open.

Problems

  1. Write the estimand for "does closing the eyes raise alpha", for your class, precisely enough that two analysts would compute the same number.

  2. With a between-person spread of 0.3 and a block noise of 1, how many blocks make the noise term equal to the spread term? What does that say about adding more?

  3. Why do significant results from underpowered studies overstate their effects?

  4. The light switch always teaches Off, On, Off, On. What does that protect against, and what would randomizing the order add?

  5. Your analysis changed after you saw the data: you dropped a wearer with poor contact. How do you report it?

Sources

Button, K. S., and others (2013). Power failure: why small sample size undermines the reliability of neuroscience. Nature Reviews Neuroscience.

Chambers, C. D. (2013). Registered reports: a new publishing initiative at Cortex. Cortex.

Gelman, A., and Carlin, J. (2014). Beyond power calculations: assessing Type S (sign) and Type M (magnitude) errors. Perspectives on Psychological Science.

Nosek, B. A., Ebersole, C. R., DeHaven, A. C., and Mellor, D. T. (2018). The preregistration revolution. Proceedings of the National Academy of Sciences.

Pernet, C. R., and others (2019). EEG-BIDS, an extension to the brain imaging data structure for electroencephalography. Scientific Data.

Pernet, C., and others (2020). Issues and recommendations from the OHBM COBIDAS MEEG committee for reproducible EEG and MEG research. Nature Neuroscience.

Pavlov, Y. G., and others (2021). #EEGManyLabs: investigating the replicability of influential EEG experiments. Cortex.

Part 3 · Real-world outcomes · Chapter 11

Research methods

This topic is part of the college and graduate courses.