使用启动从矩阵返回rowmean和cis

发布于 2025-02-06 06:00:52 字数 531 浏览 1 评论 0原文

简单的问题。我有一个矩阵foo,我想使用启动来引导每一行的平均值及其95%CI。我希望输出是data.framenrow(foo)和三列均值,下CI和上CI。看起来很简单,但是bootboot.ci语法正在避开我。

我想我将使用boot应用,但我不确定如何进一步。任何帮助都赞赏。

首先尝试。

foo <- matrix(rnorm(1000),nrow=10)
getMean <- function(x,ind){
  mean(x[ind],na.rm = TRUE)
}

meanBoot <- apply(X = foo,MARGIN = 1, FUN = boot,
                   statistic = getMean,
                   R = 200)

编辑:错字

Simple question. I have a matrix foo and I want to bootstrap the mean value of each row and its 95% CI using boot. I want the output to be a data.frame with nrow(foo) and three columns the mean, lower CI, and upper CI. Seems simple but the boot and boot.ci syntax is eluding me.

I imagine I use apply with boot but I'm not sure how to go further. Any help appreciated.

First try.

foo <- matrix(rnorm(1000),nrow=10)
getMean <- function(x,ind){
  mean(x[ind],na.rm = TRUE)
}

meanBoot <- apply(X = foo,MARGIN = 1, FUN = boot,
                   statistic = getMean,
                   R = 200)

Edit: typo

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云归处 2025-02-13 06:00:53

我们可以做

library(boot)
out <- do.call(rbind, apply(foo, 1, FUN = function(x) 
      {
    x1 <- boot.ci(boot(x, statistic = getMean, R = 200))
    data.frame(mean = x1$t0, lowerCI = x1$normal[2], upperCI = x1$normal[3])
      }))

- 输出

> out
          mean     lowerCI    upperCI
1  -0.13716932 -0.32814349 0.05074657
2   0.14091601 -0.03785282 0.30007863
3   0.06313605 -0.16234730 0.27028525
4  -0.08422669 -0.25017647 0.07886253
5  -0.07288179 -0.27784123 0.13525142
6  -0.03636316 -0.20738203 0.13542197
7  -0.13201509 -0.30910041 0.04210289
8  -0.16965578 -0.34039042 0.04289176
9  -0.05509720 -0.26274593 0.14733604
10  0.10166934 -0.09162666 0.29662724

We may do

library(boot)
out <- do.call(rbind, apply(foo, 1, FUN = function(x) 
      {
    x1 <- boot.ci(boot(x, statistic = getMean, R = 200))
    data.frame(mean = x1$t0, lowerCI = x1$normal[2], upperCI = x1$normal[3])
      }))

-output

> out
          mean     lowerCI    upperCI
1  -0.13716932 -0.32814349 0.05074657
2   0.14091601 -0.03785282 0.30007863
3   0.06313605 -0.16234730 0.27028525
4  -0.08422669 -0.25017647 0.07886253
5  -0.07288179 -0.27784123 0.13525142
6  -0.03636316 -0.20738203 0.13542197
7  -0.13201509 -0.30910041 0.04210289
8  -0.16965578 -0.34039042 0.04289176
9  -0.05509720 -0.26274593 0.14733604
10  0.10166934 -0.09162666 0.29662724
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文