R可以将t.test或其他假设检验结果可视化吗?

All*_* Xu 6 r hypothesis-test

我需要在R中进行许多假设检验并提出结果.这是一个例子:

> library(MASS)
> h=na.omit(survey$Height)
> 
> pop.mean=mean(h)
> h.sample = sample(h,30)
> 
> t.test(h.sample,mu=pop.mean)

    One Sample t-test

data:  h.sample
t = -0.0083069, df = 29, p-value = 0.9934
alternative hypothesis: true mean is not equal to 172.3809
95 percent confidence interval:
 168.8718 175.8615
sample estimates:
mean of x 
 172.3667 
Run Code Online (Sandbox Code Playgroud)

有没有什么方法可以将t.test或其他假设检验结果可视化?

以下是我正在寻找的一个例子:

在此输入图像描述

jus*_*618 5

你可以做很多事情.这里只是我从标准正态分布中抽取随机样本,然后进行t检验,绘制观察到的t和t所需的t,以拒绝平均值等于0的零假设.

N=20 #just chosen arbitrarily
samp=rnorm(N)
myTest=t.test(samp)
tcrit=qt(0.025, df=(N-1))

dum=seq(-3.5, 3.5, length=10^4)#For the plot

plot(dum, dt(dum, df=(N-1)), type='l', xlab='t', ylab='f(t)')
abline(v=myTest$statistic, lty=2)
abline(v=tcrit, col='red', lty=2)
abline(v=-tcrit, col='red', lty=2)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

当然,每次重新运行此代码时,您观察到的t都会有所不同,如果重复运行,这可能会很好地说明.


aki*_*kis 3

还有gginference 包

library(MASS)
h=na.omit(survey$Height)
pop.mean=mean(h)
h.sample = sample(h,30)
t.test(h.sample,mu=pop.mean)

library(gginference)
ggttest(t.test(h.sample,mu=pop.mean))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述