这篇教程python如何实现MK突变检验方法,代码复制修改可用写得很实用,希望能帮到您。
需求已知年份和历年最大冻土深度,计算最大冻土深度Mk突变检验。
原理
工具和语言
代码过程
定义函数def mktest(inputdata): import numpy as np inputdata = np.array(inputdata) n=inputdata.shape[0] Sk = np.zeros(n) UFk = np.zeros(n) r = 0 for i in range(1,n): for j in range(i): if inputdata[i] > inputdata[j]: r = r+1 Sk[i] = r E = (i+1)*i/4 Var = (i+1)*i*(2*(i+1)+5)/72 UFk[i] = (Sk[i] - E)/np.sqrt(Var) Sk2 = np.zeros(n) UBk = np.zeros(n) inputdataT = inputdata[::-1] r = 0 for i in range(1,n): for j in range(i): if inputdataT[i] > inputdataT[j]: r = r+1 Sk2[i] = r E = (i+1)*(i/4) Var = (i+1)*i*(2*(i+1)+5)/72 UBk[i] = -(Sk2[i] - E)/np.sqrt(Var) UBk2 = UBk[::-1] return UFk, UBk2定义函数计算变量```pythondef mktest(inputdata): import numpy as np inputdata = np.array(inputdata) n=inputdata.shape[0] s = 0 Sk = np.zeros(n) UFk = np.zeros(n) for i in range(1,n): for j in range(i): if inputdata[i] > inputdata[j]: s = s+1 else: s = s+0 Sk[i] = s E = (i+1)*(i/4) Var = (i+1)*i*(2*(i+1)+5)/72 UFk[i] = (Sk[i] - E)/np.sqrt(Var) Sk2 = np.zeros(n) UBk = np.zeros(n) s = 0 inputdataT = inputdata[::-1] for i in range(1,n): for j in range(i): if inputdataT[i] > inputdataT[j]: s = s+1 else: s = s+0 Sk2[i] = s E = (i+1)*(i/4) Var = (i+1)*i*(2*(i+1)+5)/72 UBk[i] = -(Sk2[i] - E)/np.sqrt(Var) UBk2 = UBk[::-1] return UFk, UBk2
导入变量 ,形成突变检验图 |