从t检验中得出t分布?

时间:2017-01-04 17:47:49

标签: r

是否可以为两个样本t检验制作t分布图,如下图: enter image description here
我的意思是在做了t测试之后我希望以上图的形式进行可视化。

> A
[1] -0.2657783 -0.1655625 -0.3254466
> B
[1] -2.824755 -2.889368
> t.test(A,B)

    Welch Two Sample t-test

data:  A and B
t = 45.906, df = 2.9989, p-value = 2.283e-05
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 2.424183 2.785415
sample estimates:
 mean of x  mean of y 
-0.2522625 -2.8570614 

有人发布了一个答案并且不幸地将其删除了,但是这使我接受了这个代码(正在工作)。我必须添加a function, or a call or an expression containing 'x'但是我不明白我必须在x变量中添加什么内容?

# generate data
a <- rnorm(mean(A), sd(A),1000)
b <- rnorm(mean(B), sd(B),1000)

# plot data
curve(dnorm(x, mean(A), sd(A)), from=-4, to=1, ylab="f(x)")
curve(dnorm(x, mean(B), sd(B)), from=-4, to=1, add=TRUE, col="red")

# add vertical lines
abline(v=c(mean(A), mean(B)), col=c("black", "red"))

1 个答案:

答案 0 :(得分:0)

仅使用基本曲线,假设 df=25:

x  <- function(x) dt(x, df=25)
y  <- function(x) dt(x + 0.2, df=25) # shift "mean"

curve(x, -3, 3, ylab="dt(df=25)", col="blue" )
curve(y, -3, 3,  col="red", add = TRUE)