Docsity

Assignment 7 - Bayesian Statistics | 22S 138, Assignments of Statistics

Toggle sidebar
bg1
22S:138, Bayesian Statistics
Fall 2008, Homework 7
Due: Mon., 11/03 in class
1 Directed graphs and full conditional distributions
1. The exponential distribution is commonly used to mo del data on time from some
starting point until an event occurs. The probability density function for a random
variable Y drawn from an exponential distribution with parameter λis
p(y|λ) = λ e−λy,0< y < ∞
Researchers wish to compare 5 medications that reduce fever. These medications
are all different formulations of the same drug (capsule, liquid, tablet, etc.). The
experiment involves 30 patients, each with a temperature of at least 102 degrees. Six
patients are randomly assigned to medication 1, six patients to medication 2, etc.
After the patient takes the medication assigned to him, his temperature is monitored
continuously. The outcome variable of interest is the time in hours from when the
medication is taken until the patient’s temperature goes below 99.5 degrees.
Let yij denote this time for patient jwho received medication i.
The researchers will carry out a Bayesian analysis. They assume that all the times
for patients receiving the same medication, say i, follow an exponential distribution
with the same parameter λi. They believe that the λs for different treatments are
different, but they have no idea of which ones will be larger or smaller.
Below is WinBUGS code for fitting a 3-stage hierarchical model to their data.
model {
for (i in 1:N) {
for (j in 1:M) {
Y[i,j] ~ dexp( lambda[i])
}
lambda[i] ~ dgamma( alpha, beta)
}
alpha ~ dgamma( 1,1)
beta ~ dgamma(1,1)
overall <- alpha / beta
}
(a) Draw a directed graph for this model. You may either do this by hand or use
DoodleBUGS or any graphing software that you know.
(b) Deriveexpr essions proportional to the full conditional distributions for lambda[i],
alpha, and beta. If any of them are standard distributions, identify them by
family and parameters. If any of them are not standard distributions, say so.
1
2. Suppose another level were added to the hierarchy as follows:
model {
for (i in 1:N) {
for (j in 1:M) {
Y[i,j] ~ dexp( lambda[i])
}
lambda[i] ~ dgamma( alpha, beta)
}
alpha ~ dgamma( a1, b1)
beta ~ dgamma(a2, b2 )
a1 ~ dexp(2)
b1 ~ dexp(2)
a2 ~ dexp(2)
b2 ~ dexp(2)
overall <- alpha / beta
}
(a) Will the full conditionals for the lambda[i]s change? Why or why not?
(b) Derive expressions proportional to the full conditionals for alpha, beta, a1, and
b1. If possible, identify them as standard distributions.
2 Regression
You will fit a linear regression model to the temperature/heart rate data discussed in class.
This dataset is available in WinBUGS format under “Datasets” on the course web page
as “normtbug.dat.” You may copy it from there into a WinBUGS window. We will con-
sider heart rate the response variable and body temperature the independent or predictor
variable.
See the lab 5 handout for example code for fitting a regression mo del. You will need to
change the variable names in the code to match the variable names in the data (i.e. “heart”
instead of “Y,” etc.).
You will use the noninformative priors from the example code.
1. Fit the model with centering of the predictor variable.
mu[i] <- alpha + beta * (temp[i]-temp.bar)
Run 3 separate 1000-iteration samplers. Use the following initial values. Monitor
alpha, beta, and sigma.
2
pf2

Partial preview of the text

Download Assignment 7 - Bayesian Statistics | 22S 138 and more Assignments Statistics in PDF only on Docsity!

22S:138, Bayesian Statistics

Fall 2008, Homework 7

Due: Mon., 11/03 in class 1

Directed graphs and full conditional distributions

  1. The exponential distribution is commonly used to model data on time from some

starting point until an event occurs. The probability density function for a randomvariable Y drawn from an exponential distribution with parameter

λ

is

p(

y^

|^

λ)

λ e

− λy

,^

< y <

Researchers wish to compare 5 medications that reduce fever.

These medications

are all different formulations of the same drug (capsule, liquid, tablet, etc.).

The

experiment involves 30 patients, each with a temperature of at least 102 degrees. Sixpatients are randomly assigned to medication 1, six patients to medication 2, etc.After the patient takes the medication assigned to him, his temperature is monitoredcontinuously.

The outcome variable of interest is the time in hours from when the

medication is taken until the patient’s temperature goes below 99.5 degrees.Let

y

ij^

denote this time for patient

