Sei sulla pagina 1di 21

Question 1

Study of the relationship of temperature on the growth process of a certain type of tissue.
Using the same parent batch, the scientist cultured 5 different cell lines for 4 different
temperatures (for a total of 20 different lines). The total number of cells sampled for the
different temperatures are given:

Table 1 Cell Data


Temp=40 Temp=60 Temp=80 Temp=100
1.13 1.75 2.30 3.18
1.20 1.45 2.15 3.10
1.00 1.55 2.25 3.28
0.91 1.64 2.40 3.35
1.05 1.60 2.49 3.12
1 = 1.058 2 = 1.598 3 = 2.318
4 = 3.206
n1 = 5 n2 = 5 n3 = 5 n4 = 5

The model follows,


Yij| i, ~ Normal( i, ), i| 0, 0 ~ Normal( 0, 0), 0 ~ Normal(0, 12), ~G(1, 12), and
0~G(1,12).
(a) Find the distribution of:

i. f( i|DATA, 0, , 0) ~ Normal(0 , 0 ) where i = 1, 2, 3, 4
0 0 + 1 1 0 0 +5(1.058) 0 0 +5.29
Temp = 40 : 01 = = =
0 + 1 0 +5 0 +5

01 = 0 + n1 = 0 + 5
0 0 +5.29
Thus, f( 1|DATA, 0, , 0) ~ Normal( , 0 + 5).
0 +5

0 0 + 2 2 0 0 +5(1.598) 0 0 +7.99
Temp = 60: 02 = = =
0 + 2 0 +5 0 +5

02 = 0 + n2 = 0 + 5
0 0 +7.99
Thus, f( 2|DATA, 0, , 0) ~ Normal( , 0 + 5).
0 +5

0 0 + 3 3 0 0 +5(2.318) 0 0 +11.59
Temp = 80: 03 = = =
0 + 3 0 +5 0 +5

03 = 0 + n3 = 0 + 5
0 0 +11.59
Thus, f( 3|DATA, 0, , 0) ~ Normal( , 0 + 5).
0 +5

0 0 + 4 4 0 0 +5(3.206) 0 0 +16.03
Temp = 100: 04 = = =
0 + 4 0 +5 0 +5

1|Page

04 = 0 + n4 = 0 + 5
0 0 +16.03
Thus, f( 4|DATA, 0, , 0) ~ Normal( , 0 + 5).
0 +5


ii. f( 0|DATA, 1,, 4, , 0) ~ Normal(00 , 00 )

+ 00 00
40 . +(1)(0)
40 .
4 .
00 = = = 4 0+1
40 + 00 40 +1 0
1+ 2+ 3+ 4
where .
= 4

00 = 40 + 00 = 40 + 1

4 .
Thus, f( 0|DATA, 1,, 4, , 0) ~ Normal(4 0+1, 40 + 1).
0

iii. f(|DATA, 1,, 4, 0, 0) ~ Gamma ( , )

= + (n1 + n2 + n3 + n4)/2 = 1 + 10 = 11

= + 0.5[ 4=1 5=1(ij i)2] = 1 + 0.5[ 4=1 5=1(ij i)2]

Thus, f(|DATA, 1,, 4, 0, 0) ~ Gamma (11, 1 + 0.5[ 4=1 5=1(ij i)2])

iv. f(0|DATA, 1,, 4, 0, ) ~ Gamma(0 , 0)

0 = 0 + 4/2 = 1 + 2 = 3
0 = 0 + 0.5[4=1( - 0 )2] = 1 + 0.5[4=1( - 0 )2]
Thus, f(0|DATA, 1,, 4, 0, ) ~ Gamma(3, 1 + 0.5[4=1( - 0 )2]).

(b) Using R to run a Markov chain Monte Carlo algorithm.


# prior
mu00=0; tau00=1; alpha=1; beta=1;alpha0=1; beta0=1

# data
temp40 = c(1.13, 1.20, 1.00, 0.91, 1.05)
xbar1 = mean(temp40)
n1 = length(temp40)
temp60 = c(1.75, 1.45, 1.55, 1.64, 1.60)
xbar2 = mean(temp60)
n2 = length(temp60)
temp80 = c(2.30, 2.15, 2.25, 2.40, 2.49)
xbar3 = mean(temp80)
n3 = length(temp80)
temp100 = c(3.18, 3.10, 3.28, 3.35, 3.12)
xbar4 = mean(temp100)
n4 = length(temp100)

2|Page
nbig = 20000
n=4

# starting values
mu1Start = 1; mu2Start = 1; mu3Start = 1; mu4Start = 1
tauStart = 0.0025; mu0Start = 0.0025; tau0Start = 0.0025

# MCMC parameters
set.seed(333); # The purpose of set.seed is to get the same random values

