Supplementary Bayesian Re-analysis
Methodological Supplement to the publication Examining holistic processing strategies in dogs and humans through gaze behavior
Objective of this document
This document presents a Bayesian extension of the frequentist analyses reported in Examining holistic processing strategies in dogs and humans through gaze behavior. By transitioning to a Bayesian framework, this supplement provides a more nuanced estimation of uncertainty and effect sizes for the following two key response variables. The relevant data sets dataDogHuman.txt and dataDogHumanCentroid.txt for the analysis are available at 10.5281/zenodo.12205140. The R code in the following assumes the data dataDogHuman.txt and dataDogHumanCentroid.txt in the R environment.
First-Fixation AOI Hit: A binary outcome (0/1) modeled using a Bernoulli distribution with a logit link function to estimate the probability of an initial gaze landing within the following 5 Areas of Interest (AOIs): inner features center, eyes, around eyes, else upper half, else lower half
There are three stimulus categories (human face, dog face, non-face obejct) which creates three data subsets (dataDogHuman.humanFace, dataDogHuman.dogFace, dataDogHuman.control).
First-fixation AOI centroid distance: A continuous metric representing the distance (pixels) between the first fixation and the AOI centroid. This variable was devised to further scrutinize the First-Fixation AOI hit result of humans to check if their first fixations on Inner features center AOI were indeed closest the centroid of the AOI instead of mere center of the face which locates close to the centroid of the inner features center AOI. Therefore this analysis only concerns human data of human face and dog face conditions.
Preparation of R environment
Import libraries
For model building:
library(brms)
library(Rcpp)
library(tidyverse)
For visualization and diagnostics:
library(bayesplot)
library(tidybayes)
library(posterior)
library(marginaleffects)
library(ggplot2)
For pairwise comparisons
library(emmeans)
The analysis
This report focuses specifically on the human face condition data of both response variables to demonstrate the Bayesian modeling pipeline.
- First-Fixation AOI Hit (name of the column in the data:firstFixAOIHitFiltered)
Data preparation
Data Cleaning: Remove trials with no fixations on the stimulus
This ensures we are only analyzing ‘active’ viewing behavior.
dataDogHuman <- subset(dataDogHuman, numFixOnStimTrial != 0)Factor Management: Reorder AOI levels for logical plotting
Setting the levels here ensures that ‘inner features center’ appears first in tables and plots and analysis results.
dataDogHuman$AOI <- factor(dataDogHuman$AOI, levels = c( "inner features center", "eyes", "around eyes", "else upper half", "else lower half" ))Sub setting: Split data by Stimulus Type
This allows for separate Bayesian models for each specific stimulus category.
dataDogHuman.humanFace<-subset(dataDogHuman,stimulusType=="human face")dataDogHuman.dogFace<-subset(dataDogHuman,stimulusType=="dog face")dataDogHuman.control<-subset(dataDogHuman,stimulusType=="control")Descriptive statistics: Before modeling, we examine the distribution of our primary outcome variable:
firstFixAOIHitFiltered. This is a binary variable (0 = Miss, 1 = Hit).hist(dataDogHuman.humanFace$firstFixAOIHitFiltered)Define the models
Use ‘bernoulli’ because the data is 0/1 (the hit probability)
Bayesian Model 1: without fixLocationSizeRelative (AOI size) as a fixed factor
b_humanFace_m1 <- brm( formula = firstFixAOIHitFiltered ~ AOI * species + (1 | name), data = dataDogHuman.humanFace, family = bernoulli(link = "logit"), # ADDING A PRIOR: This 'fences in' the model to realistic values prior = set_prior("normal(0, 3)", class = "b"), cores = 4, seed = 123, iter = 4000, control = list( adapt_delta = 0.99, max_treedepth = 15 # 15 is plenty if the Prior is set ), save_pars = save_pars(all = TRUE), file = "b_human_m1_robust" )Bayesian Model 2: with fixLocationSizeRelative (AOI Size) as a fixed factor
b_humanFace_m2 <- brm( firstFixAOIHitFiltered ~ AOI * species + fixLocationSizeRelative + (1 | name), data = dataDogHuman.humanFace, family = bernoulli(link = "logit"), # ADDING A PRIOR: This 'fences in' the model to realistic values prior = set_prior("normal(0, 3)", class = "b"), cores = 4, seed = 123, iter = 4000, control = list( adapt_delta = 0.99, max_treedepth = 15 # 15 is plenty if the Prior is set ), save_pars = save_pars(all = TRUE), file = "b_human_m2_robust" )Model diagnostics
Before comparing models, we verify convergence of the models.
# Check Model 1pp_check(``b_humanFace_m1``, ndraws = 100) + ggtitle("PPC: Model 1")# Check Model 2pp_check(``b_humanFace_m2``, ndraws = 100) + ggtitle("PPC: Model 2")# Quick check of R-hats for both modelsrhat_vals <- c(rhat(``b_humanFace_m1``), rhat(``b_humanFace_m2``))print(paste("Maximum R-hat across both models:", round(max(rhat_vals), 3)))"Maximum R-hat across both models: 1.002"Diagnostic checks for both models revealed excellent fit. Posterior predictive checks (PPC) confirmed that both the parsimonious model and the complex model accurately recovered the observed hit/miss distributions. Given the near-identical predictive performance and a negligible ELPD difference, Model 1 was selected for final inference based on the principle of parsimony.
Model comparison:
Compute the LOO criteria for both
loo1 <- loo(b_humanFace_m1, recompute_probabilities = TRUE, re_fit = TRUE, moment_match = TRUE)loo2 <- loo(b_humanFace_m2, recompute_probabilities = TRUE, re_fit = TRUE, moment_match = TRUE)Compare them
loo_compare(loo1, loo2)> loo_compare(loo1, loo2) elpd_diff se_diff b_humanFace_m2 0.0 0.0 b_humanFace_m1 -1.0 1.6Model comparison result indicated that the inclusion of relative AOI size (model 2) did not significantly improve the model’s predictive performance compared to the model 1. If the
elpd_diffis smaller than 2 times these_diff, the models are considered statistically tied. Since \(1.0 < 3.2\), there is no meaningful difference in predictive power between the two models. Consequently, following the principle of Parsimony,model 1 was selected as the final model for inference.pairwise comparisons
1. Construct the reference grid for the Bayesian model
use ‘response’ to get probabilities (0-1) instead of log-odds
humanFaceEsm_bayas <- emmeans(``b_humanFace_m1``~ AOI | species, type = "response")2. Define your AOI vectors
Run levels(data$AOI) to confirm the order is:
A1: inner features, B1: eyes, C1: around eyes, D1: else upper, E1: else lower
A1 <- c(1, 0, 0, 0, 0)B1 <- c(0, 1, 0, 0, 0)C1 <- c(0, 0, 1, 0, 0)D1 <- c(0, 0, 0, 1, 0)E1 <- c(0, 0, 0, 0, 1)3. Custom Pairwise Contrasts
Note: No ‘bonferroni’ needed here. report 95% Credible Intervals.
AOI_Contrants_Bayesian <- contrast(humanFaceEsm_bayas, method = list(# Pairwise Humans"Human: center - eyes" = A1 - B1,"Human: center - around eyes" = A1 - C1,"Human: center - else upper half" = A1 - D1,"Human: center - else lower half" = A1 - E1,# Pairwise Dogs"Dog: else upper - inner features" = D1 - A1,"Dog: else upper - eyes" = D1 - B1,"Dog: else upper - around eyes" = D1 - C1,"Dog: else upper - else lower half" = D1 - E1 ))4. View results
probabilities <- summary(humanFaceEsm_bayas, type = "response")
Point estimate displayed: median Results are back-transformed from the logit scale HPD interval probability: 0.95 The analysis reveals distinct fixation strategies: Humans exhibit a high-probability strategy targeting the inner features center AOI (67.8% probability). Bayesian contrasts confirm that humans are approximately 129 times more likely to target the inner features center compared to for example the else upper half AOI (OR = 129.27, 95% HPD [7.34, 362.00]). In contrast, dogs prioritize the else upper half AOI (52.3% probability). For dogs, the likelihood of first fixating on the else upper half AOI is over 534 times greater than fixating on the region around eyes AOI (OR = 534.06, 95% HPD [1.35, 1730.00]).
- First-Fixation AOI centroid distance (name of the column in the data: distance2ndFixFiltered)
Data preparation
Data Cleaning: Remove trials with no fixations on the stimulus
This ensures we are only analyzing 'active' viewing behavior.dataDogHumanCentroid<-dataDogHumanCentroid[!(dataDogHumanCentroid$distance2ndFixFiltered=="NA"),]dataHumanCentroid<-subset(dataDogHumanCentroid,species=="human")dataHumanCentroid<-subset(dataHumanCentroid,stimulusType=="human face"|stimulusType=="dog face")dataHumanCentroid<-subset(dataHumanCentroid,AOI=="inner features center"|AOI== "whole stimulus")dataHumanCentroid$AOI<- factor(dataHumanCentroid$AOI, levels = c("inner features center", "whole stimulus"))summary(dataHumanCentroid$distance2ndFixFiltered)Sub setting: Split data by Stimulus Type
This allows for separate Bayesian models for each specific stimulus category.dataHumanCentroid.humanFace<-subset(dataHumanCentroid,stimulusType=="human face") dataHumanCentroid.dogFace<-subset(dataHumanCentroid,stimulusType=="dog face")Descriptive statistics: Before modeling, we examine the distribution of our primary outcome variable
#human face condition hist(dataHumanCentroid.humanFace$distance2ndFixFiltered,breaks=80,xlab="distances to AOI centers", main="Human face condition",ylab='frequency')Define the model
bayesian_centroid_m <- brm(formula = distance2ndFixFiltered ~ AOI + (1 | name), The Data data = dataHumanCentroid.humanFace, family = gaussian(), chains = 4, iter = 2000, warmup = 1000, cores = 4, seed = 123, file = "bayesian_centroid_humanFace")Model diagnostics
1. Density Overlay (Standard pp_check)
pp_check(bayesian_centroid_m) + ggtitle("Posterior Predictive Check")2. Predicted vs. Observed Scatter Plot
This shows if the model over/under predicts at certain distances
pp_check(bayesian_centroid_m, type = "error_scatter_avg") + ggtitle("Residual Scatter")Diagnostic evaluation of the centroid distance model yielded an \(\hat{R}\) of 1.002, indicating successful convergence. Posterior predictive checks (PPC) and residual scatter analysis confirm that the Gaussian identity-link model accurately recovers the central tendency and variance of the spatial fixation data (\(y \approx y_{rep}\)
Pairwise comparison
1. Get the estimated marginal means (average distance per AOI)
centroid_means <- emmeans(bayesian_centroid_m, ~ AOI)2. Perform all possible pairwise comparisons
This calculates the difference in pixels between every AOI pair
centroid_pairs <- pairs(centroid_means)3. Summary with 95% Highest Posterior Density (HPD) Intervals
summary(centroid_pairs, point.est = mean, level = 0.95)contrast estimate lower.HPD upper.HPD inner features center - whole stimulus -11.9 -20.5 -3.17
Spatial analysis of the first fixation revealed a significant increase in targeting precision for the inner features center compared to the whole stimulus (\(\beta = -11.9\) pixels, 95% HPD [-20.5, -3.17]). This indicates that gaze directed at the inner features center AOI of the human face is not only more frequent but also more spatially focused toward the centroied of the inner features center AOI than the centroid of the whole face area.
Conclusion: Convergence of Frequentist and Bayesian Evidence
This analysis demonstrates that the gaze patterns identified in the original Linear Mixed-Effects (LME) models are robust when subjected to Bayesian inference. By transitioning to a Bayesian framework, I have moved beyond simple p-value thresholds to a more detailed estimation of the posterior distributions. The primary findings—that humans prioritize the inner features center while dogs prioritize the else upper half—remain consistent across both frameworks. However, the Bayesian approach adds significant value by providing 95% Highest Posterior Density (HPD) intervals and Odds Ratios, allowing for a direct probabilistic interpretation of species-specific gaze priorities. Furthermore, the spatial analysis of the distance to centroid confirms that gaze toward the center of the face is not only more probable but significantly more spatially precise than gaze toward the stimulus as a whole. This convergence of evidence strengthens the validity of our conclusions regarding cross-species social attention strategies.