j

who received medication

i

The researchers will carry out a Bayesian analysis.

They assume that all the times

for patients receiving the same medication, say

i , follow an exponential distribution

with the same parameter

λ

.i

They believe that the

λ

s for different treatments are

different, but they have no idea of which ones will be larger or smaller.Below is WinBUGS code for fitting a 3-stage hierarchical model to their data. model {for (i in 1:N) {

for (j in 1:M) {

Y[i,j] ~ dexp( lambda[i])

lambda[i] ~ dgamma( alpha, beta)

} alpha ~ dgamma( 1,1)beta ~ dgamma(1,1)overall <- alpha / beta}^ (a) Draw a directed graph for this model.

You may either do this by hand or use

DoodleBUGS or any graphing software that you know. (b) Derive expressions proportional to the full conditional distributions for lambda[i],

alpha, and beta.

If any of them are standard distributions, identify them by

family and parameters. If any of them are not standard distributions, say so.

  1. Suppose another level were added to the hierarchy as follows:

model {for (i in 1:N) {

for (j in 1:M) {

Y[i,j] ~ dexp( lambda[i])

lambda[i] ~ dgamma( alpha, beta)

} alpha ~ dgamma( a1, b1)beta ~ dgamma(a2, b2 )a1 ~ dexp(2)b1 ~ dexp(2)a2 ~ dexp(2)b2 ~ dexp(2)overall <- alpha / beta}^ (a) Will the full conditionals for the lambda[i]s change? Why or why not?(b) Derive expressions proportional to the full conditionals for alpha, beta, a1, and

b1. If possible, identify them as standard distributions.

Regression

You will fit a linear regression model to the temperature/heart rate data discussed in class.This dataset is available in WinBUGS format under “Datasets” on the course web pageas “normtbug.dat.” You may copy it from there into a WinBUGS window.

We will con-

sider heart rate the response variable and body temperature the independent or predictorvariable.See the lab 5 handout for example code for fitting a regression model.

You will need to

change the variable names in the code to match the variable names in the data (i.e. “heart”instead of “Y,” etc.).You will use the noninformative priors from the example code.

  1. Fit the model with centering of the predictor variable.

mu[i] <- alpha + beta * (temp[i]-temp.bar) Run 3 separate 1000-iteration samplers.

Use the following initial values.

Monitor

alpha, beta, and sigma.

list(alpha = -100, beta = 5, tau = 1)list(alpha = 0, beta = 2.5, tau = .1)list(alpha = 100, beta = 0, tau = 10)

Look at history plots of all 3 chains together, as well as autocorrelation plots. Alsorun the Gelman and Rubin diagnostic. (The only plot you need to print is the historyplot for

α

Write a paragraph describing the plots and commenting on whether the samplers areconverging satisfactorily.

‱^

How many initial iterations should you throw out in order that the remainingiterations appear to be draws from the target distribution?

  1. Print the summary statistics for the model parameters. Have WinBUGS begin com-

puting them starting at the first iteration that you do not throw out. Use the posteriormeans of

α

and

ÎČ

to hand-calculate the expected value of

heart

when

temp

Recall that the covariate has been centered.

  1. Run the plots in “Inference/Compare.” Comment on whether you see outliers, non-

linearity, or unequal variance, etc.

  1. Prediction:

In the data list, change the last value of “heart” to NA. Then fit the

model again. Run the same number of iterations as you threw out in a previous step.Then start monitoring heart[130] as well as alpha, beta, and sigma.

Obtain a 95%

prediction interval for heart[130].

  1. Informative priors: Suppose you had the following SAS output from a linear regression

fit to a dataset of body temperatures and heart rates measured on a different randomsample of 100 healthy adults. The predictor variable was centered in this analysis.

Model: MODEL

Dependent Variable: heart

Analysis of Variance

Sum of

Mean

Source

DF

Squares

Square

F Value

Pr > F

Model

Error

Corrected Total

Root MSE

R-Square

Dependent Mean

Adj R-Sq

Coeff Var

4.98304^3

The REG Procedure

Model: MODEL

Dependent Variable: heart

Parameter Estimates Parameter

Standard

Variable

DF

Estimate

Error

t Value

Pr > |t|

Intercept

temp

(a) Write one choice of informative prior based on this previous analysis.(b) Would the posterior variance of the regression slope parameter be larger or

smaller if you fit a model using this prior rather than the vague prior previ-ously used? Why? (You do not have to refit the model to answer this question.)