if(T){ # set to true to rerun the MCMC


# Initialize chain
mu1 = rep(0,nbig); mu2 = rep(0, nbig); mu3 = rep(0, nbig); mu4 = rep(0, nbig);
mu01p = rep(0,nbig); mu02p = rep(0,nbig); mu03p = rep(0,nbig); mu04p = rep(0,nbig);
tau01p = rep(0,nbig); tau02p = rep(0,nbig); tau03p = rep(0,nbig); tau04p = rep(0,nbig);
mu00p = rep(0,nbig); tau00p = rep(0, nbig); betap = rep(0, nbig); beta0p = rep(0, nbig);
tau = rep(0, nbig); mu0= rep(0, nbig); tau0= rep(0, nbig);

mu1[1] = mu1Start; mu2[1] = mu2Start; mu3[1] = mu3Start; mu4[1] = mu4Start; tau[1] = tauSt
art;
mu0[1] = mu0Start; tau0[1] = tau0Start;

alphap = alpha+(n1+n2+n3+n4)/2 # does not change in loop


alpha0p = alpha0 +4/2 # does not change in loop

for(i in 2:nbig){
# sample mu1
mu01p[i] = (tau0[i-1]*mu0[i-1]+n*tau[i-1]*xbar1)/(tau0[i-1]+n*tau[i-1])
tau01p[i] = tau0[i-1]+n*tau[i-1]
mu1[i] = rnorm(1,mu01p[i],1/sqrt(tau01p[i]))

# sample mu2
mu02p[i] = (tau0[i-1]*mu0[i-1]+n*tau[i-1]*xbar2)/(tau0[i-1]+n*tau[i-1])
tau02p[i] = tau0[i-1]+n*tau[i-1]
mu2[i] = rnorm(1,mu02p[i],1/sqrt(tau02p[i]))

# sample mu3
mu03p[i] = (tau0[i-1]*mu0[i-1]+n*tau[i-1]*xbar3)/(tau0[i-1]+n*tau[i-1])
tau03p[i] = tau0[i-1]+n*tau[i-1]
mu3[i] = rnorm(1,mu03p[i],1/sqrt(tau03p[i]))

# sample mu4
mu04p[i] = (tau0[i-1]*mu0[i-1]+n*tau[i-1]*xbar4)/(tau0[i-1]+n*tau[i-1])
tau04p[i] = tau0[i-1]+n*tau[i-1]

3|Page
mu4[i] = rnorm(1,mu04p[i],1/sqrt(tau04p[i]))

# sample m0
mu00p[i] = (tau0[i-1]*(mu1[i-1]+mu2[i-1]+mu3[i-1]+mu4[i-1]))/(n*tau0[i-1]+1)
tau00p[i] = 4*tau0[i-1]+1
mu0[i] = rnorm(1,mu00p[i],1/sqrt(tau00p[i]))

# sample tau
betap[i] = beta+0.5*(sum((temp40-mu1[i])^2+(temp60-mu2[i])^2+(temp80-mu3[i])^2+(temp
100-mu4[i])^2))
tau[i] = rgamma(1,alphap,betap[i])

# sample tau0
beta0p[i] = 1+0.5*(sum((mu1[i]-mu0[i])^2+(mu2[i]-mu0[i])^2+(mu3[i]-mu0[i])^2+(mu4[i]-mu
0[i])^2))
tau0[i] = rgamma(1,3,beta0p[i])
}
}

# the following command will give the first 10 values:


cbind(mu1, mu2, mu3, mu4, mu0, tau,tau0)[1:10,]

## mu1 mu2 mu3 mu4 mu0 tau


## [1,] 1.0000000 1.0000000 1.000000 1.000000 0.0025000 0.002500000
## [2,] 0.1062102 18.5832129 -16.492394 5.049473 -1.5084866 0.005962779
## [3,] 7.7139323 6.7401932 -4.940595 -6.156955 -0.5419304 0.013593709
## [4,] 0.5932994 0.5908909 1.248855 -2.522899 -0.3071691 0.184906374
## [5,] 0.5142620 0.7009481 2.023195 3.212813 1.0850088 2.913163018
## [6,] 0.7496282 1.5198452 2.369583 2.576578 0.8417414 7.938986796
## [7,] 1.0149135 1.6454840 2.020313 3.147220 2.1895470 8.066600881
## [8,] 0.8203745 1.5660732 2.036913 3.069471 1.1085778 4.636894573
## [9,] 0.7765211 1.8821687 2.492433 3.120126 2.5617376 4.643923286
## [10,] 1.3126615 1.2982892 1.878328 3.511026 0.8540948 3.236078739
## tau0
## [1,] 0.002500000
## [2,] 0.009527133
## [3,] 0.015714854
## [4,] 0.412272483
## [5,] 1.017200294
## [6,] 0.362394659
## [7,] 0.891210932
## [8,] 0.663611565
## [9,] 0.917757397
## [10,] 0.181112992

4|Page
(c) Give the posterior distribution a plot for the mean of each temperature effect as well as
some of the summary statistics of these posterior distributions for the drug effect means.

Table 2 Summary Statistics of the Posterior Distributions


Mean Median Standard Deviation 95% Credible Region
1 1.08 1.079 0.19717 (0.7036, 1.46287)
2 1.6 1.598 0.227 (1.224, 1.9746)
3 2.294 2.298 0.23866 (1.90575, 2.66444)
4 3.149 3.153 0.2087 (2.7562, 3.5194)

From the above results, we see that posterior distributions mean and median increase or shift
to the right in the graph on the x-axis as we move to a higher temperature group.

# Posterior Distribution for the mean of each temperature effect and some summary statistics
par(mfrow=c(2,2))
# mu1: first five observations deleted due to large deviations from the rest
plot(density(mu1[-(1:5)]), main ="Posterior Distribution for the mean of Temperature 40", xlab
= "mu1", ylab="Density")
# mu2: first five observations deleted due to large deviations from the rest
plot(density(mu2[-(1:5)]), main ="Posterior Distribution for the mean of Temperature 60", xlab

5|Page
= "mu2", ylab="Density")
# mu3: Deleting first four observations due to large deviations from the rest
plot(density(mu3[-(1:4)]),main ="Posterior Distribution for the mean of Temperature 80", xlab
= "mu3", ylab="Density")
# mu4: Deleting first three observations due to large deviations from the rest
plot(density(mu4[-(1:4)]),main ="Posterior Distribution for the mean of Temperature 100", xlab
= "mu4", ylab="Density")

# Summary stats of these posterior distributions for the drug effect means
# for mu1
summary(mu1); sd(mu1); quantile(mu1, probs=c(0.025, 0.975))

## Min. 1st Qu. Median Mean 3rd Qu. Max.


## 0.1062 0.9551 1.0790 1.0800 1.2020 7.7140

## [1] 0.19717

## 2.5% 97.5%
## 0.7036332 1.4628687

# for mu2
summary(mu2); sd(mu2); quantile(mu2, probs=c(0.025, 0.975))

## Min. 1st Qu. Median Mean 3rd Qu. Max.


## 0.5909 1.4760 1.5980 1.6000 1.7220 18.5800

## [1] 0.2273515

## 2.5% 97.5%
## 1.224242 1.974582

# for mu3
summary(mu3); sd(mu3); quantile(mu3, probs=c(0.025, 0.975))

## Min. 1st Qu. Median Mean 3rd Qu. Max.


## -16.490 2.171 2.298 2.294 2.421 3.355

## [1] 0.2386573

## 2.5% 97.5%
## 1.905754 2.664438

# for mu4
summary(mu4); sd(mu4); quantile(mu4, probs=c(0.025, 0.975))

## Min. 1st Qu. Median Mean 3rd Qu. Max.


## -6.157 3.028 3.153 3.149 3.275 5.049

6|Page
## [1] 0.2087397

## 2.5% 97.5%
## 2.756194 3.519406

(d) Define 13 = 1 - 3 as a random variable for the difference in the number of cells grown at a
temperature of 40 and temperature 80. Then posterior distribution of the random variable
() () ()
can be estimated from the sample values: 13 = 1 - 3 .

Graphical Representation

As we can see that the posterior distribution for the mean of temperature 80 is on the right
side of the posterior distribution for the mean of temperature 40, so we are expecting to see
some negative values for the posterior distribution of the difference.
As expected, we have the following summary statistics for 13:

Table 3 Summary Statistics of 13


Mean Median Standard Deviation 95% Credible Region
13 -1.214 -1.219 0.31446 (-1.745, -0.66246)

# Posterior distribution of the difference in number of cells grown at a temperature of 40 vs 80


delta13 = rep(0, nbig)
for(i in 1:nbig){
# sample posterior distribution of the difference mu13
delta13[i] = mu1[i] - mu3[i]
}
7|Page
# summary statistics for the sample posterior distribution of the difference mu13
summary(delta13); sd(delta13); quantile(delta13, probs=c(0.025, 0.975))

## Min. 1st Qu. Median Mean 3rd Qu. Max.


## -2.557 -1.389 -1.219 -1.214 -1.040 16.600

## [1] 0.3144575

## 2.5% 97.5%
## -1.7451204 -0.6624642

The following code is for the posterior probability that there will be more cells grown at a
temperature 40 versus 80 or find P(1 > 3 ):
# Posterior probability that there will be more cells grown at a temperature of 40 versus 80.
y40 = rep(0,nbig)
y80 = rep(0,nbig)
diff = rep(0, nbig)
for(i in 1:nbig){
y40[i] = rnorm(1,mu1[i],1/sqrt(tau[i]))
y80[i] = rnorm(1,mu3[i],1/sqrt(tau[i]))
diff[i] = y40[i] - y80[i]
if(diff[i]>0){diff[i]=1}else{diff[i]=0}
}
postprob = sum(diff)/length(diff)
postprob

