我一直在尝试使用R和JAGS重现以下论文的结果,但没有成功。我可以运行模型,但是显示的结果始终不同。
论文链接:https://www.pmi.org/learning/library/bayesian-approach-earned-value-management-2260
例如,本文的目的是使用从项目管理报告中收集的数据来估计项目完成日期或完成时的预算。项目绩效大部分是通过使用挣值测量报告的,该测量基本上由实际完成的工作量与计划在里程碑日期之前完成的工作量之间的比率组成(按顺序,“完成的工作/计划的工作” )。因此,如果我在该项目的第三个月花费了300.000美元来生产我先前计划花费270000美元的工作量,那么我的成本性能指数(CPI)为300.000 / 270.000 = 1.111。同样,如果到第三个月我完成的工作量与第二个月计划完成的工作量相对应,则我的进度绩效指数(SPI)为2/3 = 0.667。
本文的主要问题是如何使用绩效评估来更新关于最终项目绩效的先验信念。
我的代码显示如下。我必须对数据执行转换(在获取log()之前加1,因为其中一些将为负数并且JAGS返回错误(这就是为什么我的模型上的参数与纸张的表4所示不同)的原因。
在纸上使用的模型分别是对数正态作为似然性,并且分别对正和反Gamma的mu和sigma具有先验性。由于BUGS语法将tau = 1 /(方差)用作Normal和Lognormal的参数,因此我在tau上使用了Gamma分布(这对我来说很有意义)。
model_pmi <- function() {
for (i in 1:9) {
cpi_log[i] ~ dlnorm(mu_cpi, tau_cpi)
spi_log[i] ~ dlnorm(mu_spi, tau_spi)
}
tau_cpi ~ dgamma(75, 1)
mu_cpi ~ dnorm(0.734765, 558.126)
cpi_pred ~ dlnorm(mu_cpi, tau_cpi)
tau_spi ~ dgamma(75, 1.5)
mu_spi ~ dnorm(0.67784, 8265.285)
spi_pred ~ dlnorm(mu_spi, tau_spi)
}
model.file <- file.path(tempdir(), "model_pmi.txt")
write.model(model_pmi, model.file)
cpis <- c(0.486, 1.167, 0.856, 0.770, 1.552, 1.534, 1.268, 2.369, 2.921)
spis <- c(0.456, 1.350, 0.949, 0.922, 0.693, 0.109, 0.506, 0.588, 0.525)
cpi_log <- log(1+cpis)
spi_log <- log(1+spis)
data <- list("cpi_log", "spi_log")
params <- c("tau_cpi","mu_cpi","tau_spi", "mu_spi", "cpi_pred", "spi_pred")
inits <- function() { list(tau_cpi = 1, tau_spi = 1, mu_cpi = 1, mu_spi = 1, cpi_pred = 1, spi_pred = 1) }
out_test <- jags(data, inits, params, model.file, n.iter=10000)
out_test
在纸上发现的95%CI(2.5%; 97.5%)对于CPI和(0.55; 1.525)为(1.05; 2.35)。该模型显示了如下所示的结果。对于CPI,结果相当接近,但是当我看到SPI的结果时,我认为应该只是偶然。
Inference for Bugs model at
"C:\Users\felip\AppData\Local\Temp\RtmpSWZ70g/model_pmi.txt", fit using jags,
3 chains, each with 10000 iterations (first 5000 discarded), n.thin = 5
n.sims = 3000 iterations saved
mu.vect sd.vect 2.5% 25% 50% 75% 97.5% Rhat n.eff
cpi_pred 1.691 0.399 1.043 1.406 1.639 1.918 2.610 1.001 2200
mu_cpi 0.500 0.043 0.416 0.471 0.500 0.529 0.585 1.001 3000
mu_spi 0.668 0.011 0.647 0.660 0.668 0.675 0.690 1.001 3000
spi_pred 2.122 0.893 0.892 1.499 1.942 2.567 4.340 1.001 3000
tau_cpi 20.023 2.654 15.202 18.209 19.911 21.726 25.496 1.001 3000
tau_spi 6.132 0.675 4.889 5.657 6.107 6.568 7.541 1.001 3000
deviance 230.411 19.207 194.463 217.506 230.091 243.074 269.147 1.001 3000
For each parameter, n.eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor (at convergence, Rhat=1).
DIC info (using the rule, pD = var(deviance)/2)
pD = 184.5 and DIC = 414.9
DIC is an estimate of expected predictive error (lower deviance is better).
花了几天时间,找不到丢失或出问题的地方。
答案 0 :(得分:0)
使用y ~ dlnorm(mu,tau)
时,y
值是原始刻度值,而不是对数刻度值。但是mu
和tau
处于对数刻度(令人困惑)。
此外,将先验直接放在mu
和tau
上可能会在链中产生不良的自相关。重新参数化有帮助。有关详细信息,请参阅此博客文章(我写过):http://doingbayesiandataanalysis.blogspot.com/2016/04/bayesian-estimation-of-log-normal.html