import math
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
from scipy.special import chdtri
from collections import defaultdict
%matplotlib inline
defpchisq(q,df,ncp=0):"""Calculates the cumulative of the chi-square distribution"""from scipy.stats import chi2,ncx2if ncp==0:result=chi2.cdf(x=q,df=df,loc=0,scale=1)else:result=ncx2.cdf(x=q,df=df,nc=ncp,loc=0,scale=1)return resultdefqchisq(p,df,ncp=0):"""Calculates the quantile function of the chi-square distribution"""from scipy.stats import chi2,ncx2if ncp==0:result=chi2.ppf(q=p,df=df,loc=0,scale=1)else:result=ncx2.ppf(q=p,df=df,nc=ncp,loc=0,scale=1)return result
defget_power(MAF, beta_alt, count, pvalue=5e-8):# MAF = 0.5# beta_alt = 0.2# count = 2000sigma = math.sqrt(1-2*MAF*(1-MAF)*beta_alt**2)# error sd after SNP effect is accounted for (see next part for explanation)ses = sigma/math.sqrt(count*2*MAF*(1-MAF))# q_thresh = scipy.stats.chi2.ppf(q= 5e-8, df = 1)q_thresh = qchisq(1-pvalue,1)pwr =1- pchisq(q_thresh,1,(beta_alt/ses)**2)return pwr
下面介绍两种方法
1.利用上面性质的第五条,我们可以求各行各列的组合数
2.利用上面性质的第7条,我们可以用数组完成
下面附上代码
1.
#include<stdio.h>
void fact(int n ,int m )//求组合数
{long long int sum11;long long int sum21;int a…