# Example: swear words predicted by overall LHS
# Specify variables

data2 <- data1[ , c("word_count","swear","caq_overall_slh","p_id")]

#Coerce participant ID to factor

data2$p_factor <- coerce_index(data2$p_id)

# Null model -- intercept only

swear_null <- map2stan(
  alist(
    swear ~ binomial(word_count , p),
    logit(p) <- a_partic[p_factor],
    a_partic[p_factor] ~ dnorm(a , sigma),
    a ~ dnorm (-5 , 2),
    sigma ~ dcauchy(0 , 1)),
  data = data2, iter = 4000, chains = 4)

# Model with overall LHS as predictor of swear words

swear_overalllhs <- map2stan(
  alist(
    swear ~ binomial(word_count , p),
    logit(p) <- a + a_partic[p_factor] + b*caq_overall_slh,
    a ~ dnorm (0 , 7),
    b ~ dnorm (0 , 2),
    a_partic[p_factor] ~ dnorm(0 , sigma_participant),
    sigma_participant ~ dcauchy(0 , 1)),
  data = data2, iter = 4000, chains = 4)