这个作业是用R语言建立参数模型并进行分析
STAT 440/840 – CM 761 – Assignment 4

问题一-25分
形状参数α> 0和比例参数θ> 0的威布尔分布由下式给出

θ,α)=(
α
θ

X
θ
α-1
Ë
−(x /θ)
α
x≥0,
0 x <0,
使用γ=θ重新参数化模型
α。假设我们获得以下数据;
set.seed(440)
x = rweibull(24,形状= 1/2,比例= 64)

γ,α)=(
αxα-1
γ
Ë
-x
α/γx≥0,
0 x <0,
•注意:这里我们对γ=θ的推论感兴趣
α以α为条件。
a)[4分]显示γ的共轭先验是具有超参数的反伽马分布
由invΓ(λ,β)表示的(λ,β)。密度由下式给出

λ,β)=(β
λ
Γ(λ)
(1 / x)
λ+ 1 exp(-β/ x)x≥0,
0 x <0,
b)[6分]使用以下每个先验绘制先验和后验,然后计算可信度
γ的间隔
i)λ= 1和β= 10之前的反伽马,
ii)λ= 10且β= 1的先验反伽马,以及
iii)p(γ)= 1的不当先验
•请注意,R包invgamma可能会有所帮助。
c) [4 Marks] Calculate a confidence interval using the log-likelihood ratio.
d) [2 Marks] Compare and discuss the intervals generated in b) and d).
e) In b) we can calculate the credible intervals exactly. Instead use MCMC to estimate the credible interval
from b iii).
i) [1 Mark] Construct a R function that generates a random walk MCMC algorithm to sample
from the posterior. The input is the random walk length, the standard deviation for the random
walk density σ, and the initial position.

ii) [8 Marks] Run a random walk MCMC using σ = 0.1, 1, 5, 20, T = 104
iterations and starting
state γ
(0) = 8.9. Then for each MCMC provide
• traceplot, autocorrelation,
• summary table with the acceptance rate, estimate of the posterior mean, naive estimate of the
credible interval, and a measure of mixing using
1
T
X
T
t=1
(xt − xt−1)
2
• and then comment on the results.
Question Two – 16 Marks
Here we are interested in Bayesian inference for α conditional on the scale scale parameter being known and
equal to θ = 64. Use an improper of p(α) = 1 for α ≥ 0.
set.seed(440)
x = rweibull(n=24, shape=1/2, scale=64)
a) [2 Mark] Write a R function that is proportional to the posterior on the log-scale.
b) Write R functions that generates a MCMC sample from the posterior using the following the proposals
or candidate densities;
i) [2 Marks] follows a gamma with shape equal to 1 and rate equal to 2
ii) [2 Marks] follows a gamma with shape equal to 1 and rate equal to 1/Xt
iii) [2 Marks] follows a N(Xt, 0.1), and
iv) [2 Marks] follows a N(α, b O(αb)
−1
). i.e. an Gaussian independence sampler with mean equal to
the MLE and variance equal to the inverse observed information.
v) [6 Marks] Generate a sample path of length 10, 000 using each of the above MCMCs and the
initial value equal to 1/2.
• Summarize and comment on the traceplots, autocorrelations, histogram of the posterior from
each MCMC.
• Use a table to summarize the acceptance ratio, the estimate of the posterior average & variance
and the mixing criteria, 1
T
PT
t=1 (xt − xt−1)
2
.