r - 我收到错误“矩阵上的下标数量不正确”
问题描述
我正在尝试执行配对排列 t 检验。我收到一个错误“在 t.star[r, ] <- res[[r]] 中:矩阵上的下标数量不正确”。下面是我写的代码。任何指针表示赞赏。
library(RVAideMemoire)
library(boot)
library(xlsx)
mydata <- read.xlsx("C:/data_bootstrap.xlsx",1)
results = boot(mydata,statistic=sample_mean,R=500)
print (results)
sample_mean <- function(mydata, indices) {
sam=mydata[indices,1]
sam1=mydata[indices,2]
bar = perm.t.test(sam,sam1,paired=TRUE,nperm=500)
return(bar)
}
原始数据,无需链接:
structure(list(Random = c(11L, 10L, 11L, 11L, 10L, 10L, 36L, 11L, 10L, 16L, 16L, 10L, 16L, 10L, 16L, 10L, 11L, 11L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 10L, 10L, 10L, 11L), Statement = c(11L, 10L, 11L, 10L, 10L, 16L, 16L, 10L, 10L, 16L, 11L, 11L, 10L, 10L, 16L, 11L, 10L, 11L, 16L, 10L, 11L, 10L, 16L, 10L, 10L, 10L, 11L, 10L, 10L)), class = "data.frame", row.names = c(NA, -29L))
解决方案
该boot()
函数要求其statistic
参数是一个返回向量的函数。您的sample_mean
函数返回一个类列表,"htest"
因为这是perm.t.test()
. 根据函数名称,我假设您想要估计该测试的差异均值。
如果您将函数更改为如下所示,则代码有效。
sample_mean <- function(mydata, indices) {
sam=mydata[indices,1]
sam1=mydata[indices,2]
bar = perm.t.test(sam,sam1,paired=TRUE,nperm=500)
return(bar$estimate)
}
如果您想要与 不同的输出perm.t.test()
,则换成$estimate
其他东西,例如$statistic
or $p.value
。
这是boot
with的示例R=10
(易于管理):
results = boot(mydata,statistic=sample_mean,R=10)
print(results)
ORDINARY NONPARAMETRIC BOOTSTRAP
Call:
boot(data = mydata, statistic = sample_mean, R = 10)
Bootstrap Statistics :
original bias std. error
t1* 0.5172414 0.1206897 0.720067
推荐阅读
- flutter-test - 颤振中的错误:widget_test.dart 无法检测到 MyApp()
- node.js - 向不与我的机器人共享服务器的用户发送消息
- python - 如何理解一维数组和二维数组的 numpy dot 生成的维度变化?
- java - 添加 RecyclerView Layoutmanager 时我的应用停止了
- c# - 如何在 Android 上让 3D 对象从左到右跟随我的手指?
- connection - 将边缘插入中继连接的正确方法是什么?
- c++ - 为什么在重载区域函数时在波纹管代码的情况下会出现歧义
- python - sqlalchemy.exc.StatementError: (builtins.TypeError) SQLite DateTime 类型只接受 Python 日期时间和日期对象作为输入
- flutter - 手机的后退按钮无法正常工作
- r - geom_jitter 更小 增加点大小