chapter 10 统计检验
1.permutation test
用途:用于检验两组数据是否出生于同一分布
思路:如果产生于同一分布,两组数据混合,重新排列后,计算的基于两组数据的函数值(均值,中位数,方差等,下面程序中使用f指定)应该相差不大
方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | library ( "gtools" );permuTest<- function (g1,g2,f=mean){ tobs<- abs ( f (g1)- f (g2)); lg1<- length (g1); lg2<- length (g2); perms<- combinations (n = lg1+lg2, r = lg1); B<- dim (perms)[1]; tper<-0; data<- c (g1,g2); for (i in 1:B){ tper<-tper+ ifelse ( abs ( f (data[perms[i,]])- f (data[-perms[i,]]))>tobs,1,0); } return (tper/B); } |
2.Benjamini-Hochberg test
用途:给定一组检验p值,在给定显著性水平下,哪些检验应该拒绝
方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | BHTest<- function (p_values,alpha,unrelated=T){ lp<- length (p_values); li<-(alpha/lp)*(1:lp); if (!unrelated){ li<-li/ sum (1/(1:lp)); } sp_values<- sort (p_values); indexs<-1:lp; rejuctIndex<- max (indexs[sp_values<li]); rejuctThres<-sp_values[rejuctIndex]; return (p_values<=rejuctThres) } |
3.比较 wald test 和 likelihood ratio test
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | compareWaldAndLikelihood_mu<- function (n=1000,mu=0,fai=1){ d<- rnorm (n,mu,fai); est_mu<- mean (d); sd<- sd (d); estimator_likelihood<-(n*(mu^2-est_mu^2) + 2* sum (d)*(est_mu-mu))/sd^2; p_likelihood<-1- pchisq (estimator_likelihood,df=1); estimator_wald<- abs (est_mu-mu)*n^0.5/sd; p_wald<-2* pnorm (-estimator_wald,mean=mu,sd=sd); return ( c (p_wald,p_likelihood)); } |
---恢复内容结束---
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步