class: center, middle, inverse, title-slide .title[ # Quantitative Methods for LEL ] .subtitle[ ## Week 5 ] .author[ ### Dr Stefano Coretta ] .institute[ ### University of Edinburgh ] .date[ ### 2023/10/17 ] --- <iframe allowfullscreen frameborder="0" height="100%" mozallowfullscreen style="min-width: 500px; min-height: 355px" src="https://app.wooclap.com/events/SQQFXB/questions/652a98157fefc577d4567060" width="100%"></iframe> --- ## Summary from last week .bg-washed-blue.b--dark-blue.ba.bw2.br3.shadow-5.ph4.mt2[ - **Probability distributions** - Continuous vs discrete distributions. - Describe distributions: density functions and parameters. - **Modelling continuous variables** - The Gaussian distribution has two parameters: mean `\(\mu\)` and SD `\(\sigma\)`. - We can describe `\(\mu\)` and `\(\sigma\)` as probability distributions and estimate the (hyper-)parameters of those probability distributions. - `brm()` from brms. ] --- layout: true ## Comparing groups --- ```r polite ``` ``` ## # A tibble: 224 × 27 ## subject gender birthplace musicstudent months_ger scenario task attitude total_duration ## <chr> <chr> <chr> <chr> <dbl> <dbl> <chr> <fct> <dbl> ## 1 F1 F seoul_area yes 18 6 not informal 55.2 ## 2 F1 F seoul_area yes 18 6 not polite 28.5 ## 3 F1 F seoul_area yes 18 7 not informal 60.3 ## 4 F1 F seoul_area yes 18 7 not polite 40.8 ## 5 F1 F seoul_area yes 18 1 dct polite 18.4 ## 6 F1 F seoul_area yes 18 1 dct informal 13.6 ## 7 F1 F seoul_area yes 18 2 dct polite 5.22 ## 8 F1 F seoul_area yes 18 2 dct informal 4.25 ## 9 F1 F seoul_area yes 18 3 dct polite 6.79 ## 10 F1 F seoul_area yes 18 3 dct informal 4.13 ## # ℹ 214 more rows ## # ℹ 18 more variables: articulation_rate <dbl>, f0mn <dbl>, f0sd <dbl>, f0range <dbl>, inmn <dbl>, ## # insd <dbl>, inrange <dbl>, shimmer <dbl>, jitter <dbl>, HNRmn <dbl>, H1H2 <dbl>, ## # breath_count <dbl>, filler_count <dbl>, hiss_count <dbl>, nasal_count <dbl>, sil_count <dbl>, ## # ya_count <dbl>, yey_count <dbl> ``` --- <img src="index_files/figure-html/hnr-1.png" width="60%" style="display: block; margin: auto;" /> HNR is the ratio between periodicity and noise in the voice signal. Lower HNR values indicate less modal voice (i.e. creakier or breathier). --- .bg-washed-blue.b--dark-blue.ba.bw2.br3.shadow-5.ph4.mt2[ - We want to estimate the probability distribution of harmonics-to-noise ratio (HNR) in Korean speakers. - Let's assume it is a Gaussian probability distribution. - So, `\(\text{HNR} \sim Gaussian(\mu, \sigma)\)`. ] -- .bg-washed-blue.b--dark-blue.ba.bw2.br3.shadow-5.ph4.mt2[ - But we also want to estimate the difference in the mean (`\(\mu\)`) in the informal vs polite attitude conditions! - In other words, we need to allow the model to estimate `\(\mu\)` based on attitude (informal vs polite). ] --- .f3[ `$$\text{HNR} \sim Gaussian(\mu, \sigma)$$` ] -- .f3[ $$ `\begin{align} \mu_{attitude=informal} & \sim Gaussian(\mu_1, \sigma_1) \\ \mu_{attitude=polite} & \sim Gaussian(\mu_2, \sigma_2) \\ \sigma & \sim TruncGaussian(\mu_3, \sigma_3) \end{align}` $$ ] -- .bg-washed-yellow.b--gold.ba.bw2.br3.shadow-5.ph4.mt2[ That would be great, but alas these models are set up in a different way by default! ] -- .bg-washed-blue.b--dark-blue.ba.bw2.br3.shadow-5.ph4.mt2[ These models are called *linear models*, or *regression models*, or *linear regression models*. They are a generalisation of the formula of a line: $$ y = a + b \cdot x $$ ] --- layout: false layout: true ## Linear models --- <iframe src="https://stefanocoretta.shinyapps.io/lines/" width="100%" height="500"></iframe> --- .bg-washed-blue.b--dark-blue.ba.bw2.br3.shadow-5.ph4.mt2[ .f3.center[ `brm(y ~ x)` ] - The variable `y` to the left of `~` is called the **outcome variable** (aka response variable, dependent variable). - The variable `x` to the right of `~` is called the **predictor variable** (aka independent variable). ] -- .bg-washed-yellow.b--gold.ba.bw2.br3.shadow-5.ph4.mt2[ There is a catch: linear models are meant to be used with numeric variables. 😱 But... `attitude` is not a numeric predictor! ] .bg-washed-green.b--dark-green.ba.bw2.br3.shadow-5.ph4.mt2[ Let's talk about coding of categorical variables! ] --- layout: false layout: true ## Coding categorical predictors --- .bg-washed-yellow.b--gold.ba.bw2.br3.shadow-5.ph4.mt2[ **NOTE**: What follows is for you how to understand how coding works, but remember that this is done automatically by R for you so you never have to do it by hand!!! ] .bg-washed-blue.b--dark-blue.ba.bw2.br3.shadow-5.ph4.mt2[ **Categorical predictors can be coded using numbers.** There are two common types of coding systems: - **Treatment** coding (this week's focus). - **Sum** coding. ] -- .bg-washed-green.b--dark-green.ba.bw2.br3.shadow-5.ph4.mt2[ As with anything else in stats, **naming of coding systems is not an established matter** and the same coding can have different names, and vice versa the same name could refer to different systems. For an excellent overview, see <https://debruine.github.io/faux/articles/contrasts.html>. ] --- **Treatment** coding uses `0` and `1` to code categorical predictors. .f3[ | | attitude_pol | | ------------- | -------: | | informal | 0 | | polite | 1 | ] -- <br> .bg-washed-blue.b--dark-blue.ba.bw2.br3.shadow-5.ph4.mt2[ With **treatment coding**, the first level in the predictor is the **reference level** (in `attitude`, it is `informal`). ] -- .bg-washed-yellow.b--gold.ba.bw2.br3.shadow-5.ph4.mt2[ **Level order** By default, the ordering of levels in a categorical predictor is based on alphabetical order. But you can specify the order manually using the `factor()` function. (You will see how in the tutorial). ] --- ``` ## # A tibble: 224 × 3 ## HNRmn attitude attitude_pol ## <dbl> <fct> <dbl> ## 1 18.1 informal 0 ## 2 17.8 polite 1 ## 3 17 informal 0 ## 4 17.1 polite 1 ## 5 18.5 polite 1 ## 6 18.8 informal 0 ## 7 20.9 polite 1 ## 8 14.6 informal 0 ## 9 20.6 polite 1 ## 10 16.1 informal 0 ## # ℹ 214 more rows ``` .bg-washed-yellow.b--gold.ba.bw2.br3.shadow-5.ph4.mt2[ **NOTE**: Remember that this is done automatically by R under the hood for you so you never have to do it by hand!!! We will use `attitude` in the model. ] --- layout: false layout: true ## Comparing groups --- .f4[ $$ `\begin{align} \text{HNR} & \sim Gaussian(\mu, \sigma) \\ \mu & = \beta_0 + \beta_1 \cdot attitude_{pol} \\ [\text{formula of line: } y & = a + b \cdot x] \end{align}` $$ ] -- .bg-washed-blue.b--dark-blue.ba.bw2.br3.shadow-5.ph4.mt2[ **For [attitude = informal]**, `\(attitude_{pol} = 0\)`: $$ `\begin{align} \mu & = \beta_0 + \beta_1 \cdot attitude_{pol} \\ & = \beta_0 + \beta_1 \cdot 0 \\ & = \beta_0 \end{align}` $$ **For [attitude = polite]**, `\(attitude_{pol} = 1\)`: $$ `\begin{align} \mu & = \beta_0 + \beta_1 \cdot attitude_{pol} \\ & = \beta_0 + \beta_1 \cdot 1 \\ & = \beta_0 + \beta_1 \end{align}` $$ ] --- .f4[ $$ `\begin{align} \text{HNR} & \sim Gaussian(\mu, \sigma) \\ \mu & = \beta_0 + \beta_1 \cdot attitude_{pol} \\ [\text{formula of line: } y & = a + b \cdot x] \end{align}` $$ ] <br> .bg-washed-blue.b--dark-blue.ba.bw2.br3.shadow-5.ph4.mt2[ - `\(\beta_0\)`: (`Intercept`) mean HNR when [attitude = informal], the reference level of `attitude`. - `\(\beta_1\)`: **difference** of mean HNR between [attitude = polite] and [attitude = informal]. $$ `\begin{align} \beta_1 & = \mu_{pol} - \mu_{inf} \\ & = (\beta_0 + \beta_1) - (\beta_0) \\ & = \beta_1 \end{align}` $$ ] --- .f4[ $$ `\begin{align} \text{HNR} & \sim Gaussian(\mu, \sigma) \\ \mu & = \beta_0 + \beta_1 \cdot attitude_{pol} \\ [\text{formula of line: } y & = a + b \cdot x] \end{align}` $$ ] <br> .bg-washed-blue.b--dark-blue.ba.bw2.br3.shadow-5.ph4.mt2[ `\(\beta_1\)` is the **effect of [attitude = polite]** on mean HNR relative to the baseline mean HNR when [attitude = informal]. ] -- .bg-washed-yellow.b--gold.ba.bw2.br3.shadow-5.ph4.mt2[ With **treatment coding**, the second level [polite] is compared against the reference level [informal]. ] --- layout: false <iframe allowfullscreen frameborder="0" height="100%" mozallowfullscreen style="min-width: 500px; min-height: 355px" src="https://app.wooclap.com/events/SQQFXB/questions/652aa2082f02d279df6cf38f" width="100%"></iframe> --- layout: true ## Comparing groups --- .f4[ $$ `\begin{align} \text{HNR} & \sim Gaussian(\mu, \sigma) \\ \mu & = \beta_0 + \beta_1 \cdot attitude_{pol} \\ \beta_0 & \sim Gaussian(\mu_0, \sigma_0) \\ \beta_1 & \sim Gaussian(\mu_1, \sigma_1) \\ \sigma & \sim TruncGaussian(\mu_2, \sigma_2) \end{align}` $$ ] <br> .bg-washed-blue.b--dark-blue.ba.bw2.br3.shadow-5.ph4.mt2[ We need to estimate: - The **probability distribution of `\(\beta_0\)`**, i.e. the mean HNR when [attitude = informal]. - The **probability distribution of `\(\beta_1\)`**, i.e. the difference in mean HNR between [attitude = polite] and [attitude = informal]. - The **probability distribution of `\(\sigma\)`**, i.e. the standard deviation. ] --- .f4[ $$ `\begin{align} \text{HNR} & \sim Gaussian(\mu, \sigma) \\ \mu & = \beta_0 + \beta_1 \cdot attitude_{pol} \\ \beta_0 & \sim Gaussian(\mu_0, \sigma_0) \\ \beta_1 & \sim Gaussian(\mu_1, \sigma_1) \\ \sigma & \sim TruncGaussian(\mu_2, \sigma_2) \end{align}` $$ ] <br> .bg-washed-blue.b--dark-blue.ba.bw2.br3.shadow-5.ph4.mt2[ In other words, we need to estimate the following hyperparameters: `\(\mu_0, \sigma_0, \mu_1, \sigma_1, \mu_2, \sigma_2\)`. ] --- layout: false layout: true ## Modelling HNR by attitude --- ```r # Attach the brms package library(brms) # Run a Bayesian model vot_bm <- brm( # This is the formula of the model. HNRmn ~ 1 + attitude, # This is the probability distribution family. family = gaussian(), # And the data. data = polite ) ``` --- .f2.center[ `HNRmn ~ 1 + attitude` ] **Read as**: Model HNR values (`HNRmn`) as a function of (`~`) the mean (`1`) and attitude (`attitude`). -- .f2.center[ `HNRmn ~ attitude` ] We can omit the `1` (it is implied by default when there are other terms in the formula)! **You can read as**: Model HNR values (`HNRmn`) as a function of (`~`) attitude (`attitude`). -- .bg-washed-blue.b--dark-blue.ba.bw2.br3.shadow-5.ph4.mt2[ - `HNRmn` is the **outcome variable** (aka response variable, dependent variable). - `attitude` is the **predictor variable** (aka independent variables). ] --- ```r vot_bm <- brm( # This is the formula of the model. We can omit `1`. HNRmn ~ attitude, # This is the probability distribution family. family = gaussian(), # And the data. data = polite ) ``` --- ``` ## Family: gaussian ## Links: mu = identity; sigma = identity ## Formula: HNRmn ~ attitude ## Data: polite (Number of observations: 224) ## Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1; ## total post-warmup draws = 4000 ## ## Population-Level Effects: ## Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS ## Intercept 16.27 0.16 15.97 16.59 1.00 4136 3237 ## attitudepolite 1.25 0.23 0.80 1.70 1.00 4396 2937 ## ## Family Specific Parameters: ## Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS ## sigma 1.69 0.08 1.54 1.86 1.00 4065 2979 ## ## Draws were sampled using sample(hmc). For each parameter, Bulk_ESS ## and Tail_ESS are effective sample size measures, and Rhat is the potential ## scale reduction factor on split chains (at convergence, Rhat = 1). ``` --- ``` ## Population-Level Effects: ## Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS ## Intercept 16.27 0.16 15.97 16.59 1.00 4136 3237 ## attitudepolite 1.25 0.23 0.80 1.70 1.00 4396 2937 ``` -- <br> .f4[ $$ `\begin{align} \mu & = \beta_0 + \beta_1 \cdot attitude_{pol} \\ \beta_0 & \sim Gaussian(16.27, 0.16) \\ \beta_1 & \sim Gaussian(\mu_1, \sigma_1) \end{align}` $$ ] - Parameter `\(\beta_0\)` (`Intercept`): this is `\(\mu\)` when [attitude = informal]. - **Estimate**: `\(\mu_0 = 16.27\)` dB. - **Est.Error**: `\(\sigma_0 = 0.16\)` dB. -- .bg-washed-blue.b--dark-blue.ba.bw2.br3.shadow-5.ph4.mt2[ When [attitude = informal], the probability distribution of `\(\mu\)` is the probability distribution of `\(\beta_0\)`, which is `\(Gaussian(16.27, 0.16)\)`. ] --- <img src="index_files/figure-html/hnr-int-p-1.png" width="60%" style="display: block; margin: auto;" /> --- <img src="index_files/figure-html/hnr-int-p-2-1.png" width="60%" style="display: block; margin: auto;" /> -- There is a 95% probability that mean HNR when [attitude = informal] is between 15.97 and 16.59 dB. --- ``` ## Population-Level Effects: ## Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS ## Intercept 16.27 0.16 15.97 16.59 1.00 4136 3237 ## attitudepolite 1.25 0.23 0.80 1.70 1.00 4396 2937 ``` <br> .f4[ $$ `\begin{align} \mu & = \beta_0 + \beta_1 \cdot attitude_{pol} \\ \beta_0 & \sim Gaussian(16.27, 0.16) \\ \beta_1 & \sim Gaussian(1.25, 0.23) \end{align}` $$ ] - Parameter: **`\(\beta_1\)`**: difference of `\(\mu\)` when [attitude = polite] and [attitude = informal]. - **Estimate**: `\(\mu_1 = 1.25\)` dB. - **Est.Error**: `\(\sigma_1 = 0.23\)` dB. -- .bg-washed-blue.b--dark-blue.ba.bw2.br3.shadow-5.ph4.mt2[ The probability distribution of the difference between `\(\mu_{\text{attitude = polite}}\)` and `\(\mu_{\text{attitude = informal}}\)` is the probability distribution of `\(\beta_1\)`, which is `\(Gaussian(1.25, 0.23)\)`. ] --- <img src="index_files/figure-html/hnr-att-p-1.png" width="60%" style="display: block; margin: auto;" /> --- <img src="index_files/figure-html/hnr-att-p-2-1.png" width="60%" style="display: block; margin: auto;" /> -- There is 95% probability that the difference in mean HNR between `\(\mu_{\text{attitude = polite}}\)` and `\(\mu_{\text{attitude = informal}}\)` is between 0.8 and 1.7 dB. --- ``` ## Population-Level Effects: ## Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS ## Intercept 16.27 0.16 15.97 16.59 1.00 4136 3237 ## attitudepolite 1.25 0.23 0.80 1.70 1.00 4396 2937 ``` .f4[ $$ `\begin{align} \mu & = \beta_0 + \beta_1 \cdot attitude_{pol} \\ \beta_0 & \sim Gaussian(16.27, 0.16) \\ \beta_1 & \sim Gaussian(1.25, 0.23) \end{align}` $$ ] .bg-washed-blue.b--dark-blue.ba.bw2.br3.shadow-5.ph4.mt2[ What is the average `\(\mu\)` when [attitude = polite]? $$ `\begin{align} \mu & = \beta_0 + \beta_1 \cdot attitude_{pol} \\ & = \beta_0 + \beta_1 \cdot 1 \\ & = \beta_0 + \beta_1 \\ & = 16.27 + 1.25 \\ & = 17.52 \end{align}` $$ ] --- ``` ## Family Specific Parameters: ## Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS ## sigma 1.69 0.08 1.54 1.86 1.00 4065 2979 ``` <br> .f4[ $$ `\begin{align} \text{HNR} & \sim Gaussian(\mu, \sigma) \\ \mu & = \beta_0 + \beta_1 \cdot attitude_{pol} \\ \beta_0 & \sim Gaussian(16.27, 0.16) \\ \beta_1 & \sim Gaussian(1.25, 0.23) \\ \sigma & \sim TruncGaussian(1.69, 0.08) \end{align}` $$ ] --- **Reporting** > We fitted a Bayesian model with HNR as the outcome variable and attitude (informal vs polite) as the only predictor, using a Gaussian distribution as the distribution family of the outcome variable. The categorical predictor attitude was coded using the default treatment contrasts, with "informal" as the reference level. > > According to the model, the mean HNR for the informal attitude is between 16 and 16.5 db (`\(\beta\)` = 16.3, SD = 0.16), at 95% probability. When the attitude is polite, there is an increase in HNR between 0.8 and 1.7 db (`\(\beta\)` = 1.25, SD = 0.23). --- <img src="index_files/figure-html/hnr-sig-p-1.png" width="60%" style="display: block; margin: auto;" /> --- <img src="index_files/figure-html/hnr-sig-p-2-1.png" width="60%" style="display: block; margin: auto;" /> -- There is a 95% probability that the standard deviation of the probability distribution of HNR values is between 1.54 and 1.86 dB. --- layout: false class: center middle ## MID-TERM COURSE EVALUATION ## [bit.ly/45wgCEf](http://bit.ly/45wgCEf) --- layout: true ## Modelling VOT by stop --- ```r alb_vot_vl ``` ``` ## # A tibble: 45 × 8 ## speaker file label release voi_onset consonant vot stop ## <chr> <chr> <chr> <dbl> <dbl> <chr> <dbl> <chr> ## 1 s01 011-kati k 0.754 0.785 k 31.5 k ## 2 s01 014-pata p 0.705 0.712 p 7.46 p ## 3 s01 020-tapa t 0.825 0.833 t 8.00 t ## 4 s01 052-kati k 0.772 0.807 k 35.0 k ## 5 s01 055-pata p 0.823 0.838 p 15.0 p ## 6 s01 061-tapa t 0.944 0.953 t 8.62 t ## 7 s01 093-kati k 0.908 0.946 k 38.1 k ## 8 s01 096-pata p 1.10 1.10 p 6.24 p ## 9 s01 102-tapa t 0.951 0.964 t 13.1 t ## 10 s02 011-tapa t 0.752 0.766 t 13.9 t ## # ℹ 35 more rows ``` --- <img src="index_files/figure-html/vot-1-1.png" width="60%" style="display: block; margin: auto;" /> --- <img src="index_files/figure-html/vot-2-1.png" width="60%" style="display: block; margin: auto;" /> --- <img src="index_files/figure-html/vot-3-1.png" width="60%" style="display: block; margin: auto;" /> --- .bg-washed-blue.b--dark-blue.ba.bw2.br3.shadow-5.ph4.mt2[ - We want to estimate the probability distribution of Voice Onset Time (VOT) in Albanian voiceless stops /k, p, t/. - Let's assume it is a Gaussian probability distribution. - So, `\(\text{vot} \sim Gaussian(\mu, \sigma)\)`. ] -- .bg-washed-blue.b--dark-blue.ba.bw2.br3.shadow-5.ph4.mt2[ - But we also want to estimate the difference in the mean (`\(\mu\)`) in each stop /k, p, t/! - In other words, we need to allow the model to estimate `\(\mu\)` based on the stop. ] -- .bg-washed-green.b--dark-green.ba.bw2.br3.shadow-5.ph4.mt2[ 😱 But... `stop` is not a numeric predictor! ] --- **Treatment** coding uses `0` and `1` to code categorical predictors. **But** now we have three levels (`k, p, t`) so `0` and `1` are not enough. -- .bg-washed-blue.b--dark-blue.ba.bw2.br3.shadow-5.ph4.mt2[ In treatment coding, **N-1 dummy variables** are created where N is the number of levels. - `attitude` has two levels (informal vs polite) so we need `\(N-1 = 2-1 = 1\)` dummy variable: `attitude_pol`. - `stop` has three levels (/k, p, t/) so we need `\(N-1 = 3-1 = 2\)` dummy variables: `stop_p` and `stop_t`. - The reference level does not get a dummy variable! ] -- <br> | | stop_p | stop_t | |---|--------|--------| | k | 0 | 0 | | p | 1 | 0 | | t | 0 | 1 | --- ```r # Run a Bayesian model vot_bm <- brm( # This is the formula of the model. vot ~ stop, # This is the probability distribution family. family = gaussian(), # And the data. data = alb_vot_vl ) ``` -- .bg-washed-yellow.b--gold.ba.bw2.br3.shadow-5.ph4.mt2[ **Remember**: coding is done under the hood for you. You don't have to do it manually! ] --- ``` ## Family: gaussian ## Links: mu = identity; sigma = identity ## Formula: vot ~ stop ## Data: alb_vot_vl (Number of observations: 45) ## Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1; ## total post-warmup draws = 4000 ## ## Population-Level Effects: ## Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS ## Intercept 54.12 4.44 45.35 63.01 1.00 3233 2426 ## stopp -40.55 6.27 -53.23 -28.35 1.00 3669 2833 ## stopt -39.42 6.32 -51.81 -27.36 1.00 3259 2577 ## ## Family Specific Parameters: ## Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS ## sigma 16.77 1.82 13.71 20.89 1.00 3141 2785 ## ## Draws were sampled using sample(hmc). For each parameter, Bulk_ESS ## and Tail_ESS are effective sample size measures, and Rhat is the potential ## scale reduction factor on split chains (at convergence, Rhat = 1). ``` --- .f5[ $$ `\begin{align} vot & \sim Gaussian(\mu, \sigma) \\ \mu & \sim \beta_0 + \beta_1 \cdot stop_p + \beta_2 \cdot stop_t \\ \sigma & \sim TruncGaussian(\mu_3, \sigma_3) \end{align}` $$ ] .bg-washed-blue.b--dark-blue.ba.bw2.br3.shadow-5.ph4.mt2[ **For [stop = k]**, `\(stop_p = 0\)` and `\(stop_t = 0\)`: $$ `\begin{align} \mu & = \beta_0 + \beta_1 \cdot stop_p + \beta_2 \cdot stop_t \\ & = \beta_0 + \beta_1 \cdot 0 + \beta_2 \cdot 0 = \beta_0 \end{align}` $$ **For [stop = p]**, `\(stop_p = 1\)` and `\(stop_t = 0\)`: $$ `\begin{align} \mu & = \beta_0 + \beta_1 \cdot stop_p + \beta_2 \cdot stop_t \\ & = \beta_0 + \beta_1 \cdot 1 + \beta_2 \cdot 0 = \beta_0 + \beta_1 \end{align}` $$ **For [stop = t]**, `\(stop_p = 0\)` and `\(stop_t = 1\)`: $$ `\begin{align} \mu & = \beta_0 + \beta_1 \cdot stop_p + \beta_2 \cdot stop_t \\ & = \beta_0 + \beta_1 \cdot 0 + \beta_2 \cdot 1 = \beta_0 + \beta_2 \end{align}` $$ ] --- .f5[ $$ `\begin{align} vot & \sim Gaussian(\mu, \sigma) \\ \mu & \sim \beta_0 + \beta_1 \cdot stop_p + \beta_2 \cdot stop_t \\ \sigma & \sim TruncGaussian(\mu_3, \sigma_3) \end{align}` $$ ] .bg-washed-blue.b--dark-blue.ba.bw2.br3.shadow-5.ph4.mt2[ **For [stop = k]**, `\(stop_p = 0\)` and `\(stop_t = 0\)`: $$ `\begin{align} \mu & = 54.12 + (-40.55) \cdot stop_p + (-39.42) \cdot stop_t \\ & = 54.12 - 40.55 \cdot 0 - 39.42 \cdot 0 = 54.12 \end{align}` $$ **For [stop = p]**, `\(stop_p = 1\)` and `\(stop_t = 0\)`: $$ `\begin{align} \mu & = 54.12 + (-40.55) \cdot stop_p + (-39.42) \cdot stop_t \\ & = 54.12 - 40.55 \cdot 1 - 39.42 \cdot 0 = 54.12 - 40.55 = 13.57 \end{align}` $$ **For [stop = t]**, `\(stop_p = 0\)` and `\(stop_t = 1\)`: $$ `\begin{align} \mu & = 54.12 + (-40.55) \cdot stop_p + (-39.42) \cdot stop_t \\ & = 54.12 - 40.55 \cdot 1 - 39.42 \cdot 1 = 54.12 - 39.42 = 14.7 \end{align}` $$ ] --- .f4[ $$ `\begin{align} vot & \sim Gaussian(\mu, \sigma) \\ \mu & \sim \beta_0 + \beta_1 \cdot stop_p + \beta_2 \cdot stop_t \\ \beta_0 & \sim Gaussian(54.12, 4.44) \\ \beta_1 & \sim Gaussian(-40.55, 6.27) \\ \beta_2 & \sim Gaussian(-39.42, 6.32) \\ \sigma & \sim TruncGaussian(16.77, 1.82) \end{align}` $$ ] .bg-washed-blue.b--dark-blue.ba.bw2.br3.shadow-5.ph4.mt2[ **IMPORTANT** - While `\(\beta_0\)` is the probability distribution of mean VOT when [stop = k] - `\(\beta_1\)` and `\(\beta_2\)` are the probability distributions of the **DIFFERENCE** between mean VOT when [stop = p] and when [stop = k], and when [stop = t] and when [stop = k], respectively. - `\(\beta_1\)` and `\(\beta_2\)` are **NOT** the probability distributions of the mean VOT when [stop = p] and when [stop = t]! ] --- layout: false ## Summary .bg-washed-blue.b--dark-blue.ba.bw2.br3.shadow-5.ph4.mt2[ - **Comparing groups** with `brm()` - `outcome ~ predictor`. - Categorical predictor with 2 and 3 levels. - **Treatment coding** of categorical predictors. - N-1 **dummy variables**, where N is number of levels in the predictor. - Level ordering is *alphabetical* but you can specify your own. - **NOTE**: you don't have to apply treatment coding yourself! It's done under the hood by R. - **Remember** - The **Intercept** `\(\beta_0\)` is the mean of the reference level. - The other `\(\beta\)`'s are the **difference** of the other levels relative to the reference level. ]