- 积分
- 11
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2012-9-11
- 最后登录
- 1970-1-1
|
发表于 2014-3-11 12:02:34
|
显示全部楼层
本帖最后由 唐果果 于 2014-3-11 12:05 编辑
我来贴个Excel中VB的宏吧,这个简单。
Const k = 10
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''m-k方法
Dim i, j As Integer
Dim countn As Integer
Dim sk As Integer
''''数据序号
For i = 2 To k + 1
Sheet5.Cells(i, 3) = i - 1
Next i
'''''计算顺序ri
For i = 2 To k + 1
countn = 0
For j = 2 To i
If Sheet5.Cells(i, 2) > Sheet5.Cells(j, 2) Then
countn = countn + 1
End If
Sheet5.Cells(i, 4) = countn
Next j
Next i
''''''''''逆序数据
For i = 2 To k + 1
Sheet5.Cells(i, 9) = Sheet5.Cells(k + 3 - i, 2)
Next i
'''''''''''计算逆序ri
For i = 2 To k + 1
countn = 0
For j = 2 To i
If Sheet5.Cells(i, 9) > Sheet5.Cells(j, 9) Then
countn = countn + 1
End If
Sheet5.Cells(i, 12) = countn
Next j
Next i
'''''''''''计算sk
For i = 2 To k + 1
a = CStr(i)
Sheet5.Cells(i, 5) = "=sum(D2:D" + a + ")" '顺序
Sheet5.Cells(i, 13) = "=sum(L2:L" + a + ")" '逆序
Next i
'''''''''''''''计算均值和方差
For i = 2 To k + 1
a = CStr(i)
Sheet5.Cells(i, 6) = (i - 1) * (i - 2) / 4 '顺序
Sheet5.Cells(i, 7) = (i - 1) * (i - 2) * (2 * (i - 1) + 5) / 72 '顺序
Sheet5.Cells(i, 10) = (i - 1) * (i - 2) / 4 '逆序
Sheet5.Cells(i, 11) = (i - 1) * (i - 2) * (2 * (i - 1) + 5) / 72 '逆序
Next i
''''计算UF
Sheet5.Cells(2, 8) = 0
Sheet5.Cells(2, 14) = 0
For i = 3 To k + 1
Sheet5.Cells(i, 8) = (Sheet5.Cells(i, 5) - Sheet5.Cells(i, 6)) / Sheet5.Cells(i, 7) ^ 0.5
Sheet5.Cells(i, 14) = (Sheet5.Cells(i, 13) - Sheet5.Cells(i, 10)) / Sheet5.Cells(i, 11) ^ 0.5
Next i
''''''计算ub
For i = 2 To k + 1
Sheet5.Cells(i, 15) = -Sheet5.Cells(k + 3 - i, 14)
Next i
数据的格式基本如下:
年份 | 数据 | 1981 | 49.5 | 1982 | 44.3 | 1983 | 46.1 | 1984 | 42.1 | 1985 | 42.7 | 1986 | 47.4 | 1987 | 53.2 | 1988 | 47.1 | 1989 | 41.6 | 1990 | 44.4 |
|
|