- 积分
- 2368
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-10-10
- 最后登录
- 1970-1-1
|

楼主 |
发表于 2011-12-8 15:10:56
|
显示全部楼层
这里是有关MK检验的代码- class Mann_Kendall
- {
- private float[] _myUF;
- private float[] _myUB;
- public float[] UF
- { get { return _myUF; } }
- public float[] UB
- { get { return _myUB; } }
- public Mann_Kendall(List<float> list)
- {
- float[] myArry = list.ToArray();
- list.Reverse();
- float[] myRevArry = list.ToArray();
- CalculateUF(myArry);
- CalculateUB(myRevArry);
- }
- public Mann_Kendall(float[] arry)
- {
- float[] tempArry = new float[arry.Length];
- Array.Copy(arry, tempArry, arry.Length);
- Array.Reverse(tempArry);
- CalculateUF(arry);
- CalculateUB(tempArry);
- }
- private void CalculateUF(float[] x)
- {
- _myUF = GetResult(x);
- }
- private void CalculateUB(float[] x)
- {
- float[] result = GetResult(x);
- List<float> listUB = new List<float>();
- foreach (float item in result.Reverse())
- {
- listUB.Add(-item);
- }
- _myUB = listUB.ToArray();
- }
- private float[] GetResult(float[] x)
- {
- List<int> listR = new List<int>();
- for (int i = 0; i < x.Length; i++)
- {
- int sum = 0;
- for (int j = 0; j <= i; j++)
- {
- sum = x[i] > x[j] ? sum + 1 : sum;
- }
- listR.Add(sum);
- }
- float[] U = new float[listR.Count];
- for (int i = 0; i < listR.Count; i++)
- {
- if (i == 0)
- { U[i] = 0; }
- else
- {
- int s = 0, n = i + 1;
- float e = 0, var = 0;
- e = n * (n - 1) / 4f;
- var = n * (n - 1) * (2 * n + 5) / 72f;
- for (int j = 0; j <= i; j++)
- {
- s = s + listR[j];
- }
- U[i] = Convert.ToSingle(Math.Round((s - e) / Convert.ToSingle(Math.Sqrt(Convert.ToDouble(var))), 2));
- }
- }
- return U;
- }
- }
复制代码 |
|