## [1] 0.02375

As we see, the posterior probability that there will be more cells grown at a temperature of 40
than at temperature 80 is P(1 > 3 ) = 0.02375. The complement of this probability is 0.97625.
This implies there is a higher posterior probability that there will be more cells grown at a
temperature of 80.

8|Page
Question 2

The Bayesian Poisson Regression:

model{
for(i in 1:30)
{
NumDown[i]~dpois(lam[i])
log(lam[i]) <- log(NumLivBir[i]) +b0 + beta.a[AgeCat[i]] + beta.b[BirOrd[i]] + b[i]
b[i] ~ dnorm(0, tau)
b.adj[i] <-b[i]-mean(b[])
}
tau~dgamma(0.001,0.001)
b0~dnorm(0,.001)
b0.adj <- b0+mean(beta.a[])+mean(beta.b[])

for(ia in 1:6){
beta.a[ia]~dnorm(mu.a,tau.a)
beta.a.adj[ia] <-beta.a[ia]-mean(beta.a[])
}
mu.a~dnorm(0,.001)
tau.a ~dgamma(0.001, 0.001)

for(ib in 1:5){
beta.b[ib]~dnorm(mu.b,tau.b)
beta.b.adj[ib] <-beta.b[ib]-mean(beta.b[])
}
mu.b~dnorm(0,.001)
tau.b ~dgamma(0.001, 0.001)
sigma.a <-1/sqrt(tau.a)
sigma.b <-1/sqrt(tau.b)
diff.a.adj <- exp(beta.a.adj[6] - beta.a.adj[2])
diff.b.adj <- exp(beta.b.adj[1] - beta.b.adj[5])
}

list(AgeCat = c(1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6),


BirOrd = c(1, 2, 3, 4, 5, 1, 2, 3, 4, 5 ,1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5),
NumDown = c( 107, 25, 3, 1, 0, 141, 150, 71, 26, 8, 60, 110, 114, 64, 63, 40, 84, 103, 89,
112, 39, 82, 108, 137, 262, 25, 39, 75, 96, 295),
NumLivBir = c(230061, 72202, 15050, 2293, 327, 329449, 326701, 175702, 68800,
30666, 114920, 208667, 207081, 132434, 123419, 39487, 83228, 117300, 98301, 149919,
14208, 28466, 45026, 46075, 104088, 3052, 5375, 8660, 9834, 34392))

9|Page
list(tau = 1, b = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1,1, 1, 1, 1, 1, 1, 1,1,1,1,1,1,1,1), b0 = 0,
beta.a = c(5, 5, 5, 5, 5, 5), beta.b = c(3, 3, 3, 3, 3), mu.a = 1, mu.b = 1, tau.a =1, tau.b = 1)

list(tau = 0.5, b = c(10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10), b0 = 1, beta.a = c(2, 2, 2, 2, 2, 2), beta.b = c(5, 5, 5, 5,
5), mu.a = 0.5, mu.b = 0.5, tau.a =0.5, tau.b = 0.5)

list(tau = 0.5, b = c(5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5),


b0 = 0.5, beta.a = c(1, 1, 1, 1, 1, 1), beta.b = c(4, 4, 4, 4, 4), mu.a = 2, mu.b = 2, tau.a = 2, tau.b
= 2)

Below are the b0, beta.a, beta.b, the adjusted version, and the precisions in the model:

mean sd MC_error val2.5pc median val97.5pc start sample


