单样本 t 检验接受或拒绝
One-Sample t Test Accept or Reject
我有以下列表:
> str1<-'cor 0.9834559 0.9816176 0.9797794 0.9926471'
> df1 <- read.table(text=scan(text=str1, what='', quiet=TRUE), header=TRUE)
> t.test (df1, mu=0.9816176, alternative = "less", conf.level = 0.95)
One Sample t-test
data: df1
t = 0.96491, df = 3, p-value = 0.7971
alternative hypothesis: true mean is less than 0.9816176
95 percent confidence interval:
-Inf 0.9911001
sample estimates:
mean of x
0.984375
我想根据 t 检验得出一个决定:Accept
或 Reject
假设 H0。在这种情况下,因为 p-value > 0.05
我应该接受 H0。
如何自动获取相关结果?
这是一个基于评论的解决方案。它涉及编写一个函数,该函数将从 t 检验中创建的对象中提取相关的 p.value
:
auto <- function(x) {
z <- t.test(x, mu=mean(x), alternative = "less", conf.level = 0.95)
if (z$p.value > 0.05) {
print("ACCEPT H0")
} else {
print("REJECT H0")
}
}
#call the function
auto(df1$cor)
#[1] "ACCEPT H0"
我有以下列表:
> str1<-'cor 0.9834559 0.9816176 0.9797794 0.9926471'
> df1 <- read.table(text=scan(text=str1, what='', quiet=TRUE), header=TRUE)
> t.test (df1, mu=0.9816176, alternative = "less", conf.level = 0.95)
One Sample t-test
data: df1
t = 0.96491, df = 3, p-value = 0.7971
alternative hypothesis: true mean is less than 0.9816176
95 percent confidence interval:
-Inf 0.9911001
sample estimates:
mean of x
0.984375
我想根据 t 检验得出一个决定:Accept
或 Reject
假设 H0。在这种情况下,因为 p-value > 0.05
我应该接受 H0。
如何自动获取相关结果?
这是一个基于评论的解决方案。它涉及编写一个函数,该函数将从 t 检验中创建的对象中提取相关的 p.value
:
auto <- function(x) {
z <- t.test(x, mu=mean(x), alternative = "less", conf.level = 0.95)
if (z$p.value > 0.05) {
print("ACCEPT H0")
} else {
print("REJECT H0")
}
}
#call the function
auto(df1$cor)
#[1] "ACCEPT H0"