我想绘制测试的大小(例如 t test )与样本大小.如何在 R 中进行? [英] I want to plot the size of a test (for example t test ) vs the sample size .How to do it in R?

查看:28
本文介绍了我想绘制测试的大小(例如 t test )与样本大小.如何在 R 中进行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 x<-rnorm (a,0,1)y <- rnorm( a,0,1) a 代表样本大小 I将使用不同的样本大小,例如 (20,30,40,50),然后计算测试的大小(t 检验或任何其他测试),然后绘制它与样本大小的关系.

i have x<-rnorm (a,0,1) and y <- rnorm( a,0,1) the a represent the sapmle size I will use different sample size for example (20,30,40,50) and then calculate the size of the test (t test or whatever other test) and then plot it vs sample size.

plot(a,测试的大小)

推荐答案

这听起来像是我给学生做的一个练习,向他们展示自由度对临界 T 值的影响.

That sounds like an excercise I do with students to show them the impact of degrees of freedom on critical T-values.

首先,我不会为每个样本大小做一次,而是至少做 100-1000 次.然后,存储所有结果并绘制密度图以可视化 T 值.也许还包括条形图,以表明 5% 变得显着,与样本量无关,因为 R 校正了自由度:

First off, I would not do it once for each sample size but at least 100-1000 times. Then, store all the results and draw density plots to visualize the T-Values. Perhaps also include barplots to show that 5% get significant, independent of the sample size because R corrects for degrees of freedom:

ssizes = c(5,10,20,30,50,100,200)
cols = rainbow(7)
t.list = list()
p.list = list()
n = 1000
for(s in ssizes){
  t = c()
  sig = 0
  for(i in 1:n){
    x = rnorm(s,0,1)
    y = rnorm(s,0,1)
    test = t.test(x,y)
    t[i] = test$statistic ## Store the t-value
    if(test$p.value<0.05){sig=sig+1}
  }
  t.list[[as.character(s)]]=t
  p.list[[as.character(s)]]=sig
}

plot(0,0,pch="",main="Density Plots",xlim=c(-4,4),ylim=c(0,0.5),
     xlab="T-Value")
for(i in 1:length(ssizes)){
  lines(density(t.list[[i]]),col=cols[i])
}
legend("topleft",as.character(ssizes),lwd=1,col=cols)

barplot(unlist(p.list),main=paste("Number of tests with p<.05 out of ",n,"tests"),
        xlab="Sample Size")

这篇关于我想绘制测试的大小(例如 t test )与样本大小.如何在 R 中进行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