b0 2.767 4.095 0.1739 -3.279 2.088 11.33 10000 102003
b0.adj -6.805 0.02581 1.079E-4 -6.857 -6.804 -6.755 10000 102003
beta.a[1] 7.587 3.323 0.1456 0.8265 7.462 12.85 10000 90003
beta.a[2] 7.602 3.322 0.1455 0.8475 7.474 12.87 10000 90003
beta.a[3] 7.823 3.322 0.1456 1.065 7.696 13.09 10000 90003
beta.a[4] 8.353 3.322 0.1456 1.592 8.225 13.62 10000 90003
beta.a[5] 9.458 3.322 0.1456 2.699 9.333 14.73 10000 90003
beta.a[6] 10.64 3.323 0.1456 3.878 10.52 15.9 10000 90003
beta.a.adj[1]-0.9896 0.08493 3.935E-4 -1.16 -0.988 -0.8278 10000 90003
beta.a.adj[2]-0.9751 0.05462 2.616E-4 -1.083 -0.975 -0.8689 10000 90003
beta.a.adj[3]-0.7543 0.05244 2.247E-4 -0.8575 -0.7545 -0.651 10000 90003
beta.a.adj[4]-0.2243 0.05238 2.402E-4 -0.3266 -0.2244 -0.1207 10000 90003
beta.a.adj[5]0.8809 0.0481 2.318E-4 0.7872 0.8807 0.9764 10000 90003
beta.a.adj[6]2.062 0.05172 2.519E-4 1.96 2.062 2.163 10000 90003
beta.b[1] -17.95 2.034 0.08914 -21.49 -18.31 -14.32 10000 90003
beta.b[2] -17.96 2.034 0.08915 -21.5 -18.32 -14.32 10000 90003
beta.b[3] -17.99 2.033 0.08913 -21.53 -18.35 -14.36 10000 90003
beta.b[4] -17.96 2.034 0.08915 -21.49 -18.32 -14.33 10000 90003
beta.b[5] -18.02 2.033 0.08912 -21.55 -18.37 -14.39 10000 90003
beta.b.adj[1]0.02302 0.0381 1.881E-4 -0.04627 0.02002 0.1058 10000 90003
beta.b.adj[2]0.01612 0.03394 1.582E-4 -0.04857 0.01458 0.08703 10000 90003
beta.b.adj[3]-0.01661 0.03424 1.651E-4 -0.08937 -0.01483 0.04753 10000 90003
beta.b.adj[4]0.01863 0.03548 1.663E-4 -0.04861 0.01708 0.09387 10000 90003
beta.b.adj[5]-0.04117 0.03701 2.407E-4 -0.1218 -0.03785 0.02276 10000 90003
tau 809.1 802.5 54.98 97.09 556.4 3021.0 42001 3000
tau.a 0.6651 0.4209 0.005255 0.1079 0.5787 1.692 40001 9000
tau.b 575.6 610.2 11.71 38.6 376.6 2270.0 40001 9000
sigma.a 1.456 0.6064 0.01295 0.778 1.315 3.073 43001 3000
sigma.b 0.06437 0.0409 0.001454 0.0216 0.05341 0.1756 43001 3000

10 | P a g e
(b) Trace Plots of the adjusted b0, beta.a, beta.b, and the precisions of based on three chains

11 | P a g e
Autocor Plots of the adjusted b0, beta.a, beta.b, and the precisions based on three chains

12 | P a g e
The trace plots show that the samples quickly cycle through the main probability mass after 10,
000 interations, and this indicates that we are running enough samples to be close to the
posterior distribution (except for tau.a, and tau.b). The autocorrelation plots also show that the
autocorrelation quickly fall to zero, and this gives some evidence that the sample chain is
quickly mixing (except for tau.a and tau.b, which fluctuate more). Thus, these are the evidence
that the model has converged and I have burned in my simulation enough.

13 | P a g e
(c)
mean sd MC_error val2.5pc median val97.5pc start sample
diff.a.adj 20.95 1.708 0.01216 17.81 20.88 24.52 44001 48000
diff.b.adj 1.069 0.06813 3.851E-4 0.9578 1.06 1.224 10000 110103

The probability of a child being born with Down Syndrome to a mother of 40+ is 20.95 times the
probability of a child being born with Down Syndrome to a 20-24-year-old mother. The 95%
confidence interval is (17.81, 24.52). The probability of a child being born with Down Syndrome
as the first child is 1.069 times the probability of a child being born with Down Syndrome as the
5th or later child. The 95% confidence interval is (0.8224, 1.033).
Question 3
Define the Growth Curve Model:
Yij| 0i, 1i, xj ~ Normal(0i + 1i*Weekj, )
0i|0i, 0i ~ Normal(0i, 0i)
1i|1i, 1i ~ Normal(1i, 1i)
00 ~ Normal(0, 0.0001)
01 ~ Normal(0, 0.0001)
10 ~ Normal(0, 0.0001)
11 ~ Normal(0, 0.0001)
~ Gamma(a, b)
where, 0i = E[0i] = 00 + 01*DoseLevel and 1i = E[1i] = 10 + 11*DoseLevel. The Dose Level
is defined as 0, 0.5, 1, 4, and 8. 0i, 1i and are noninformative prior distributions.
(a) The following is the code for the model, and some data points are omitted.

model
{
for( i in 1 : 50 ) {
for( j in 1 : 11 ) {
Y[i , j] ~ dnorm(mu[i , j],tau)
mu[i , j] <- beta0[i] + beta1[i] * x[j]
}
beta0[i] ~ dnorm(ma[i],ta)
beta1[i] ~ dnorm(mb[i],tb)
ma[i] <-b00 + b01*dose[i]
mb[i] <-b10 + b11*dose[i]
}
tau ~ dgamma(0.001,0.001)

14 | P a g e
sigma <- 1 / sqrt(tau)
b00 ~ dnorm(0.0,0.0001)
b01 ~ dnorm(0.0, 0.0001)
b10 ~ dnorm(0.0,0.0001)
b11 ~ dnorm(0.0, 0.0001)
ta ~ dgamma(0.001,0.001)
tb ~ dgamma(0.001,0.001)
}

list(x = c(8.0, 15.0, 22.0, 29.0, 36.0, 43.0, 50.0, 57.0, 64.0, 71.0, 78.0), dose = c(0, 0, 0 , 0,
0, 0, 0, 0, 0, 0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1, 1, 1, 1,1, 1,1, 1, 1, 1, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8),
Y = structure(
.Data = c(54, 60, 63, 74, 77, 89, 93,100, 108, 114, 124,
69, 75, 81, 90, 97, 120, 114, 119, 126, 138, 143,
77, 81, 87, 94, 101, 110, 117, 124, 134, 141, 151,

67, 77, 83, 83, 92, 99, 104, 108, 114, 118, 129),
.Dim = c(50,11)))
list(beta0 = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1,
1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
beta1 = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1,
1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
tau = 1, ta = 1, tb = 1, b00 = 1, b01 = 1, b10 = 1, b11 = 1)

list(beta0 = c(5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,5, 5, 5, 5, 5, 5, 5, 5, 5, 5,5, 5,


5, 5, 5, 5, 5, 5, 5, 5,5, 5, 5, 5, 5, 5, 5, 5, 5, 5),
beta1 = c(5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,5, 5, 5, 5, 5, 5, 5, 5, 5,
5,5, 5, 5, 5, 5, 5, 5, 5, 5, 5,5, 5, 5, 5, 5, 5, 5, 5, 5, 5),
tau = 1.5, ta = 1.5, tb = 1.5, b00 = 1.5, b01 = 1.5, b10 = 1.5, b11 = 1.5)

list(beta0 = c(10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,10,
10, 10, 10, 10, 10, 10, 10, 10, 10,10, 10, 10, 10, 10, 10, 10, 10, 10, 10,10, 10, 10, 10, 10, 10,
10, 10, 10, 10),
beta1 = c(10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10,10, 10, 10, 10, 10, 10, 10, 10, 10, 10,10, 10, 10, 10, 10, 10, 10, 10, 10, 10,10, 10, 10, 10,
10, 10, 10, 10, 10, 10),
tau = 0.5, ta = 0.5, tb = 0.5, b00 = 0.5, b01 = 0.5, b10 = 0.5, b11 = 0.5)

(b) Provide some preliminary evidence that the model looks like it converged.

Trace Plots and Autocorrelation plots for 00, 01, 10, and 11 based on three chains

15 | P a g e
16 | P a g e
If the model has converged, the trace plot will move around the mode of the distribution, which
is the case for all the four trace plots above after 1000 iterations. The autocorrelation plots are
quickly falling to zero and they indicate that the sample chains are quickly mixing.
(c)
mean sd MC_error val2.5pc median val97.5pc start sample
beta0[1] 44.01 9.332 0.3153 41.13 44.49 47.75 1 210000
beta0[2] 59.76 10.13 0.3428 56.9 60.29 63.59 1 210000
beta0[3] 63.97 10.32 0.3494 61.12 64.52 67.8 1 210000
beta0[4] 54.47 9.865 0.3337 51.6 54.99 58.25 1 210000
beta0[5] 43.91 9.346 0.3156 40.99 44.39 47.7 1 210000
beta0[6] 54.21 9.838 0.3329 51.37 54.72 57.97 1 210000
beta0[7] 72.68 10.76 0.3649 69.87 73.24 76.54 1 210000
beta0[8] 68.09 10.55 0.3577 65.26 68.65 71.93 1 210000
beta0[9] 62.52 10.24 0.3468 59.69 63.06 66.35 1 210000
beta0[10] 66.94 10.48 0.3551 64.12 67.49 70.76 1 210000
beta0[11] 54.41 9.818 0.3319 51.55 54.91 58.19 1 210000
beta0[12] 58.02 9.968 0.3372 55.16 58.53 61.81 1 210000
beta0[13] 80.63 11.11 0.3767 77.83 81.22 84.52 1 210000
beta0[14] 70.21 10.59 0.3586 67.42 70.76 74.06 1 210000
beta0[15] 53.51 9.754 0.3298 50.59 54.02 57.29 1 210000
beta0[16] 56.39 9.907 0.3352 53.54 56.91 60.15 1 210000
beta0[17] 62.95 10.24 0.3465 60.09 63.49 66.76 1 210000

17 | P a g e
beta0[18] 60.27 10.1 0.3417 57.42 60.8 64.07 1 210000
beta0[19] 57.7 9.959 0.3369 54.83 58.22 61.49 1 210000
beta0[20] 45.28 9.35 0.3156 42.39 45.75 49.02 1 210000
beta0[21] 47.66 9.421 0.3177 44.77 48.14 51.42 1 210000
beta0[22] 47.5 9.399 0.3172 44.6 47.97 51.25 1 210000
beta0[23] 59.62 10.01 0.3385 56.77 60.14 63.39 1 210000
beta0[24] 48.73 9.451 0.3189 45.84 49.22 52.5 1 210000
beta0[25] 54.82 9.772 0.3301 51.95 55.33 58.64 1 210000
beta0[26] 52.57 9.646 0.3258 49.69 53.06 56.34 1 210000
beta0[27] 67.58 10.41 0.352 64.76 68.12 71.43 1 210000
beta0[28] 63.08 10.17 0.3441 60.22 63.61 66.91 1 210000
beta0[29] 61.91 10.12 0.342 59.07 62.44 65.72 1 210000
beta0[30] 58.43 9.952 0.3363 55.58 58.95 62.21 1 210000
beta0[31] 56.44 9.515 0.32 53.55 56.93 60.18 1 210000
beta0[32] 45.45 8.977 0.3008 42.54 45.9 49.18 1 210000
beta0[33] 56.06 9.501 0.3194 53.18 56.54 59.8 1 210000
beta0[34] 56.89 9.521 0.3202 54.0 57.37 60.65 1 210000
beta0[35] 58.2 9.584 0.3226 55.33 58.69 61.97 1 210000
beta0[36] 75.35 10.47 0.3534 72.54 75.9 79.16 1 210000
beta0[37] 63.71 9.869 0.3325 60.84 64.21 67.48 1 210000
beta0[38] 49.0 9.179 0.3079 46.06 49.46 52.77 1 210000
beta0[39] 57.85 9.593 0.3228 54.99 58.34 61.61 1 210000
beta0[40] 55.49 9.473 0.3184 52.63 55.97 59.24 1 210000
beta0[41] 50.42 8.84 0.2935 47.47 50.84 54.16 1 210000
beta0[42] 53.21 8.926 0.2968 50.26 53.64 56.96 1 210000
beta0[43] 51.51 8.854 0.2942 48.56 51.94 55.25 1 210000
beta0[44] 52.82 8.919 0.2967 49.86 53.26 56.54 1 210000
beta0[45] 48.15 8.726 0.2896 45.19 48.58 51.87 1 210000
beta0[46] 68.17 9.651 0.3228 65.27 68.66 71.95 1 210000
beta0[47] 67.75 9.626 0.3218 64.84 68.23 71.52 1 210000
beta0[48] 37.53 8.237 0.2716 34.56 37.91 41.2 1 210000
beta0[49] 60.59 9.325 0.3108 57.64 61.06 64.37 1 210000
beta0[50] 61.74 9.343 0.3118 58.81 62.2 65.51 1 210000
beta1[1] 0.9997 0.1956 0.006633 0.922 0.9894 1.059 1 210000
beta1[2] 1.086 0.1921 0.006503 1.007 1.075 1.145 1 210000
beta1[3] 1.082 0.1922 0.006503 1.004 1.072 1.142 1 210000
beta1[4] 0.9819 0.1973 0.006685 0.9042 0.9715 1.041 1 210000
beta1[5] 0.869 0.2018 0.006853 0.7907 0.8583 0.9282 1 210000
beta1[6] 1.077 0.1925 0.006522 0.9994 1.067 1.135 1 210000
beta1[7] 1.046 0.1949 0.006589 0.9681 1.036 1.106 1 210000
beta1[8] 0.983 0.1981 0.006712 0.9048 0.9725 1.042 1 210000
beta1[9] 1.147 0.1891 0.006397 1.07 1.137 1.207 1 210000
beta1[10] 1.105 0.1919 0.006495 1.027 1.095 1.164 1 210000
beta1[11] 0.9034 0.1995 0.006761 0.8254 0.8928 0.9622 1 210000
beta1[12] 1.025 0.1936 0.006552 0.9479 1.015 1.085 1 210000
beta1[13] 1.25 0.1846 0.006223 1.172 1.24 1.31 1 210000
beta1[14] 1.146 0.188 0.00635 1.069 1.137 1.206 1 210000
beta1[15] 0.8696 0.2005 0.0068 0.7916 0.8589 0.9293 1 210000
beta1[16] 0.9453 0.1973 0.00669 0.8685 0.9347 1.004 1 210000
beta1[17] 0.9538 0.1976 0.006684 0.8759 0.9433 1.013 1 210000
beta1[18] 0.901 0.1997 0.00677 0.823 0.8904 0.9597 1 210000
beta1[19] 1.029 0.1935 0.006551 0.951 1.018 1.088 1 210000
beta1[20] 1.029 0.1928 0.00653 0.9516 1.019 1.088 1 210000

