假设检验-方差齐性检验

版权声明:本人博文一律不许转载,如发现转载,需负法律责任 https://blog.csdn.net/qq_38984677/article/details/82730172

传送:随机变量概率分布函数汇总-离散型分布+连续型分布

            假设检验-KS检验

            假设检验-W检验

            假设检验-单样本t检验

            假设检验-两服从正态分布的独立总体均值检验

一、单样本方差检验-需服从正态分布 

chisq.var.test=function(x,var,mu=Inf,alternative="two.sided"){
		n=length(x)
		df=n-1	#均值未知-自由度
		v=var(x)	#均值未知-样本方差
		#当总体均值已知时
		if (mu<Inf) {df=n;v=sum((x-mu)^2)/n}
		chi2=df*v/var	#卡方统计量
		result=list()
		result$df=df;result$var=v;result$chi2=chi2
		result$P=2*min(pchisq(chi2,df),pchisq(chi2,df,lower.tail=FALSE))
		#针对单侧检验-需要重新计算P值
		if (alternative=="greater") result$P=pchisq(chi2,df,lower.tail=FALSE)
		else if (alternative="less") result$P=pchisq(chi2,df)
		result
	}

二、两总体方差检验-需服从正态分布

#方差齐性检验(F检验,双侧检验)判断方差是否相等(原假设为方差相等)
#alternative hypothesis: true ratio of variances is not equal to 1(R打印出的是备选假设)
var.test(x1,x2,conf.level=0.95)
var.test(incomes[sex=="男"],incomes[sex=="女"])

三、多样本方差齐性检验

1.正态分布样本

bartlett.test(x,g,...)
#x-数据向量或列表,g-因子向量(当x为list时忽略g)

bartlett.test(formula,data,subset,na.action,...)	#formula-方差分析公式,subset-
指定观测值的子集用于分析
x<-c(x1,x2,x3)
accout<-data.frame(x=x,A=factor(rep(c(1,2,3),each=7)))
bartlett.test(x~A,data=accout)

2.正态分布、非正态分布或分布不明样本

library("car")
#levene.test(x,group),原假设:不同水平下样本的来源总体是等方差的

猜你喜欢

转载自blog.csdn.net/qq_38984677/article/details/82730172