CommencerCommencer gratuitement

Regression priors

Let \(Y\)i be the weight (in kg) of subject \(i\). Past studies have shown that weight is linearly related to height \(X\)i (in cm). The average weight \(m\)i among adults of any shared height \(X\)i can be written as \(m\)i \(= a + b X\)i. But height isn't a perfect predictor of weight - individuals vary from the trend. To this end, it's reasonable to assume that \(Y\)i are Normally distributed around \(m\)i with residual standard deviation \(s\): \(Y\)i \(\sim N(m\)i, \(s^2)\).

Note the 3 parameters in the model of weight by height: intercept \(a\), slope \(b\), & standard deviation \(s\). In the first step of your Bayesian analysis, you will simulate the following prior models for these parameters: \(a \sim N(0, 200^2)\), \(b \sim N(1, 0.5^2)\), and \(s \sim Unif(0, 20)\).

Cet exercice fait partie du cours

Bayesian Modeling with RJAGS

Afficher le cours

Instructions

  • Sample 10,000 draws from each of the \(a\), \(b\), and \(s\) priors. Assign the output to a, b, and s. These are subsequently combined in the samples data frame along with set = 1:10000, an indicator of the draw numbers.
  • Construct separate density plots of each of the a, b, and s samples.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Take 10000 samples from the a, b, & s priors
a <- ___
b <- ___
s <- ___

# Store samples in a data frame
samples <- data.frame(set = 1:10000, a, b, s)

# Construct density plots of the prior samples    
ggplot(___, aes(x = ___)) + 
    ___()
ggplot(___, aes(x = ___)) + 
    ___()
ggplot(___, aes(x = ___)) + 
    ___()
Modifier et exécuter le code