科研 Skill
单被试实验设计分析
single-case-experimental-design
Analyzes single-case ABAB, multiple-baseline, and alternating-treatment designs with visual analysis, Tau-U, PND, and randomization tests. Use for studies with few participants observed across phases.
SKILL.md
Single-Case Experimental Design (SCED) Analysis
Purpose
Single-case (N-of-1) designs — ABAB/withdrawal, multiple baseline across participants/behaviors/settings, alternating treatments, and changing criterion designs — are standard in clinical, school, and applied behavior analysis psychology, but they are not group-comparison studies: there is no "sample size," no t-test, and ordinary ANOVA/regression machinery does not apply directly to a handful of repeated-measures time series per participant. This skill covers the field's actual analytic toolkit: structured visual analysis, non-overlap indices, and randomization tests, plus when a multilevel model is (and is not) an appropriate addition.
When to Use
- A study has 1–8 participants, each observed repeatedly (many time points) across two or more phases (e.g., baseline "A", intervention "B").
- The question is whether a behavior changed level, trend, or variability when a phase changed (e.g., did on-task behavior increase after an intervention started).
- Multiple-baseline logic: an intervention is introduced to different participants/behaviors/settings at staggered times, and replication of the effect across those staggered introductions is the evidence for causality.
- You need publication-standard effect sizes for single-case data (Tau-U, PND, PEM, NAP) for a dissertation, case report, or meta-analysis of SCED studies.
Does NOT trigger
- A between-groups RCT or quasi-experiment with many independent participants per condition — use ordinary power analysis / ANOVA / regression skills instead; this skill's indices are specifically for the few-participants-many-observations structure.
- Experience-sampling / diary data with many participants each contributing
repeated observations, analyzed with mixed models — see
multilevel-modeling; SCED analysis is for when there are too few participants (often one) to support a multilevel model's between-person variance estimate at all.
Core Workflow
Step 1 — Visual analysis (always do this first, never skip to statistics)
The field's primary analytic method is structured visual inspection of the graphed data, following the What Works Clearinghouse (WWC) Single-Case Design Standards (2022) criteria:
- Level: mean (or median) of the data within each phase.
- Trend: slope of the best-fit line within each phase (e.g., via
scipy.stats.theilslopesfor a robust, outlier-resistant slope, or ordinary least squares for stable data). - Variability: range or SD of data within each phase.
- Immediacy of effect: how quickly the last 3 data points of one phase differ from the first 3 of the next.
- Overlap: proportion of data points in the new phase that overlap the range of the previous phase (less overlap = stronger effect).
- Consistency of patterns across similar phases (e.g., both "A" phases in an ABAB design should look similar if the intervention is truly responsible for the "B" phase change).
import numpy as np
import pandas as pd
from scipy.stats import theilslopes
def phase_summary(df: pd.DataFrame, time_col: str, value_col: str, phase_col: str) -> pd.DataFrame:
"""One row per phase: n, mean, median, SD, range, and robust trend slope."""
rows = []
for phase, g in df.groupby(phase_col, sort=False):
g = g.sort_values(time_col)
slope, intercept, lo, hi = theilslopes(g[value_col], g[time_col])
rows.append({
"phase": phase, "n": len(g),
"mean": round(g[value_col].mean(), 3),
"median": round(g[value_col].median(), 3),
"sd": round(g[value_col].std(ddof=1), 3),
"range": (round(g[value_col].min(), 3), round(g[value_col].max(), 3)),
"trend_slope": round(slope, 4),
})
return pd.DataFrame(rows)
Step 2 — Non-overlap effect sizes
def tau_u(baseline: np.ndarray, treatment: np.ndarray, correct_for_baseline_trend: bool = True) -> dict:
"""
Tau-U (Parker, Vannest, Davis, 2011): a Mann-Kendall-based non-overlap
index that can optionally correct for an undesirable trend already
present in baseline. Tau-U ranges roughly -1 to 1; values near 1 mean
treatment phase scores are consistently higher than baseline (for an
increasing-is-better outcome).
"""
def mann_whitney_s(a, b):
# S = (# pairs where b_j > a_i) - (# pairs where b_j < a_i), all (i,j) pairs
diffs = b.reshape(-1, 1) - a.reshape(1, -1)
return np.sign(diffs).sum()
s_ab = mann_whitney_s(baseline, treatment)
n_a, n_b = len(baseline), len(treatment)
tau_ab = s_ab / (n_a * n_b)
if correct_for_baseline_trend and n_a > 2:
s_aa = mann_whitney_s(baseline, baseline) # trend within baseline
n_pairs_a = n_a * (n_a - 1)
tau_a_trend = s_aa / n_pairs_a if n_pairs_a > 0 else 0.0
s_corrected = s_ab - s_aa
denom = n_a * n_b + n_pairs_a
tau_u_value = s_corrected / denom if denom > 0 else np.nan
else:
tau_u_value = tau_ab
return {"tau_u": round(float(tau_u_value), 4), "n_baseline": n_a, "n_treatment": n_b}
def pnd(baseline: np.ndarray, treatment: np.ndarray, higher_is_better: bool = True) -> float:
"""Percentage of Non-overlapping Data (Scruggs, Mastropieri & Casto, 1987)."""
threshold = baseline.max() if higher_is_better else baseline.min()
if higher_is_better:
n_exceeding = (treatment > threshold).sum()
else:
n_exceeding = (treatment < threshold).sum()
return round(100 * n_exceeding / len(treatment), 1)
PND is widely used but has known weaknesses (a single extreme baseline point collapses it to near 0%, and it ignores all but one baseline point) — report Tau-U or NAP (nonoverlap of all pairs) as the primary index and PND only as a supplementary, historically comparable number.
Step 3 — Randomization test for phase-change significance
When the order or timing of phase changes was randomized at the design stage (e.g., randomized multiple baseline, randomized ABAB switch points), a randomization test gives a design-based p-value without distributional assumptions:
def randomization_test(df: pd.DataFrame, value_col: str, phase_col: str,
possible_start_points: list, observed_start: int,
statistic=lambda a, b: b.mean() - a.mean(),
n_permutations: int = 2000, seed: int = 0) -> dict:
"""
Re-assigns the intervention start point among the possible randomized
start points (as actually specified at the design stage — do not invent
start points that were never eligible under the original randomization
scheme) and compares the observed test statistic to its permutation
distribution.
"""
rng = np.random.default_rng(seed)
values = df[value_col].to_numpy()
observed_stat = statistic(values[:observed_start], values[observed_start:])
perm_stats = []
for _ in range(n_permutations):
sp = rng.choice(possible_start_points)
perm_stats.append(statistic(values[:sp], values[sp:]))
perm_stats = np.array(perm_stats)
p_value = (np.sum(np.abs(perm_stats) >= abs(observed_stat)) + 1) / (n_permutations + 1)
return {"observed_stat": round(float(observed_stat), 4), "p_value": round(float(p_value), 4)}
Step 4 — When (and when not) to add a multilevel/regression model
With enough phases and data points per participant (rule of thumb: 20+ total observations with multiple phase transitions), a piecewise regression (interrupted time-series) or multilevel model with phase, time, and phase×time terms can supplement — never replace — visual analysis:
import statsmodels.formula.api as smf
df["time_centered"] = df.groupby("phase_dummy_ref")["time"].transform(lambda t: t - t.iloc[0])
model = smf.ols("value ~ phase + time_centered + phase:time_centered", data=df).fit(
cov_type="HAC", cov_kwds={"maxlags": 1} # autocorrelation-robust SEs
)
print(model.summary())
Reaction-time-style independence assumptions do not hold here: single-case time series are typically serially autocorrelated, so plain OLS standard errors are anti-conservative. Use HAC/Newey-West standard errors or an explicit autoregressive error structure, and say so when reporting p-values.
Prerequisites
- Phase-labeled, time-ordered data for each participant (one row per observation, columns for time, outcome, phase label, participant ID).
- Python with
numpy,pandas,scipy,statsmodels. - Knowledge of which start points were actually eligible under the original randomization scheme (for Step 3) — this is a design fact, not something to infer from the data after the fact.
- For multiple-baseline designs, the staggered intervention start times for each tier (participant/behavior/setting), since replication across these staggered starts is central to the causal argument.
Limitations
- All indices here (Tau-U, PND, NAP) summarize non-overlap, not effect magnitude in the ordinary-least-squares sense; they are not directly comparable to Cohen's d from a group design, and converting between them is not a settled, lossless procedure — do not report a Tau-U-derived "equivalent Cohen's d" without flagging the conversion as approximate.
- With very few data points per phase (under ~5), both overlap indices and randomization tests have limited power and should be interpreted alongside visual analysis, not instead of it.
- Serial autocorrelation in single-case time series inflates Type I error for naive significance tests; always check/model it (Step 4) rather than running a plain two-sample test on raw phase scores.
- This skill does not cover power analysis for planning a new SCED study —
pair with the
power-analysisskill's simulation-based approach if a required number of data points/phases needs to be justified in advance.
Quality Checks
- Never report a single statistic as "the" result; pair visual analysis (level/trend/variability/overlap) with at least one quantitative index.
- Confirm the direction convention (higher-is-better vs lower-is-better) is
correctly set in
pnd()/tau_u()calls — a flipped sign silently reports the intervention as harmful when it helped, or vice versa. - For multiple-baseline designs, confirm the effect "replicates" at each staggered introduction point before claiming a causal effect from a single tier's data.
- State which WWC design standard tier (meets standards / meets with reservations / does not meet standards) the design satisfies, based on the number of phases, data points per phase, and whether staggered introduction was used, when the context is a systematic review or evidence rating.
References
- Kratochwill, T. R., et al. (2010/2022). Single-Case Design Technical Documentation. What Works Clearinghouse.
- Parker, R. I., Vannest, K. J., & Davis, J. L. (2011). Effect size in single-case research: A review of nine nonoverlap techniques. Behavior Modification, 35(4), 303–322.
- Scruggs, T. E., Mastropieri, M. A., & Casto, G. (1987). The quantitative synthesis of single-subject research. Remedial and Special Education.
- Edgington, E. S., & Onghena, P. (2007). Randomization Tests (4th ed.). Chapman & Hall/CRC.
- Shadish, W. R., Rindskopf, D. M., & Hedges, L. V. (2008). The state of the science in the meta-analysis of single-case experimental designs. Evidence-Based Communication Assessment and Intervention, 2(3), 188–196.
示例提示词
帮我对这份ABAB单被试干预数据做Tau-U和重叠指标分析。
所属插件
安装该插件会一并获得同领域的 13 个 Skill / MCP。
同插件的其他科研 Skill
- 结构方程与测量模型拟合Fits CFA, SEM, EFA, and IRT models with semopy and factor_analyzer, reporting fit indices, omega reliability, and invariance. Use for latent-variable, factor-loading, or invariance requests.
- 临床量表评分解读Scores PHQ-9, GAD-7, PCL-5, BDI-II, and SWLS, computing severity, prorated scores, and the Reliable Change Index. Use when batch-scoring clinical scales or testing pre-post change.
- 实验设计与顺序平衡Guides within- vs between-subjects design, Latin-square and ABBA counterbalancing, confound control, and preregistration before data collection. Use when planning an experiment’s design.
- 眼动数据分析Processes raw eye-tracking data: IVT fixation detection, AOI dwell time, scanpath similarity, heatmaps, pupillometry baseline correction. Use for gaze or pupil data from eye trackers.
- 评分者间信度分析Computes inter-rater/inter-coder reliability with Cohen’s/weighted/Fleiss’ kappa, Krippendorff’s alpha, ICC, and Gwet’s AC1. Use when raters coded the same cases and agreement must be reported.
- 心理学元分析Pools effect sizes across studies with Cohen’s d, Hedges’ g, random-effects pooling, forest/funnel plots, and publication-bias tests. Use when synthesizing results from multiple studies.
- 多层线性混合效应模型Fits multilevel/mixed-effects models with pymer4 and lme4: ICC, random slopes, likelihood-ratio comparison, within-person centering for ESM data. Use for nested or repeated-measures designs.
- 心理学研究功效分析Computes power, sample size, or minimum detectable effect for t-tests, ANOVA, correlation, regression, and simulation-based designs including mediation. Use when planning a study’s sample size.
- 心理测量学分析Runs CTT item stats, Cronbach’s alpha, EFA, CFA, 2PL IRT, measurement invariance, and Mantel-Haenszel DIF detection in Python. Use when validating a scale’s reliability, structure, or item fairness.
- PsychoPy行为实验设计Builds PsychoPy experiments: monitor calibration, stimulus presentation, response timing, BIDS events.tsv output, Pavlovia deployment checklist. Use when implementing a stimulus-response task.
- 反应时数据分析Cleans RT data and fits ex-Gaussian distributions, EZ-diffusion parameters, and Bayesian drift-diffusion models with PyMC. Use for RT outliers, distribution shape, or decision-model parameters.
- 问卷量表翻译审查Reviews OB, management, and psychology survey scales for translation equivalence and adaptation validity, producing a Chinese dashboard report. Use for pre-launch questionnaire quality checks.
常见问题
单被试实验设计分析能做什么?
Analyzes single-case ABAB, multiple-baseline, and alternating-treatment designs with visual analysis, Tau-U, PND, and randomization tests. Use for studies with few participants observed across phases。
如何安装单被试实验设计分析?
在科搭 Codar 左侧点击「插件」,在「组件」页签搜索「单被试实验设计分析」并安装;在 Claude Code 或 Codex 中可以发送本页的安装提示词,或下载 Skill 包后解压到 ~/.claude/skills 或 ~/.codex/skills。
单被试实验设计分析需要哪些权限?
该科研 Skill没有声明额外权限;执行具体操作时仍由 Agent 按自身规则请求确认。
单被试实验设计分析经过官方审核吗?
是。SpeedSkills 收录的每个版本都会记录内容摘要与权限声明,当前版本已通过安全审核。