Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中带bootstrap的T检验_R_Statistics Bootstrap_T Test - Fatal编程技术网

R中带bootstrap的T检验

R中带bootstrap的T检验,r,statistics-bootstrap,t-test,R,Statistics Bootstrap,T Test,我正在尝试用R中的bootstrap运行t测试。 我有一个50人的样本,其中39人是女性。我有一个因变量,d’,我想看看男性和女性在这个变量上是否有所不同。因为我只有11名男性参与者,我想使用自举t检验(这不是最好的方法,但我在文献中见过) 我有一个名为“data”的数据库,其中包含多个变量。首先,我提取了两个向量: dPrimeFemales <- subset(data, Gender == "F", select=c(dPri

我正在尝试用R中的bootstrap运行t测试。 我有一个50人的样本,其中39人是女性。我有一个因变量,d’,我想看看男性和女性在这个变量上是否有所不同。因为我只有11名男性参与者,我想使用自举t检验(这不是最好的方法,但我在文献中见过)

我有一个名为“data”的数据库,其中包含多个变量。首先,我提取了两个向量:

dPrimeFemales <- subset(data, Gender == "F", 
                  select=c(dPrime))

dPrimeMales <- subset(data, Gender == "M", 
                        select=c(dPrime))
我也试过:

首先,我无法加载函数。因此,我复制粘贴并运行以下命令:

boot.t.test(x = dPrimeFemales, y = dPrimeMales)

然后我运行这个:

boot.t.test(x = dPrimeFemales, y = dPrimeMales)
但是,它说:

Error in boot.t.test(x = dPrimeFemales, y = dPrimeMales) : 
  dims [product 1] do not match the length of object [1000]
In addition: There were 50 or more warnings (use warnings() to see the first 50)
如果我使用
warnings()
它会说:

1: In mean.default(x) : argument is not numeric or logical: returning NA
2: In mean.default(y) : argument is not numeric or logical: returning NA
3: In mean.default(c(x, y)) : argument is not numeric or logical: returning NA
4: In mean.default(x) : argument is not numeric or logical: returning NA
5: In mean.default(y) : argument is not numeric or logical: returning NA
等等

更清楚地说,我想到了SPSS中的引导t检验,如下所示:

我以为这会容易得多。 欢迎任何帮助

谢谢大家抽出时间

structure(list(dPrime = c(0.60805224661517, 0.430727299295457, 
-0.177380196159658, 0.771422126383253, 0.598621304083563, 0, 
0.167894004788105, -0.336998837042929, 0.0842422708809764, -0.440748778800912, 
0.644261556974516, -0.167303467814258, 0.169695369228671, -0.251545738695235, 
0.0842422708809764, -0.0985252105020469, -0.239508275220057, 
-0.143350050535084, 0.430727299295457, 0.757969499665785, -0.282230896122292, 
-0.271053409572241, -0.090032472207662, -0.090032472207662, 0.524400512708041, 
-0.218695510362827, -0.271053409572241, 1.07035864674857, 0.262833294507352, 
0.421241107923905, -0.0836517339071291, 0.090032472207662, -0.598621304083563, 
-0.356506507919935, 0.474566187745845, 0.336998837042929, 1.35083901409173, 
-0.336998837042929, -0.443021053393661, 0.757969499665785, -0.841621233572914, 
0.167303467814258, 0.167894004788105, 0.090032472207662, -0.177380196159658, 
0.251545738695235, -0.344495842891614, -0.17280082229969, -0.440748778800912, 
0), Gender = c("F", "F", "F", "F", "F", "F", "F", "F", "M", "M", 
"F", "F", "F", "F", "F", "F", "F", "F", "M", "F", "M", "M", "F", 
"F", "F", "F", "F", "F", "F", "F", "M", "F", "F", "F", "M", "F", 
"F", "F", "F", "M", "M", "F", "F", "M", "M", "F", "F", "F", "F", 
"F")), row.names = c(NA, -50L), class = c("tbl_df", "tbl", "data.frame"
))

下面是一个将该函数用于模拟数据的示例,其中p值接近1。无需预先将其子集并创建中间对象

set.seed(0)
df <- data.frame(gender = sample(c('M', 'F'), size=50, replace=T),
                 measure = runif(n=50))

boot.t.test(df[df$gender=='M', 'measure'], df[df$gender=='F', 'measure'], reps=1000)

Bootstrap Two Sample t-test


t = -0.186, p-value = 0.859
Alternative hypothesis: true difference in means is not equal to 0

$mu0 
[1] 0

$statistic
[1] -0.1863362

$alternative
[1] "two.sided"

$p.value
[1] 0.859
set.seed(0)

df我不清楚你到底打算引导什么。t统计?你能分享
数据的结构吗?误差到底在哪里?是的,t统计量。我会尝试上传数据(尝试)…你应该可以在这里获得数据样本:(不知道这里是否有更好的共享方式)。此外,我还试图通过添加一张我在SPSSHi Bill中试图实现的分析图片来更清楚地说明我的意思,这看起来很棒,但您能告诉我您需要哪些软件包吗?因为我尝试了类似的东西(我想),但我得到了:boot.t.test中的错误(df[data$Gender==“M”,“measure”]、df[data$Gender==:找不到函数“boot.t.test显然我丢失了一些包或库我无法安装tpepler/nonpar包(),所以我只是复制并粘贴了这个函数到我的工作区。虽然不理想,但足以测试它。抱歉,我只是尝试了你的建议。所以,我尝试了以下内容:set.seed(0)boot.t.test(data[data$Gender='M',dprome'],data[data$Gender='F',dprome'],reps=1000)我得到这个错误:boot.t.test(data[data$Gender='M',dprome'],data[data$Gender==:dims[product 1]与对象[1000]的长度不匹配。此外:有50个或更多警告(使用warnings()查看前50个)。这与我之前得到的类似(请参阅我的初始帖子)顺便说一句,如果我尝试一下你的例子,它会起作用。我真的不明白为什么它不能处理我的数据。我无法回答,因为filehosting.org在我的工作场所被阻止。如果你使用dput()在上面的问题中发布你的数据,我很乐意提供进一步的帮助。当你运行数据[data$Gender='m',dprome',它会返回预期长度的数字向量吗?
set.seed(0)
df <- data.frame(gender = sample(c('M', 'F'), size=50, replace=T),
                 measure = runif(n=50))

boot.t.test(df[df$gender=='M', 'measure'], df[df$gender=='F', 'measure'], reps=1000)

Bootstrap Two Sample t-test


t = -0.186, p-value = 0.859
Alternative hypothesis: true difference in means is not equal to 0

$mu0 
[1] 0

$statistic
[1] -0.1863362

$alternative
[1] "two.sided"

$p.value
[1] 0.859