简体   繁体   English

如何从mcmc.list对象中获取均值?

[英]How to get the mean from mcmc.list object?

output = RBugsfit(..., coda=T, ...) output a mcmc.list object, which contains samples of the posterior distributions of four parameters, and their sample posterior means. output = RBugsfit(..., coda=T, ...)输出一个mcmc.list对象,其中包含四个参数的后验分布样本及其样本后验均值。 Using summary() I can see the sample posterior means, but I wonder how to retrieve the sample posterior means from output into a variable in my program? 使用summary()我可以看到样本后验的意思,但我想知道如何从我的程序中将output检索到变量后面的变量? Thanks! 谢谢!

> summary(output)

Iterations = 201:3396
Thinning interval = 5 
Number of chains = 2 
Sample size per chain = 640 

1. Empirical mean and standard deviation for each variable,
   plus standard error of the mean:

           Mean        SD  Naive SE Time-series SE
beta  1.052e+00 3.189e-02 8.914e-04      9.185e-04
df    3.849e+00 2.916e-01 8.150e-03      1.516e-02
sigma 1.056e-02 2.504e-04 6.998e-06      1.000e-05
tau   8.990e+03 4.273e+02 1.194e+01      1.710e+01

2. Quantiles for each variable:

           2.5%       25%       50%       75%     97.5%
beta  9.891e-01 1.032e+00 1.052e+00 1.073e+00 1.113e+00
df    3.304e+00 3.650e+00 3.836e+00 4.042e+00 4.450e+00
sigma 1.004e-02 1.039e-02 1.055e-02 1.072e-02 1.105e-02
tau   8.197e+03 8.700e+03 8.977e+03 9.263e+03 9.917e+03

> str(output)
List of 2
 $ : mcmc [1:640, 1:4] 1.1 1.03 1.05 1.12 1.07 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:4] "beta" "df" "sigma" "tau"
  ..- attr(*, "mcpar")= num [1:3] 201 3396 5
 $ : mcmc [1:640, 1:4] 1.03 1.04 1.06 1.06 1.07 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:4] "beta" "df" "sigma" "tau"
  ..- attr(*, "mcpar")= num [1:3] 201 3396 5
 - attr(*, "class")= chr "mcmc.list"

I usualy use two ways: 我通常使用两种方式:

1) using a summary (assuming output is of class mcmc.list): 1)使用摘要(假设输出是mcmc.list类):

s <- summary(output)
m <- s$statistics[,"Mean"]

2) do it myself: 2)自己做:

mt <- as.matrix(output)
m <- apply(mt, 2, mean)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM