簡體   English   中英

關於 R 的 JAGS 中的警告消息

[英]Regarding a warning message in JAGS for R

我在學習貝葉斯時正在試驗rjags r package。 我使用rrr package 中的煙草數據集擬合了多元 model。

在此處輸入圖像描述

其中 \gamma 是一個隨機截距,用於衡量結果之間的相關性。 此外,我故意將響應的某些值設為缺失值,以探索數據結構不平衡的結果。 同時,我添加了表示主題 ID 的 AID 變量。

我使用rjags安裝了這個 model,如下所示。

library(rrr)
require(dplyr)
library(rjags)
data("tobacco")
tobacco <- as_data_frame(tobacco)

tobacco$AID=seq(1:25)
tobacco[4,1]=NA
tobacco[14,1]=NA
tobacco[8,1]=NA
tobacco[6,2]=NA
tobacco[1,2]=NA
tobacco[19,2]=NA
tobacco[21,2]=NA


N1=length(tobacco$Y1.BurnRate)
bayes_model_mul="model {
for(i in 1:N1){
Y1.BurnRate[i]~dnorm(mu1[i],tau1)
Y2.PercentSugar[i]~dnorm(mu2[i],tau2)
mu1[i]=beta1[1] + beta1[2]*X2.PercentChlorine[i] + beta1[3]*X3.PercentPotassium[i] + gamma[AID[i]]
mu2[i]=beta2[1] + beta2[3]*X2.PercentChlorine[i] + beta2[2]*X1.PercentNitrogen[i]+
beta2[4]*X3.PercentPotassium[i]+gamma[AID[i]]
gamma[i] ~ dmnorm(0,tau_u)

}
for (l in 1:3) { beta1[l] ~dnorm(0, 0.001) }
for (l in 1:4) { beta2[l] ~dnorm(0, 0.001) }
tau1 ~ dgamma(.01,.01)
sigma_tau1 = 1/tau1 

tau2 ~ dgamma(.01,.01)
sigma_tau2 = 1/tau2

tau_u ~ dgamma(.01,.01)
sigma_tau_u = 1/tau_u 
}"


model3 <- jags.model(textConnection(bayes_model_mul), 
                     data = list(Y1.BurnRate=tobacco$Y1.BurnRate,
                                 Y2.PercentSugar=tobacco$Y2.PercentSugar
                                 ,X1.PercentNitrogen=tobacco$X1.PercentNitrogen,
                                 N1=N1,X2.PercentChlorine=tobacco$X2.PercentChlorine,
                                 X3.PercentPotassium=tobacco$X3.PercentPotassium,AID=tobacco$AID),
                     n.chains=1)
params <- c('beta1','sigma_tau1','sigma_tau2','beta2','sigma_tau_u','gamma')
samps.1 <- coda.samples(model3, params, n.iter = 10000)
burn.in=1000
summary.model.1=summary(window(samps.1, start = burn.in))

我沒有收到任何錯誤。 但是我收到了以下警告消息。

Warning message:
In FUN(X[[i]], ...) : start value not changed

誰能幫我弄清楚這條錯誤消息是關於什么的?

謝謝你。

window function 用於 select 一系列樣本。 它需要startend參數。 start取的值應該大於傳遞給n.adapt中的jags.modelsn.iter中的update的迭代次數之和,如果明確設置了老化樣本的數量。

你可以看看 jags.model 返回的jags.model看看迭代次數是如何變化的。

# Define the model
model3 <- jags.model(textConnection(bayes_model_mul), n.adapt=1234,
                     data = list(Y1.BurnRate=tobacco$Y1.BurnRate,Y2.PercentSugar=tobacco$Y2.PercentSugar,X1.PercentNitrogen=tobacco$X1.PercentNitrogen,N1=N1,X2.PercentChlorine=tobacco$X2.PercentChlorine,X3.PercentPotassium=tobacco$X3.PercentPotassium,AID=tobacco$AID),
                     n.chains=1)
# Look at the number of iterations (== n.adapt)
model3$iter()
#1234

# Add some burnin iterations: iterations are updated to n.adapt + burnin
update(model3, n.iter=1111)
model3$iter()
# 2345

# Draw more samples -> iterations updated to n.adapt + burnin + n.iter
samps.1 <- coda.samples(model3, n.iter = 10000, variable.names=c('beta1','sigma_tau1','sigma_tau2','beta2','sigma_tau_u','gamma'))
model3$iter()
# 12345

當我們使用window時,起始值預計會大於n.adapt + burnin ,因為這些迭代已被丟棄。 如果不是, coda.samples object 中提取start (請參閱mcpar(samps.1[[1]]) )並且不使用您的手動start

所以使用w=window(samps.1, start=2345)會給出你看到的警告

警告信息:
在 FUN(X[[i]], ...) 中:起始值未更改

但是以下是可以的,因為start大於n.adapt + burnin

w=window(samps.1, start=2346)

請記住,這些只是警告,在這種情況下並不那么重要。 但是,如果您在不重新運行coda.samples的情況下重新運行jags.model ,這將再次更新迭代,這使得跟蹤要傳遞給window的值變得有點困難(然后可能會拋出錯誤)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM