【发布时间】:2019-04-09 00:12:50
【问题描述】:
从对象中提取东西一直是 R 对我来说最令人困惑的方面之一。我已经使用 rjags 拟合了贝叶斯线性回归模型,并具有以下 mcmc 对象:
summary(m_csim)
Iterations = 1:150000
Thinning interval = 1
Number of chains = 1
Sample size per chain = 150000
1. Empirical mean and standard deviation for each variable,
plus standard error of the mean:
Mean SD Naive SE Time-series SE
BR2 0.995805 0.0007474 1.930e-06 3.527e-06
BR2adj 0.995680 0.0007697 1.987e-06 3.633e-06
b[1] -5.890842 0.1654755 4.273e-04 1.289e-02
b[2] 1.941420 0.0390239 1.008e-04 1.991e-03
b[3] 1.056599 0.0555885 1.435e-04 5.599e-03
sig2 0.004678 0.0008333 2.152e-06 3.933e-06
2. Quantiles for each variable:
2.5% 25% 50% 75% 97.5%
BR2 0.994108 0.995365 0.995888 0.996339 0.99702
BR2adj 0.993932 0.995227 0.995765 0.996229 0.99693
b[1] -6.210425 -6.000299 -5.894810 -5.784082 -5.55138
b[2] 1.867453 1.914485 1.940372 1.967466 2.02041
b[3] 0.942107 1.020846 1.057720 1.094442 1.16385
sig2 0.003321 0.004082 0.004585 0.005168 0.00657
为了提取系数的意思我做了b = colMeans(mod_csim)[3:5]。我想计算可信区间,所以我也需要提取 0.025 和 0.975 分位数。我如何以编程方式做到这一点?
【问题讨论】:
-
通常有这样的方法。不确定
rjags,但是coef和fixef一般都是用的,要么在模型对象上,要么在模型对象的摘要上。也有不错的包,比如tidybayes。 -
如果您包含一个简单的reproducible example,其中包含可用于测试和验证可能解决方案的示例输入和所需输出,则更容易为您提供帮助。
-
我会从
str(m_csim)开始,看看它到底是什么。然后,请记住 summary functions 在打印之前多次执行自己的计算并运行str(summary(m_csim))。