Reader small image

You're reading from  The Statistics and Machine Learning with R Workshop

Product typeBook
Published inOct 2023
Reading LevelIntermediate
PublisherPackt
ISBN-139781803240305
Edition1st Edition
Languages
Right arrow
Author (1)
Liu Peng
Liu Peng
author image
Liu Peng

Peng Liu is an Assistant Professor of Quantitative Finance (Practice) at Singapore Management University and an adjunct researcher at the National University of Singapore. He holds a Ph.D. in statistics from the National University of Singapore and has ten years of working experience as a data scientist across the banking, technology, and hospitality industries.
Read more about Liu Peng

Right arrow

Bayesian linear regression with a categorical variable

When the predictor is categorical, such as a binary feature, we would set one parameter for each corresponding category. The following exercise demonstrates such an example.

Exercise 14.5 – Performing Bayesian inference with a categorical variable

In this exercise, we will examine the relationship between am (automatic or manual transmission, a categorical variable) and mpg (miles per gallon, a continuous variable). We will define the mean of the normal likelihood for mpg as a function of am, with a different mean mu[i] for each level of am. We’ll also give mu a normal prior and standard deviation s a uniform prior. Follow the next steps:

  1. Specify the aforementioned model architecture, as follows:
    # define the model
    model = "model{
        # Define model for data Y[i]
        for(i in 1:length(Y)) {
          Y[i] ~ dnorm(mu[am[i]+1], s^(-2...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
The Statistics and Machine Learning with R Workshop
Published in: Oct 2023Publisher: PacktISBN-13: 9781803240305

Author (1)

author image
Liu Peng

Peng Liu is an Assistant Professor of Quantitative Finance (Practice) at Singapore Management University and an adjunct researcher at the National University of Singapore. He holds a Ph.D. in statistics from the National University of Singapore and has ten years of working experience as a data scientist across the banking, technology, and hospitality industries.
Read more about Liu Peng