7

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 

t.test やその他の仮説検定の結果を視覚化する方法はありますか?

以下は、私が探しているものの例です。

ここに画像の説明を入力

4

6 に答える 6

0

推定値と 95% 信頼区間を使用して、多くの仮説検定の結果を視覚化する 1 つの方法を次に示します。TukeyHSD()プロット方法から直接アイデアを取り入れましたが、 で実装しましたggplot2htest残念ながら、 R には結果のプロット方法が組み込まれていません。

library(MASS)
library(ggplot2)

h = na.omit(survey$Height)
pop.mean = mean(h)

n_reps = 20
sample_size = 30
res_list = list()

for (i in 1:n_reps) {
    h.sample = sample(h, sample_size)
    res_list[[i]] = t.test(h.sample, mu=pop.mean)
}

dat = data.frame(id=seq(length(res_list)),
                 estimate=sapply(res_list, function(x) x$estimate),
                 conf_int_lower=sapply(res_list, function(x) x$conf.int[1]),
                 conf_int_upper=sapply(res_list, function(x) x$conf.int[2]))

p = ggplot(data=dat, aes(x=estimate, y=id)) +
    geom_vline(xintercept=pop.mean, color="red", linetype=2) +
    geom_point(color="grey30") +
    geom_errorbarh(aes(xmin=conf_int_lower, xmax=conf_int_upper), 
                   color="grey30", height=0.4)

ggsave("CI_plot.png", plot=p, height=4, width=6, units="in", dpi=150)

ここに画像の説明を入力

于 2016-04-08T22:46:24.940 に答える
-1

探していると思います

t <- t.test(h.sample,mu=pop.mean)
t$conf.int[2] # the t-statistic value (pink circle in your image)
t$p.value

使用する

str(t)

使用可能なすべてのパラメーターを表示します。

于 2016-04-08T19:58:49.680 に答える