Latent mediation (bootstrap)
Does trust in institutions affect community participation through the sense of belonging? When each of the constructs is measured by several items, mediation is tested in a structural equation model – and the test of the indirect effect is done by bootstrap: thousands of samples drawn from the data, and a confidence interval from the resulting distribution, without assuming it is normal. The page estimates the model as lavaan does, decomposes each effect into direct, indirect by path, and total, and prints for each a delta-method standard error alongside bootstrap with percentile and bias-corrected intervals – exactly the same samples as in lavaan with the same seed.
Loading the data
Paste columns directly from the sheet (including the header row) – select them in Excel, copy, and paste here:
Model specification
When to use?
When the hypothesis is about a mechanism: one factor affects the outcome through a third factor. Kline (2023, p. 349) describes mediation analysis as the question of "how changes are transmitted from a causal factor through one or more mediating variables, which in turn lead to changes in the outcome". In the sample data file: trust in institutions → sense of belonging to the community → participation, alongside a direct path from trust to participation.
Why with latent factors and not with scale scores? Kline (2023, p. 350) cites simulations by Iacobucci et al. (2007, as cited in Kline) according to which mediation analyses with several indicators per variable, which control for measurement error, are "generally preferable" to analyses with a single indicator (ordinary regression). With scale scores – the page path analysis and mediation (which also has bootstrap), or moderation and mediation (PROCESS-style, including moderated mediation); for the full model without decomposing the mediation – structural equation model; for testing the measurement model alone – confirmatory factor analysis.
The logic: a product of paths
The indirect effect of X on Y through M is the product of the two coefficients – a (X ← M) times b (M ← Y), where b already controls for X; the total is ab + c′, with c′ the direct effect. Kline (2023, p. 125) interprets: ab is the expected change in Y when X is held constant and M changes to the value it would reach with a one-point change in X (Pearl, 2009, as cited in Kline). With several mediators – each path has its own product (parallel: X ← M1 ← Y and X ← M2 ← Y; in sequence: X ← M1 ← M2 ← Y), and the total indirect effect is the sum (Kline, pp. 351-352, Figure 20.2).
The standard error. For the path itself – an ordinary standard error. For the product there are two ways. The delta method (Sobel, 1982, as cited in Kline, 2023, p. 125, Equation 8.2; this is also the default of := in lavaan – Rosseel, 2012, section 7.4) – but "the Sobel test assumes normality, whereas distributions of product estimators are generally not normal; they are often asymmetrical with high kurtosis", it requires a large sample, and its p values in a small sample "can be very inaccurate" (Kline, p. 128). Bootstrap – which "does not assume normality" and is also suitable for paths of three or more links (ibid.). The page prints both side by side.
Bootstrap and the confidence intervals
Byrne (2016, pp. 367-368) describes the idea: the original sample serves as the "population", and many samples of the same size are drawn from it "with replacement"; in each sample the model is re-estimated, and the distribution of the estimates is a "concrete" sampling distribution that does not depend on the normality assumption. The page samples whole rows (participants) from the participants with a value on all items, estimates the model in each sample starting from the full-sample estimates, and keeps all the effects. A sample in which the estimation did not converge – is excluded from the computation; a sample with an inadmissible solution – stays and is reported, as in lavaan. The chart in the output shows the resulting distribution, and usually its asymmetry as well.
Two confidence intervals. Percentile: the limits are the 2.5th and 97.5th percentiles of the bootstrap distribution (the page uses lavaan's interpolation, boot.ci.type = "perc"). Bias-corrected: Kline (2023, p. 129) describes it as a method that "adjusts for possible asymmetry in the empirical sampling distribution, by determining the proportion of bootstrap estimates that fall below the observed result" (Efron, 1987, as cited in Kline) – this is lavaan's "bca.simple", and it is the interval that AMOS prints (Byrne, 2016, p. 374, the default there – 90%). The page prints both ("both/and"): when they agree – there is no question; when one includes zero and the other does not – the result is borderline. The seed: Kline (p. 129) notes that bootstrap interval limits "are not necessarily unique unless the researcher sets a seed" – with a different seed and in another sample the question of whether zero is inside can flip. The page implements R's random-number generator (Mersenne-Twister and sample.int), so seed 2026 here and iseed = 2026 in lavaan give exactly the same samples – and the same intervals.
How many samples? 1,000 – the default in the packages Kline (p. 129) ran, and also on the page; Byrne (p. 374) demonstrated with 500. The more samples, the less the limits depend on the seed; 5,000 take about half a minute in the browser.
Effect size
Kline (2023, pp. 353-355) notes that there is no "universal, comprehensive mediation effect size" and that all indices have limitations. Table 5 in the output gives three: the standardized indirect effect – in standard deviations of the outcome, for a change of one standard deviation in the predictor (p. 353), with the limitation that standardized values cannot be compared across samples with different variances. The proportion mediated PM = ab/(ab + c′) (Equation 20.1) – "probably the most reported", but "not a simple proportion": it can exceed 1 or be negative, it is unbounded when the total is close to zero, and a ratio of a very small indirect effect to a total only slightly larger can look "high" (Preacher and Kelley, 2011, as cited in Kline, p. 354); and its values "may be unstable when N < 500". In the sample data file PM = 1.05 – the direct effect is almost zero and negative – and its bootstrap interval is very wide: this is exactly why. û = (asbs)² (Lachowicz et al., 2018, as cited in Kline, Equation 20.3) – the square of the standardized indirect effect, which in the population equals the share of the outcome's variance that the predictor and the mediator explain together after correcting for spurious associations; biased upward, especially in a small sample. The page prints it only for a single path of two links, as in the definition.
Interpretation: what mediation says – and what it does not
Full, partial, inconsistent. A direct path that does not differ from zero alongside an indirect effect that does – "full mediation"; direct and indirect effects with the same sign – "partial" (Kline, 2023, p. 127). When the indirect and direct effects have opposite signs – "inconsistent mediation": the total can be close to zero even when the indirect effect is substantial, so the old requirement of a "significant relation between the predictor and the outcome" as a first condition for mediation wrongly rules it out; when controlling for the mediator strengthens the relation – "suppression" (ibid., pp. 127-128). The interpretation of the result in the output identifies all three cases.
The mediation myth. Kline (2023, p. 349) opens the mediation chapter with a "myth" – the belief that a typical mediation study actually estimates mediation, when the design is cross-sectional, the assumptions are not discussed, a significant indirect effect is taken as "proof" and equivalent models are not mentioned. Three obstacles in cross-sectional research (p. 350): (1) "lack of temporal precedence" – mediation is defined as change transmitted from factor to factor, and change cannot be estimated from a single measurement; (2) without a strong conceptual order in time, one model cannot be preferred over equivalent models – and in a model of three variables there are 18 of them, some with no mediation at all (Figure 20.1); (3) bias from an unmeasured common cause. Thoemmes (2015, as cited in Kline, pp. 352-353) showed that reversing arrows in order to choose the model with the significant indirect effect is not legitimate – a wrong model often gives an indirect effect of similar size, and the right model is not necessarily the one with the largest effect. What helps: a longitudinal design (half-longitudinal or full – pp. 356-357), an instrumental variable, good indicators and different measurement methods for the mediator and the outcome (p. 353).
Assumptions and warnings
Bootstrap is not magic. Kline (2023, p. 129): bootstrap estimates "can be very biased in small samples, especially if the sample distributions do not reflect the population distributions". Byrne (2016, pp. 369-370) lists the limitations: the original sample must represent the population; the observations must be independent and identically distributed (Yung and Bentler, 1996, as cited in Byrne); with normal data bootstrap standard errors are more biased than ML ones (Ichikawa and Konishi, 1995, as cited in Byrne); and bootstrap "is certainly not a panacea for small samples". Setting the scale: Byrne (p. 370) cites Arbuckle (2007, as cited in Byrne): with bootstrap, fix one loading per factor, not the factor variance – fixing the variances to 1 "leads to highly inflated bootstrap standard errors" (Hancock and Nevitt, 1999, as cited in Byrne). So on the page – marker only; the standardized effects do not depend on this choice.
Sample size and the SEM assumptions – as on the page structural equation model: below 200 participants, or fewer than 10 per parameter, the page warns (Kline, 2023, p. 16); items with fewer than five categories (Rhemtulla et al., 2012, p. 354); an inadmissible solution (Kline, p. 421). Kline (p. 354) adds that the proportion mediated PM may be unstable below 500 participants. Missing values – listwise deletion before the bootstrap (as in lavaan).
What the page does not compute. Conditional mediation (moderation of a path – "conditional process analysis", Kline, pp. 358-361), longitudinal models with lagged effects, causal mediation in Pearl's sense (natural effects, p. 360), a full BCa interval (with an acceleration constant – only bca.simple), Bollen-Stine bootstrap for the fit test, non-recursive models and disturbance correlations, group comparison and measurement invariance.
And how is it done in SPSS and AMOS?
SPSS Statistics has no structural equation models (Pallant, 2020, Chapter 10); for mediation between scale scores there is Hayes's PROCESS macro (2022, as cited in Kline, 2023, pp. 129, 358), which computes bootstrap intervals for observed variables and assumes "zero measurement error" (Kline, p. 358). In AMOS the model is drawn as on the SEM page, and in the Analysis Properties window, on the Bootstrap tab, check Perform bootstrap, the number of samples and Bias-corrected confidence intervals – the default is 90% (Byrne, 2016, pp. 373-374). In the summary AMOS reports how many samples were "not used" because no solution was found (ibid., p. 382) – like the bootstrap line at the top of the output here. The expected differences: AMOS computes χ² with divisor N − 1 (Byrne, p. 93), and its random-number generator is different – the limits will be close but not identical.
And how do you do it in R?
In lavaan, define labels for the paths (a*trust), the effects with :=, and request se = "bootstrap" (Rosseel, 2012, Section 7.4); iseed sets the seed. The confidence intervals – in parameterEstimates with boot.ci.type = "perc" or "bca.simple". The "Download R script" button in the output writes the model you defined with the same number of samples and the same seed. The script below was run as is on the sample data file (lavaan 0.6-17), and the page, with 1,000 samples and seed 2026, gives the same numbers.
# Latent mediation with bootstrap – Professor Stat. This file is saved as UTF-8; every comment line starts with an English word
library(readxl) # Reading Excel
library(lavaan) # sem, parameterEstimates
# Loading: the standard layout – row = participant, column = item; the sheet "data"
d <- read_excel("C:/Rdata/DATA_cfa_example_eng.xlsx", sheet = "data")
items <- c(paste0("belong_", 1:4), paste0("trust_", 1:4), paste0("partic_", 1:4))
d <- as.data.frame(d[, items])
names(d) <- c(paste0("b", 1:4), paste0("t", 1:4), paste0("p", 1:4)) # Short English names for the model
# Model: trust → belonging → participation, plus trust → participation; indirect effect, total and proportion mediated
model <- "
belong =~ b1 + b2 + b3 + b4
trust =~ t1 + t2 + t3 + t4
partic =~ p1 + p2 + p3 + p4
belong ~ a*trust
partic ~ b*belong + c*trust
ind := a*b
tot := c + a*b
pm := (a*b) / (c + a*b)
"
# 1000 bootstrap samples; iseed – the seed (as on the page: same seed, same samples)
fit <- sem(model, data = d, se = "bootstrap", bootstrap = 1000, iseed = 2026)
pe <- parameterEstimates(fit, boot.ci.type = "perc")
pe[pe$op %in% c("~", ":="), c("lhs", "op", "rhs", "label", "est", "se", "ci.lower", "ci.upper")]
# a 0.531 [0.402, 0.681]; b 0.529 [0.363, 0.712]; c -0.014 [-0.187, 0.158]
# ind 0.281 (SE 0.061) [0.174, 0.412]; tot 0.267 [0.121, 0.438]; pm 1.051 (SE 1.104) [0.574, 2.252]
pb <- parameterEstimates(fit, boot.ci.type = "bca.simple") # Bias-corrected
pb[pb$op == ":=", c("lhs", "est", "ci.lower", "ci.upper")] # ind [0.175, 0.413]
# For comparison – the delta method (no bootstrap)
fit_ml <- sem(model, data = d)
parameterEstimates(fit_ml)[parameterEstimates(fit_ml)$op == ":=", c("lhs", "est", "se", "pvalue")]
# ind SE 0.060; pm SE 0.332 – versus 1.104 with bootstrap: the delta method does not see the instability of the ratio
Reporting the results
Report the model (predictor, mediators, outcome, direct path or not), the model fit, the paths (b with its standard error, and β), and for each indirect effect – estimate, bootstrap confidence interval and its type (percentile or bias-corrected), the number of samples and the seed; with several mediators – each path separately as well. Kline (2023, p. 128) notes that there is no obligation to read the interval as a test: "all values within a confidence interval are in principle equivalent", and a zero inside it "is no more special than any other value" in it. Kline (p. 422): "it is a mistake to report only the standardized solution". APA (2020, section 6.36) – no zero before the decimal point for β and p, and with a zero for b; a table with a row for each effect – like Table 3 in the output. And in the discussion – the design (cross-sectional or longitudinal) and the equivalent models, without which "mediation" is a claim stronger than the data.
Common mistakes
"The indirect effect is significant – mediation is proven". In a cross-sectional design this is a hypothesis the data are consistent with, not proof (Kline, 2023, pp. 349-350).
Requiring first a significant relation between the predictor and the outcome. In inconsistent mediation the total can be zero even when the indirect effect is substantial (Kline, p. 127).
Relying on Sobel. The distribution of the product is asymmetric; report a bootstrap interval.
Changing the seed until the interval excludes zero. Set the seed in advance and report it; if the result depends on the seed – it is borderline.
Reading PM as a "percentage mediated". It can exceed 1, as in the example; report the standardized indirect effect alongside it.
Reversing arrows and choosing the model with the largest indirect effect. Equivalent models cannot be decided statistically (Thoemmes, 2015, as cited in Kline, pp. 352-353).
References
American Psychological Association. (2020). Publication manual of the American Psychological Association (7th ed.). https://doi.org/10.1037/0000165-000
Brown, T. A. (2015). Confirmatory factor analysis for applied research (2nd ed.). Guilford Press.
Byrne, B. M. (2016). Structural equation modeling with AMOS: Basic concepts, applications, and programming (3rd ed.). Routledge.
Hu, L., & Bentler, P. M. (1999). Cutoff criteria for fit indexes in covariance structure analysis: Conventional criteria versus new alternatives. Structural Equation Modeling: A Multidisciplinary Journal, 6(1), 1-55. https://doi.org/10.1080/10705519909540118
Kline, R. B. (2023). Principles and practice of structural equation modeling (5th ed.). Guilford Press.
Pallant, J. (2020). SPSS survival manual: A step by step guide to data analysis using IBM SPSS (7th ed.). Routledge.
Rhemtulla, M., Brosseau-Liard, P. É., & Savalei, V. (2012). When can categorical variables be treated as continuous? A comparison of robust continuous and categorical SEM estimation methods under suboptimal conditions. Psychological Methods, 17(3), 354-373. https://doi.org/10.1037/a0029315
Rosseel, Y. (2012). lavaan: An R package for structural equation modeling. Journal of Statistical Software, 48(2), 1-36. https://doi.org/10.18637/jss.v048.i02
Efron (1987), Hayes (2022), Iacobucci et al. (2007), Jackson (2003), Lachowicz et al. (2018), Pearl (2009), Preacher and Kelley (2011), Sobel (1982) and Thoemmes (2015) – as cited in Kline (2023); Arbuckle (2007), Hancock and Nevitt (1999), Ichikawa and Konishi (1995) and Yung and Bentler (1996) – as cited in Byrne (2016); Sobel (1982) – also in Rosseel (2012). By the site's rule, the reference list includes only sources read in the original. Site conventions: the default of 1,000 samples and seed 2026, showing both types of interval side by side, and marker only. The computation on the page is verified against lavaan 0.6-17 in R – the same samples, the same intervals.