我一直在尝试使用 R 和 JAGS 重现以下论文的结果,但没有成功。我可以让模型运行,但显示的结果始终不同。
论文链接:https ://www.pmi.org/learning/library/bayesian-approach-earned-value-management-2260
例如,本文的目的是使用从项目管理报告中收集的数据来估计项目完成日期或完成时的预算。项目绩效主要通过使用挣值衡量来报告,该衡量基本上包括实际完成的工作量与计划完成的工作量之间的比率,直到里程碑日期(换句话说,“完成的工作/计划的工作” )。因此,如果我在项目的第三个月花费了 300.000 美元来完成我之前计划花费 270.000 美元的工作量,那么我的成本绩效指数 (CPI) 为 300.000/270.000 = 1.111。同样,如果到第 3 个月我完成了与计划在第 2 个月完成的工作相对应的工作量,我的进度绩效指数 (SPI) 为 2/3 = 0.667。
论文背后的一般问题是如何使用绩效测量来更新对最终项目绩效的先验信念。
我的代码如下所示。我必须对数据执行转换(在获取 log() 之前添加 1,因为其中一些会是负数并且 JAGS 返回错误(这就是为什么我的模型上的参数与纸上表 4 中显示的参数不同的原因)。
论文中使用的模型是对数正态的似然性和先验的 mu 和 sigma 分别在 Normal 和 Inverse Gamma 上。由于 BUGS 语法使用 tau = 1/(variance) 作为正态和对数正态的参数,因此我在 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 的 (1.05;2.35) 和 (0.55;1.525)。该模型呈现了如下所示的结果。对于 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).
这几天一直在努力,找不到丢失的东西或错误的地方。