jnmonroe
08-17-2014, 12:42 PM
Below is a VBA code the Foxes Team developed to determine the rank of a matrix. The VBA is one among several VBA the Foxes Team made available to the public. I would like to be able to make the VBA work as a stand-alone VBA. Sheet 1 in the attached VBA lists 50 measurements (samples) of 4 measurements (column-variables) of the Species Setosa of the Iris Flower Data of Fisher (The use of multi-measurements in taxonomic problems,1931). The fact that the variables are uncorrelated is information we know in advance. Because the variables are uncorrelated the rank of the 50x4 matrix is 4. Sometimes, you don't know in advance that data variables are uncorrelated; in these cases it would help to have a VBA which determines the rank of the matrix. Microsoft's statistical formulas do not include a formula that determines the rank of a matrix.
When I try to run the VBA, a dialog box pops up. The title of the box is "Macro" below this title there is a space expecting me to enter a "Macro Name"
Can anyone suggest what can be done to enable this VBA to run successfully? Ideally, the number "4" should appear somewhere. I know in advance that the rank of the matrix is 4.
Function M_RANK(Mat)
'Returns the rank of a matrix
'ver. 23-6-2002 by L.V.
'Original M_RANK routine by Bernard Wagner, CH (Thanks Bernard)
'
Dim A, At, b, u
Const tiny = 10 ^ -15
A = Mat
N = UBound(A, 1): m = UBound(A, 2) 'get A dimension
'reduce Mat to a square matrix U with the lowest dimension
If N <> m Then
At = M_TRANSP(Mat)
If N < m Then
b = Application.WorksheetFunction.MMult(A, At)
nb = N
Else
b = Application.WorksheetFunction.MMult(At, A)
nb = m
End If
Else
b = A 'nothing to do
nb = N
End If
'compute the sub-space of Ax=0
u = SysLinSing(b, , tiny)
'count null column-vectors of sub-space
Rank = nb
For j = 1 To nb
s = 0: For i = 1 To nb: s = s + Abs(u(i, j)): Next i
If s > tiny Then Rank = Rank - 1
Next j
M_RANK = Rank
End Function
When I try to run the VBA, a dialog box pops up. The title of the box is "Macro" below this title there is a space expecting me to enter a "Macro Name"
Can anyone suggest what can be done to enable this VBA to run successfully? Ideally, the number "4" should appear somewhere. I know in advance that the rank of the matrix is 4.
Function M_RANK(Mat)
'Returns the rank of a matrix
'ver. 23-6-2002 by L.V.
'Original M_RANK routine by Bernard Wagner, CH (Thanks Bernard)
'
Dim A, At, b, u
Const tiny = 10 ^ -15
A = Mat
N = UBound(A, 1): m = UBound(A, 2) 'get A dimension
'reduce Mat to a square matrix U with the lowest dimension
If N <> m Then
At = M_TRANSP(Mat)
If N < m Then
b = Application.WorksheetFunction.MMult(A, At)
nb = N
Else
b = Application.WorksheetFunction.MMult(At, A)
nb = m
End If
Else
b = A 'nothing to do
nb = N
End If
'compute the sub-space of Ax=0
u = SysLinSing(b, , tiny)
'count null column-vectors of sub-space
Rank = nb
For j = 1 To nb
s = 0: For i = 1 To nb: s = s + Abs(u(i, j)): Next i
If s > tiny Then Rank = Rank - 1
Next j
M_RANK = Rank
End Function