r - 如何在 (...) 中获取值并取平均值?
问题描述
我正在使用包R0
。我正在尝试复制 CRAN pdf 中提供的示例,但没有得到与 pdf 中提供的完全相同的结果。
代码:
library(R0)
data(Germany.1918)
mGT <- generation.time("gamma", c(3,1.5))
SB <- est.R0.SB(Germany.1918, mGT)
##Results will include "most likely R(t)" (ie. the R(t) value for which the computed probability
##is the highest), along with 95% CI, in a data.frame object
SB
# Reproduction number estimate using Real Time Bayesian method.
# 0 0 2.02 0.71 1.17 1.7 1.36 1.53 1.28 1.43 ...
SB$Rt.quant
# Date R.t. CI.lower. CI.upper.
# 1 1918-09-29 0.00 0.01 1.44
# 2 1918-09-30 0.00 0.01 1.42
# 3 1918-10-01 2.02 0.97 2.88
# 4 1918-10-02 0.71 0.07 1.51
# 5 1918-10-03 1.17 0.40 1.84
# 6 1918-10-04 1.70 1.09 2.24
# 7 1918-10-05 1.36 0.84 1.83
# 8 1918-10-06 1.53 1.08 1.94
# 9 1918-10-07 1.28 0.88 1.66
# 10 1918-10-08 1.43 1.08 1.77
# ...
我有三个疑问。
最后一个命令
SB$Rt.quant
在输出中显示 NULL。我怎样才能得到与示例中完全相同的结果?如何获取隐藏在 (...) 中的值,用于命令:
SB
和SB$Rt.quant
?如何获取 SB 的均值和中位数并获得 SB 的相关均值和中位数的置信区间?
解决方案
现在争论已经改变了。您必须使用SB$conf.int
才能获得置信区间,例如
library(R0)
## Data is taken from the paper by Nishiura for key transmission parameters of an institutional
## outbreak during 1918 influenza pandemic in Germany)
data(Germany.1918)
mGT <- generation.time("gamma", c(3,1.5))
SB <- est.R0.SB(Germany.1918, mGT)
SB
SB$conf.int
然后您可以使用write.csv(SB$conf.int)
打印所有值。如果您想同时拥有 R 和置信区间,就像R0
pdf 文档中的示例一样,您可以使用以下代码
cbind(Rt=SB$R, SB$conf.int)
阅读第三个问题,我认为您可以通过使用来获得平均值,
SB$R
并且包中没有中值函数。置信区间已经可以通过SB$conf.int
.
推荐阅读
- excel - 将最近 5 天工作簿的单元格值汇总到单个工作簿中
- if-statement - Crystal 2008 中此处需要一个字符串(If Else 语句)
- security - SSL 客户端问候重置
- php - PHP - 将拍卖结束日期设置为在工作日结束
- javascript - 在不知道“data-”之后的内容的情况下获取 data-* 属性的值
- android - 清单合并失败:属性 application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory)
- flask-assets - 烧瓶资产 append_path() catch-22
- javascript - TypeError:无法读取未定义 jQuery 的属性“顶部”
- php - PHP 和 Ruby 上的相同代码给出不同的结果
- c# - liskov 替换原则再次 - 每个方法覆盖都违反了原则