执行一个给定均值和标准差的单样本 t 检验。

huangapple go评论63阅读模式
英文:

Performing one sample t test with given mean and sd

问题

我正在尝试执行一个已知均值和标准差的单样本 t 检验。

样本均值为 100.5
总体均值为 100
总体标准差为 2.19
样本大小为 50。

尽管使用数据表执行 t 检验相对简单,但我不知道如何使用给定的数据执行 t 检验。

编写这段代码的最简单方式是什么?

我想要获得我的 t 检验值、自由度值和 p 值,就像 t.test() 函数提供的结果一样。

我看到另一篇与此类似的帖子,但没有提供任何解决方案。

我找不到关于如何执行已知均值和标准差的单样本 t 检验的解释。

英文:

I'm trying to perform a one sample t test with given mean and sd.

Sample mean is 100.5
population mean is 100
population standard deviation is 2.19
and sample size is 50.

although it is relatively simple to perfrom a t-test with a datasheet, I don't know how to perform a t test with given data.

What could be the easiest way to write this code?

I would like to get my t test value, df value and my p-value just like what the code t.test() gives you.

I saw another post similar to this. but it didn't have any solutions.

I couldn't find any explanation for performing one sample t test with given mean and sd.

答案1

得分: 0

由于人口参数已知(μ=100,σ=2.19),且样本大小大于30(n=50),可以执行z-检验t-检验。然而,基础的R语言没有进行z-检验的函数。在BSDA包(Arnholt和Evans,2017)中有一个z.test()函数:

library(BSDA)
z.test(
     x = sample_data # 你的样本值向量
    ,y= NULL # 因为你在执行单样本检验
    ,alternative = "two.sided"
    ,mu = 100 # 在零假设中指定
    ,sigma.x = 2.19
)

类似地,可以使用基础R函数t.test()执行t-检验:

t.test(sample_data
       , mu=100
       , alternative = "two-sided"
)

问题是,我们应该考虑哪个检验来解释我们的结果呢?

  • z-检验只是一个近似检验(即数据只是大致服从正态分布),不像t-检验,因此如果在z-检验和t-检验之间有选择,建议选择t-检验(由Michael J Crawley和同事编写的《R语言之书》)。
  • 在选择单侧或双侧检验时也很重要,如果μ和μ0之间的差异未知,则应使用双侧检验。否则,使用单侧检验。

希望这能帮助你。

英文:

Since the parameters of the population is known (mu=100, sigma=2.19) and your sample size is greater than 30 (n=50), it is possible to perform either z-test or t-test. However, the base R doesn't have any function to do z-test. There is a z.test() function in the package BSDA (Arnholt and Evans, 2017):

library(BSDA)
z.test (
      x = sample_data # a vector of your sample values
     ,y= NULL # since you are performing one-sample test
     ,alternative = "two.sided"
     ,mu = 100 # specified in the null hypothesis
     ,sigma.x = 2.19
)

Similarly the t.test can be performed using base R function t.test():

t.test(sample_data
       , mu=100
       , alternative = "two-sided"
 )

The question is that which test we might consider to interpret our result?

  • The z-test is only an approximate test (i.e. the data will only be approximately Normal), unlike the t-test, so if there is a choice between a z-test and a t-test, it is recommended to choose t-test (The R book by Michael J Crawley and colleagues).
  • Also choosing between one-sided or two-sided is important,If
    the difference between μ and μ0 is not known, a two-sided
    test should be used. Otherwise, a one-sided test is used.

Hope this could helps.

huangapple
  • 本文由 发表于 2023年2月14日 08:16:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75442354.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定