TuringModels

Chimpanzees

This is the third Chimpanzees model (m10.3) in Statistical Rethinking Edition 1.

  1. Data
  2. Model
  3. Output
  4. Original output

Data

import CSV
import Random
import TuringModels

using DataFrames

Random.seed!(1)

file_path = joinpath(TuringModels.project_root, "data", "chimpanzees.csv")
df = CSV.read(file_path, DataFrame; delim=';');

Model

using StatsFuns
using Turing

@model function m10_3(y, x₁, x₂)
    α ~ Normal(0, 10)
    βp ~ Normal(0, 10)
    βpC ~ Normal(0, 10)

    logits = α .+ (βp .+ βpC * x₁) .* x₂
    y .~ BinomialLogit.(1, logits)
end
m10_3 (generic function with 2 methods)

Output

model = m10_3(df.pulled_left, df.condition, df.prosoc_left)
chns = sample(model, NUTS(), 2000)
Chains MCMC chain (2000×15×1 Array{Float64, 3}):

Iterations        = 1001:1:3000
Number of chains  = 1
Samples per chain = 2000
Wall duration     = 6.97 seconds
Compute duration  = 6.97 seconds
parameters        = α, βp, βpC
internals         = lp, n_steps, is_accept, acceptance_rate, log_density, hamiltonian_energy, hamiltonian_energy_error, max_hamiltonian_energy_error, tree_depth, numerical_error, step_size, nom_step_size

Summary Statistics
  parameters      mean       std   naive_se      mcse         ess      rhat   ess_per_sec
      Symbol   Float64   Float64    Float64   Float64     Float64   Float64       Float64

           α    0.0456    0.1277     0.0029    0.0036   1346.4069    1.0003      193.2549
          βp    0.6097    0.2205     0.0049    0.0073   1116.8667    1.0052      160.3081
         βpC   -0.0940    0.2626     0.0059    0.0082   1055.6564    1.0006      151.5224

Quantiles
  parameters      2.5%     25.0%     50.0%     75.0%     97.5%
      Symbol   Float64   Float64   Float64   Float64   Float64

           α   -0.2119   -0.0423    0.0498    0.1319    0.2884
          βp    0.1673    0.4573    0.6100    0.7623    1.0526
         βpC   -0.5852   -0.2684   -0.0957    0.0855    0.4300

using StatsPlots

StatsPlots.plot(chns)

Original output

"""
      Mean StdDev lower 0.89 upper 0.89 n_eff Rhat
 a    0.05   0.13      -0.15       0.25  3284    1
 bp   0.62   0.22       0.28       0.98  3032    1
 bpC -0.11   0.26      -0.53       0.29  3184    1
""";