svgparallel-analysis
Parallel analysis
How many factors stand out above what random data would produce?
How to read it
- Read the solid line as your data's eigenvalues.
- Read the dashed line as those of random data of the same size.
- Keep factors where the solid line stays above the dashed one.
- Callout 1: The first factor stands far above random.
- Callout 2: The last factor above random.
- Callout 3: Below random: noise.
Watch out
- It's a guide: factor interpretation still decides what to keep.
Defaults
No settings: the chart draws one way.
Pinned in the code
- Draws the run's numbers as given (computed by the Python/R engine); the chart computes nothing statistical.
- Retained = the leading run of factors whose observed eigenvalue exceeds the simulated one (the 95th percentile or the mean of the simulations, as the engine sends). The Kaiser line is shown for reference only — it over-extracts.
# Parallel analysis — Codesplash Chart Lab (recipe "parallel-analysis")
# controls: defaults
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
try:
import codesplash as cs # optional: the app's chart theme
except ImportError:
cs = None
if cs:
cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]
df = pd.read_csv("parallel-analysis-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["kind"] = pd.Categorical(df["kind"].astype("string"), categories=["observed", "simulated (95th percentile)"])
F = "factor"
E = "eigenvalue"
K = "kind"
fig, ax = plt.subplots(figsize=(8, 4.5))
for name, d in df.dropna(subset=[F, E]).sort_values(F).groupby(K, observed=True, sort=False):
sim = any(w in str(name).lower() for w in ("sim", "random", "parallel"))
ax.plot(d[F], d[E], marker="o", ms=4, color="grey" if sim else PALETTE[0], linestyle="--" if sim else "-", linewidth=1.6 if sim else 2, label=str(name))
ax.axhline(1, color="grey", linestyle=":", linewidth=1)
ax.set_xlabel(F)
ax.set_ylabel(E)
ax.legend(fontsize=8)
plt.show()Needs pandas, numpy, matplotlib · reads parallel-analysis-demo.csv · app theme from the optional codesplash helper
# Parallel analysis — Codesplash Chart Lab (recipe "parallel-analysis")
# controls: defaults
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
try:
import codesplash as cs # optional: the app's chart theme
except ImportError:
cs = None
if cs:
cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else px.colors.qualitative.Plotly
df = pd.read_csv("parallel-analysis-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["kind"] = pd.Categorical(df["kind"].astype("string"), categories=["observed", "simulated (95th percentile)"])
F = "factor"
E = "eigenvalue"
K = "kind"
fig = px.line(df.dropna(subset=[F, E]).sort_values(F), x=F, y=E, color=K, markers=True, color_discrete_sequence=[PALETTE[0], "grey"])
fig.add_hline(y=1, line=dict(color="grey", dash="dot", width=1))
fig.update_layout(legend_title=None)
fig.show()Needs pandas, numpy, plotly · reads parallel-analysis-demo.csv · app theme from the optional codesplash helper
# Parallel analysis — Codesplash Chart Lab (recipe "parallel-analysis")
# controls: defaults
library(ggplot2)
has_cs <- isTRUE(requireNamespace("codesplashr", quietly = TRUE)) # optional: the app's chart theme
theme_cs <- if (has_cs) codesplashr::theme_codesplash(dark = FALSE) else theme_minimal()
cs_cat <- if (has_cs) codesplashr::cs_palette(dark = FALSE)$categorical else grDevices::palette.colors(8, "Okabe-Ito")
if (has_cs) update_geom_defaults("text", list(colour = codesplashr::cs_palette(dark = FALSE)$foreground))
df <- read.csv("parallel-analysis-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["kind"]] <- factor(df[["kind"]], levels = c("observed", "simulated (95th percentile)"))
f_col <- "factor"
e_col <- "eigenvalue"
k_col <- "kind"
d <- data.frame(f = df[[f_col]], e = df[[e_col]], k = factor(as.character(df[[k_col]]), levels = unique(as.character(df[[k_col]]))))
p <- ggplot(d, aes(f, e, colour = k, linetype = k)) + geom_hline(yintercept = 1, colour = "grey60", linetype = "dotted") +
geom_line(linewidth = 0.9) + geom_point(size = 1.8) + scale_colour_manual(values = c(cs_cat[1], "grey50")) +
scale_x_continuous(breaks = function(l) seq(1, floor(l[2]))) + labs(x = f_col, y = e_col, colour = NULL, linetype = NULL) + theme_cs
print(p)Needs ggplot2 · reads parallel-analysis-demo.csv · app theme from the optional codesplashr helper