开始使用免费开始使用

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)\).

本练习是课程的一部分

Bayesian Modeling with RJAGS

查看课程

练习说明

  • 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.

交互式实操练习

通过完成这段示例代码来试试这个练习。

# 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 = ___)) + 
    ___()
编辑并运行代码