bayesian regression with a categorical predictor
play

Bayesian regression with a categorical predictor Alicia Johnson - PowerPoint PPT Presentation

DataCamp Bayesian Modeling with RJAGS BAYESIAN MODELING WITH RJAGS Bayesian regression with a categorical predictor Alicia Johnson Associate Professor, Macalester College DataCamp Bayesian Modeling with RJAGS Chapter 4 goals Incorporate


  1. DataCamp Bayesian Modeling with RJAGS BAYESIAN MODELING WITH RJAGS Bayesian regression with a categorical predictor Alicia Johnson Associate Professor, Macalester College

  2. DataCamp Bayesian Modeling with RJAGS Chapter 4 goals Incorporate categorical predictors into Bayesian models Engineer multivariate Bayesian regression models Extend our methodology for Normal regression models to generalized linear models: Poisson regression

  3. DataCamp Bayesian Modeling with RJAGS Rail-trail volume Goal: Explore daily volume on a rail-trail in Massachusetts. [1] Photo courtesy commons.wikimedia.org

  4. DataCamp Bayesian Modeling with RJAGS Modeling volume Y = trail volume (# of users) on day i i Model 2 Y ∼ N ( m , s ) i i

  5. DataCamp Bayesian Modeling with RJAGS Modeling volume by weekday Y = trail volume (# of users) on day i i X = 1 for weekdays, 0 for weekends i Model 2 Y ∼ N ( m , s ) i i

  6. DataCamp Bayesian Modeling with RJAGS Modeling volume by weekday Y = trail volume (# of users) on day i i X = 1 for weekdays, 0 for weekends i Model 2 Y ∼ N ( m , s ) i i

  7. DataCamp Bayesian Modeling with RJAGS Modeling volume by weekday Y = trail volume (# of users) on day i i X = 1 for weekdays, 0 for weekends i Model 2 Y ∼ N ( m , s ) i i m = a + bX i i

  8. DataCamp Bayesian Modeling with RJAGS Modeling volume by weekday Y = trail volume (# of users) on day i i X = 1 for weekdays, 0 for weekends i Model 2 Y ∼ N ( m , s ) i i m = a + bX i i a = typical weekend volume

  9. DataCamp Bayesian Modeling with RJAGS Modeling volume by weekday Y = trail volume (# of users) on day i i X = 1 for weekdays, 0 for weekends i Model 2 Y ∼ N ( m , s ) i i m = a + bX i i a = typical weekend volume a + b = typical weekday volume b = contrast between typical weekday vs weekend volume s = residual standard deviation

  10. DataCamp Bayesian Modeling with RJAGS Priors for a & b Typical weekend volume is most likely We lack certainty about how weekday around 400 users per day, but possibly volume compares to weekend volume. It as low as 100 or as high as 700 users. could be more, it could be less.

  11. DataCamp Bayesian Modeling with RJAGS Prior for s The standard deviation in volume from day to day (whether on weekdays or weekends) is equally likely to be anywhere between 0 and 200 users.

  12. DataCamp Bayesian Modeling with RJAGS Bayesian model of volume by weekday status 2 Y ∼ N ( m , s ) i i m = a + bX i i 2 a ∼ N (400,100 ) 2 b ∼ N (0,200 ) s ∼ Unif (0,200)

  13. DataCamp Bayesian Modeling with RJAGS DEFINE the Bayesian model in RJAGS rail_model_1 <- "model{ 2 Y ∼ N ( m , s ) # Likelihood model for Y[i] i i m = a + bX i i 2 a ∼ N (400,100 ) 2 b ∼ N (0,200 ) # Prior models for a, b, s s ∼ Unif (0,200) }"

  14. DataCamp Bayesian Modeling with RJAGS DEFINE the Bayesian model in RJAGS rail_model_1 <- "model{ 2 Y ∼ N ( m , s ) # Likelihood model for Y[i] i i for(i in 1:length(Y)) { m = a + bX Y[i] ~ dnorm(m[i], s^(-2)) i i 2 a ∼ N (400,100 ) } 2 b ∼ N (0,200 ) # Prior models for a, b, s s ∼ Unif (0,200) a ~ dnorm(400, 100^(-2)) s ~ dunif(0, 200) }"

  15. DataCamp Bayesian Modeling with RJAGS DEFINE the Bayesian model in RJAGS rail_model_1 <- "model{ # Likelihood model for Y[i] m[i] <- a + b[X[i]] for(i in 1:length(Y)) { Y[i] ~ dnorm(m[i], s^(-2)) m[i] <- a + b[X[i]] X[1] = weekend, X[2] = weekday } # Prior models for a, b, s b has 2 levels: b[1] , b[2] a ~ dnorm(400, 100^(-2)) s ~ dunif(0, 200) weekend trend ( m = a ) i }" m[i] <- a + b[1]

  16. DataCamp Bayesian Modeling with RJAGS DEFINE the Bayesian model in RJAGS rail_model_1 <- "model{ # Likelihood model for Y[i] m[i] <- a + b[X[i]] for(i in 1:length(Y)) { Y[i] ~ dnorm(m[i], s^(-2)) m[i] <- a + b[X[i]] X[1] = weekend, X[2] = weekday } # Prior models for a, b, s b has 2 levels: b[1] , b[2] a ~ dnorm(400, 100^(-2)) s ~ dunif(0, 200) weekend trend ( m = a ) b[1] <- 0 i }" m[i] <- a + b[1] b[1] <- 0

  17. DataCamp Bayesian Modeling with RJAGS DEFINE the Bayesian model in RJAGS rail_model_1 <- "model{ # Likelihood model for Y[i] m[i] <- a + b[X[i]] for(i in 1:length(Y)) { Y[i] ~ dnorm(m[i], s^(-2)) m[i] <- a + b[X[i]] X[1] = weekend, X[2] = weekday } # Prior models for a, b, s b has 2 levels: b[1] , b[2] a ~ dnorm(400, 100^(-2)) s ~ dunif(0, 200) weekend trend ( m = a ) b[1] <- 0 i b[2] ~ dnorm(0, 200^(-2)) }" m[i] <- a + b[1] b[1] <- 0 weekday trend ( m = a + b ) i m[i] <- a + b[2] b[2] ~ dnorm(0, 200^(-2))

  18. DataCamp Bayesian Modeling with RJAGS BAYESIAN MODELING WITH RJAGS Let's practice!

  19. DataCamp Bayesian Modeling with RJAGS BAYESIAN MODELING WITH RJAGS Multivariate Bayesian regression Alicia Johnson Associate Professor, Macalester College

  20. DataCamp Bayesian Modeling with RJAGS Modeling volume Y = trail volume (# of users) on day i i [1] Photo courtesy commons.wikimedia.org

  21. DataCamp Bayesian Modeling with RJAGS Modeling volume by weekday Y = trail volume (# of users) on day i i X = 1 for weekdays, 0 for weekends i

  22. DataCamp Bayesian Modeling with RJAGS Modeling volume by temperature Y = trail volume (# of users) on day i i ∘ Z = high temperature on day i (in F) i

  23. DataCamp Bayesian Modeling with RJAGS Modeling volume by temperature & weekday Y = trail volume (# of users) on day i i X = 1 for weekdays, 0 for weekends i ∘ Z = high temperature on day i (in F) i 2 Y ∼ N ( m , s ) i i m = a + bX + cZ i i i Weekends: m = a + cZ i i Weekdays: m = ( a + b ) + cZ i i

  24. DataCamp Bayesian Modeling with RJAGS Modeling volume by temperature & weekday Y = trail volume (# of users) on day i i X = 1 for weekdays, 0 for weekends i ∘ Z = high temperature on day i (in F) i 2 Y ∼ N ( m , s ) i i m = a + bX + cZ i i i Weekends: m = a + cZ i i Weekdays: m = ( a + b ) + cZ i i

  25. DataCamp Bayesian Modeling with RJAGS Modeling volume by temperature & weekday m = a + bX + cZ i i i Weekends: m = a + cZ i i Weekdays: m = ( a + b ) + cZ i i a = weekend y-intercept a + b = weekday y-intercept b = contrast between weekday vs weekend y-intercepts c = common slope s = residual standard deviation

  26. DataCamp Bayesian Modeling with RJAGS Priors for a and b We lack certainty about the y-intercept We lack certainty about how typical for the relationship between temperature volume compares on weekdays vs & weekend volume. weekends of similar temperature.

  27. DataCamp Bayesian Modeling with RJAGS Priors for c and s Whether on weekdays or weekends, we The typical deviation from the trend is lack certainty about the association equally likely to be anywhere between 0 between trail volume & temperature. and 200 users.

  28. DataCamp Bayesian Modeling with RJAGS Bayesian model of volume by weekday status 2 Y ∼ N ( m , s ) i i m = a + bX + cZ i i i 2 a ∼ N (0,200 ) 2 b ∼ N (0,200 ) 2 c ∼ N (0,20 ) s ∼ Unif (0,200)

  29. DataCamp Bayesian Modeling with RJAGS DEFINE the Bayesian model in RJAGS rail_model_2 <- "model{ 2 Y ∼ N ( m , s ) # Likelihood model for Y[i] i i for(i in 1:length(Y)) { m = a + bX + cZ Y[i] ~ dnorm(m[i], s^(-2)) i i i m[i] <- a + b[X[i]] + c * Z[i] 2 a ∼ N (0,200 ) } 2 b ∼ N (0,200 ) # Prior models for a, b, c, s 2 c ∼ N (0,20 ) a ~ dnorm(0, 200^(-2)) b[1] <- 0 s ∼ Unif (0,200) b[2] ~ dnorm(0, 200^(-2)) c ~ dnorm(0, 20^(-2)) s ~ dunif(0, 200) }"

  30. DataCamp Bayesian Modeling with RJAGS BAYESIAN MODELING WITH RJAGS Let's practice!

  31. DataCamp Bayesian Modeling with RJAGS BAYESIAN MODELING WITH RJAGS Poisson regression Alicia Johnson Associate Professor, Macalester College

  32. DataCamp Bayesian Modeling with RJAGS Normal likelihood structure Y = volume (# of users) on a given day 2 Y ∼ N ( m , s ) Technically... The Normal model assumes Y has a continuous scale and can be negative. But Y is a discrete count and cannot be negative.

  33. DataCamp Bayesian Modeling with RJAGS The Poisson model Y = volume (# of users) on a given day Y ∼ Pois( l ) Y is the # of independent events that occur in a fixed interval (0, 1, 2,...). Rate parameter l represents the typical # of events per time interval ( l > 0 ).

  34. DataCamp Bayesian Modeling with RJAGS The Poisson model Y = volume (# of users) on a given day Y ∼ Pois( l ) Y is the # of independent events that occur in a fixed interval (0, 1, 2,...). Rate parameter l represents the typical # of events per time interval ( l > 0 ).

  35. DataCamp Bayesian Modeling with RJAGS The Poisson model Y = volume (# of users) on a given day Y ∼ Pois( l ) Y is the # of independent events that occur in a fixed interval (0, 1, 2,...). Rate parameter l represents the typical # of events per time interval ( l > 0 ).

  36. DataCamp Bayesian Modeling with RJAGS The Poisson model Y = volume (# of users) on a given day Y ∼ Pois( l ) Y is the # of independent events that occur in a fixed interval (0, 1, 2,...). Rate parameter l represents the typical # of events per time interval ( l > 0 ).

  37. DataCamp Bayesian Modeling with RJAGS Poisson regression Y ∼ Pois( l ) where l > 0 i i i

  38. DataCamp Bayesian Modeling with RJAGS Poisson regression Y ∼ Pois( l ) where l > 0 i i i l = a + bX + cZ i i i

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend