Guides dimensionality reduction and latent-variable analysis of neural populations (PCA, GPFA, dPCA)
This skill encodes expert methodological knowledge for dimensionality reduction and latent-variable analysis of neural population recordings. A competent programmer without computational neuroscience training will get this wrong because:
Do NOT use this skill for:
neural-decoding-analysis skill instead)Before executing the domain-specific steps below, you MUST:
For detailed methodology guidance, see the research-literacy skill.
This skill was generated by AI from academic literature. All parameters, thresholds, and citations require independent verification before use in research. If you find errors, please open an issue.
Single-neuron analysis characterizes individual tuning curves and response properties. Population analysis characterizes the collective, low-dimensional structure of neural activity. Use population analysis when (Cunningham & Yu, 2014):
Domain judgment: Population analysis does NOT require that individual neurons be untuned. Even populations of well-tuned neurons have emergent low-dimensional structure that single-neuron analyses miss. The question is whether the research question is about individual neuron properties or collective population geometry (Cunningham & Yu, 2014).
What is your research question?
|
+-- "What are the dominant patterns of co-variation across the population?"
| --> PCA (linear, static)
| Simplest method; start here
| Output: principal components, variance explained, projections
|
+-- "What are the smooth latent trajectories on single trials?"
| --> GPFA (Yu et al., 2009) or Factor Analysis
| For temporal structure; extracts trial-by-trial dynamics
| Output: latent trajectories per trial, dimensionality estimate
|
+-- "How is variance distributed across task parameters?"
| --> dPCA (Kobak et al., 2016)
| Demixes stimulus, decision, time, and interaction variance
| Output: demixed components, marginalization pie chart
|
+-- "Are there rotational dynamics in the population?"
| --> jPCA (Churchland et al., 2012)
| Finds rotational structure in neural trajectories
| Output: rotational plane projections, R^2 of rotational fit
|
+-- "I want to visualize population structure in 2-3D"
--> t-SNE or UMAP -- VISUALIZATION ONLY
NOT for quantitative analysis or distance comparisons
Output: 2D/3D embedding (qualitative only)
Trial averaging vs. single-trial: Trial-averaged PCA smooths out single-trial variability and is appropriate when the question is about condition-mean trajectories. Single-trial PCA preserves trial-to-trial variability but requires more data (Cunningham & Yu, 2014).
Soft normalization (CRITICAL): Do NOT use standard z-scoring (subtract mean, divide by SD). This eliminates firing rate differences that carry information. Instead, use soft normalization (Churchland et al., 2012):
normalized_rate = (rate - mean) / (range + constant)
where constant is typically 5 spikes/s (Churchland et al., 2012). This prevents low-firing neurons from dominating due to noise amplification while preserving rate differences.
Square-root transform: An alternative normalization for Poisson-like spike counts: sqrt(mean firing rate + constant) (Churchland et al., 2012). Stabilizes variance across neurons with different firing rates.
Mean subtraction: Subtract the condition-averaged PSTH across all conditions from each condition. This removes the shared temporal modulation and focuses PCA on condition-discriminating variance (Kobak et al., 2016).
| Method | Description | When to Use | Source |
|---|---|---|---|
| Parallel analysis | Compare eigenvalues to those from shuffled data | Recommended default; principled threshold | Humphries, 2021 |
| Cross-validated PCA | Hold out neurons or time bins; test reconstruction | Avoids overfitting; gold standard | Cunningham & Yu, 2014 |
| Scree plot elbow | Subjective visual inspection | Quick but unreliable; avoid for publication | Expert consensus |
| Percent variance threshold | e.g., "keep PCs explaining 90%" | NOT recommended; arbitrary threshold | Humphries, 2021 |
Domain judgment: There is no fixed variance-explained threshold for choosing the number of PCs. The "90% rule" from data science is meaningless for neural data because it confounds signal dimensionality with noise. Use parallel analysis (compare eigenvalues to those expected from random data with matched statistics) or cross-validation (Humphries, 2021).
To avoid overfitting dimensionality estimates:
This is especially critical with small neuron counts (<50 neurons) where noise dimensions can mimic signal dimensions (Cunningham & Yu, 2014).
GPFA extracts smooth, low-dimensional latent trajectories from single-trial spike trains by combining factor analysis with Gaussian process temporal smoothing (Yu et al., 2009).
| Parameter | Recommended Value | Rationale | Source |
|---|---|---|---|
| Bin size | 20--50 ms | Smaller bins preserve temporal resolution but increase noise; 20 ms is standard for motor cortex | Yu et al., 2009 |
| Latent dimensions | Cross-validate | Fit models with 2--15 dimensions; select by leave-one-neuron-out cross-validation log-likelihood | Yu et al., 2009 |
| GP timescale (tau) | Learned from data | Each latent dimension has its own timescale; inspect for biologically plausible values (10--500 ms) | Yu et al., 2009 |
Domain judgment: GPFA is NOT simply "smoothed PCA." Factor analysis and PCA make different assumptions about noise structure. PCA treats all variance as signal; factor analysis separates shared (signal) variance from private (noise) variance per neuron. GPFA adds temporal smoothness to the shared component. This distinction matters when neurons have heterogeneous noise levels (Yu et al., 2009).
dPCA finds linear projections that capture maximum variance attributable to specific task parameters (e.g., stimulus identity, decision, time, and their interactions), rather than maximum total variance like PCA (Kobak et al., 2016).
Marginalization: Partition the data tensor by task parameter (e.g., average over all decisions to isolate stimulus variance). dPCA finds components that maximize variance within each marginalization (Kobak et al., 2016).
Regularization: The regularization parameter lambda controls the tradeoff between demixing (fidelity to marginalization) and reconstruction (total variance captured). Select lambda by cross-validation (Kobak et al., 2016):
| Classifier | When to Use | Source |
|---|---|---|
| Linear SVM | Default; robust for high-dimensional population data | Cunningham & Yu, 2014 |
| LDA | When number of neurons << number of trials | Cunningham & Yu, 2014 |
| Logistic Regression | When probability estimates are needed | Cunningham & Yu, 2014 |
| Strategy | When to Use | Source |
|---|---|---|
| Leave-one-trial-out | Small trial counts; maximizes training data | Cunningham & Yu, 2014 |
| Stratified k-fold (k=5--10) | Sufficient trials; balances bias/variance | Cunningham & Yu, 2014 |
Train a classifier at time t, test at all times t'. The resulting matrix reveals dynamics of neural coding (King & Dehaene, 2014):
See the neural-decoding-analysis skill for detailed guidance on temporal generalization.
Standard z-scoring (subtract mean, divide by SD) amplifies noise from low-firing neurons and eliminates informative rate differences. Always use soft normalization or square-root transform for neural population data (Churchland et al., 2012).
t-SNE and UMAP distort distances, create spurious clusters, and are sensitive to hyperparameters (perplexity, n_neighbors). They are useful for visualization but must NEVER be used for quantitative claims about distance, clustering, or dimensionality (Cunningham & Yu, 2014).
There is no universal threshold. The correct approach is parallel analysis (compare to null eigenvalue distribution) or cross-validated reconstruction (Humphries, 2021).
GPFA is designed for single-trial data. Applying it to trial-averaged PSTHs defeats its purpose (separating shared latent signal from private noise) and provides no advantage over PCA (Yu et al., 2009).
Population analyses have minimum neuron requirements for reliable estimates. Below ~30 simultaneously recorded neurons, dimensionality estimates from PCA are dominated by noise; GPFA latent trajectories become unstable below ~50 neurons (Cunningham & Yu, 2014; Yu et al., 2009).
Using default or arbitrary regularization parameters in dPCA can either over-demix (fitting noise) or under-demix (missing true task-related structure). Always cross-validate lambda (Kobak et al., 2016).
Based on Cunningham & Yu (2014), Kobak et al. (2016), and Yu et al. (2009):
See references/method-comparison.md for detailed parameter tables and software recommendations.
See references/data-requirements.md for minimum neuron and trial count guidelines by method.