18 | P a g e
beta1[21] 0.9687 0.1942 0.006578 0.8912 0.9586 1.028 1 210000
beta1[22] 1.004 0.1923 0.006516 0.9271 0.9941 1.064 1 210000
beta1[23] 1.013 0.193 0.006526 0.9359 1.003 1.072 1 210000
beta1[24] 0.9729 0.1934 0.006549 0.8954 0.9629 1.032 1 210000
beta1[25] 0.8577 0.2002 0.006781 0.7793 0.8472 0.9167 1 210000
beta1[26] 1.027 0.192 0.006496 0.9494 1.016 1.086 1 210000
beta1[27] 1.149 0.1871 0.00631 1.071 1.139 1.208 1 210000
beta1[28] 0.9654 0.1951 0.0066 0.8873 0.9552 1.025 1 210000
beta1[29] 1.037 0.1919 0.006489 0.96 1.027 1.097 1 210000
beta1[30] 0.984 0.194 0.006563 0.9067 0.9737 1.043 1 210000
beta1[31] 0.9017 0.1904 0.006409 0.8246 0.8919 0.9611 1 210000
beta1[32] 0.7819 0.1951 0.006582 0.7047 0.7719 0.841 1 210000
beta1[33] 0.9252 0.1884 0.006345 0.8481 0.9157 0.9848 1 210000
beta1[34] 0.9291 0.1886 0.006349 0.8517 0.9196 0.989 1 210000
beta1[35] 0.9699 0.1872 0.006291 0.8931 0.9605 1.029 1 210000
beta1[36] 0.8503 0.1937 0.006515 0.773 0.8402 0.9094 1 210000
beta1[37] 1.031 0.1844 0.006198 0.9538 1.021 1.09 1 210000
beta1[38] 0.743 0.1976 0.006671 0.6648 0.7328 0.8028 1 210000
beta1[39] 0.8136 0.1942 0.006545 0.7364 0.8037 0.8727 1 210000
beta1[40] 0.9153 0.1893 0.006376 0.8385 0.9057 0.9744 1 210000
beta1[41] 0.8674 0.1823 0.006066 0.7902 0.8587 0.9285 1 210000
beta1[42] 0.9707 0.1776 0.005886 0.8938 0.9623 1.032 1 210000
beta1[43] 0.9788 0.1763 0.005853 0.9023 0.9702 1.04 1 210000
beta1[44] 1.043 0.1743 0.005774 0.9669 1.035 1.105 1 210000
beta1[45] 0.6572 0.1914 0.006401 0.5797 0.6477 0.7174 1 210000
beta1[46] 1.014 0.1756 0.005824 0.9376 1.005 1.076 1 210000
beta1[47] 1.121 0.1721 0.005677 1.045 1.113 1.183 1 210000
beta1[48] 0.6574 0.1921 0.006414 0.5804 0.648 0.7172 1 210000
beta1[49] 0.5363 0.1987 0.006645 0.458 0.5262 0.5964 1 210000
beta1[50] 0.8318 0.1839 0.006127 0.7548 0.8228 0.8926 1 210000
b00 58.73 10.09 0.3411 55.71 59.26 62.71 1 210000
b01 -0.4357 0.4783 0.006132 -1.3 -0.4445 0.4375 1 210000
b10 1.017 0.1932 0.0066 0.9566 1.006 1.057 1 210000
b11 -0.02137 0.007766 1.047E-4 -0.03378 -0.02125 -0.008859 1 210000
tau 0.1418 0.01265 2.759E-4 0.1238 0.142 0.1614 1 210000

(d) mean sd MC_error val2.5pc median val97.5pc start sample


b01 -0.4357 0.4783 0.006132 -1.3 -0.4445 0.4375 1 210000
b11 -0.02137 0.007766 1.047E-4 -0.03378 -0.02125 -0.008859 1 210000

19 | P a g e
The mean of b01 is -0.4357, and its 95% credible region is (-1.3, 0.4375). This interval contains
0, and this means that drug dose level has no significant effect on the intercept of the growth of
rats. The mean of b11 is -0.02137, and its 95% credible region is (-0.03378, -0.008859), which
contains no 0. This indicates that the drug dose level has a significant effect on the slope of the
growth of rats, as we can see the growth curves below.

The lines are generated from the mean of the posterior distribution mu[i, j] of the model. Dose
level 0 lines are the smooth lines and they are the fastest set of growth curves. Dose level 0.5
lines are the lines with plus signs and they are the second fastest growth curves (except 2
peculiar rats in this group). Dose level 1 lines are the lines with the asterisks and they are the
third fastest growth curves. Dose level 4 lines are the lines with the x signs and they are the
fourth fastest growth curves. Does level 8 lines are the lines with circles and they are the
slowest growth curves. This concludes that the higher the dose level, the slower the growth
rate (flatter the slope).

20 | P a g e
(e) Statistics have proven that b01s 95% credible region is (-1.3, 0.4375) and it contains 0. This
means that drug dose level has no significant effect on the intercept of the growth of rats.
However, b11s 95% credible region (-0.03378, -0.008859) contains no 0, and this indicates
that the drug dose level has a significant effect on the slope of the growth of rats. The mean
of the b11 distribution is -0.02137, and it can be interpreted as an one unit increase in dose
leads to -0.02137 decrease in the slope of the growth of rats. This relationship can be
shown in the growth curves diagram above.

21 | P a g e

Potrebbero piacerti anche