如何对R中的总体方差进行一样本卡方检验?

时间:2020-09-02 22:13:40

标签: r statistics variance population

首先,我知道可以使用var.test(x,y)来推断两个总体方差的比率,但是我的问题是关于一个总体方差的推断。

根据此source,我应该使用varTest()函数对总体方差进行一样本测试。但是,每次尝试此操作时都会收到错误代码,因为R找不到此功能:

x <- rnorm(50, mean = 4, sd = 1)
varTest(x, sigma.squared = 1) # sigma.squared is our null hypothesis for population variance
Error in varTest(x, sigma.squared = 1) : 
  could not find function "varTest"

如果我尝试使用var.test()对总体方差进行一个样本测试,则会发生以下情况:

x <- rnorm(50, mean = 4, sd = 1)
var.test(x, sigma.squared = 1)
Error in var.test.default(x, sigma.squared = 1) : 
  argument "y" is missing, with no default

第二个错误不足为奇,因为我认为var.test()仅保留用于推断两个总体方差的比率。

是否应该使用varTest函数,但是我根本没有安装包含该函数的软件包?

背景信息: 我在macOS Catalina版本10.15.6上运行RStudio版本1.3.959 这是我要在R中进行的统计测试的video

1 个答案:

答案 0 :(得分:1)

您链接到的函数是EnvStats软件包的一部分。您需要先安装并加载它,然后才能执行功能:

install.packages("EnvStats")

library(EnvStats)

x <- rnorm(50, mean = 4, sd = 1)
varTest(x, sigma.squared = 1)
#> 
#>  Chi-Squared Test on Variance
#> 
#> data:  x
#> Chi-Squared = 28.224, df = 49, p-value = 0.01506
#> alternative hypothesis: true variance is not equal to 1
#> 95 percent confidence interval:
#>  0.4019175 0.8944284
#> sample estimates:
#>  variance 
#> 0.5759921
相关问题