tags:

views:

22

answers:

0

In Visual Basic within STATISTICA (a stats program), I am trying to run "LOWESS," an existing STATISTICA Matrix Library Function. I have defined my arrays based on the number of rows and columns I either know or expect they should have. Unfortunately, my macro gets an error of "(10025) Array has different number of indexes" when running the pre-made function. Here is my code:

Sub Main
>'Define Arrays
    Dim ArrayX() As Double
    Dim ArrayY() As Double
    Dim MainArray() As Double
    Dim Xs() As Double
    Dim Ys() As Double
    Dim Rw() As Double
    Dim Res() As Double
    ReDim ArrayX(65,1)
    ReDim ArrayY(65,1)
    ReDim MainArray(80,9)
    ReDim Xs(65,1)
    ReDim Ys(65,1)
    ReDim Rw(65,1)
    ReDim Res(65,1)
>'Bring In Rainfall And streamflow datafile
    MatrixReadFromDataFile("G:\02425\014\W970\Statistics\Rainfall LOWESS Analysis\Rainfall_LOWESS.sta",0,0,0,0,MainArray())
>'Create X and Y vectors for LOWESS, using only years they have in common
    MATRIXCOPY(MainArray(), 16, 3, 65, 1, ArrayX(), 1, 1)
    MATRIXCOPY(MainArray(), 16, 4, 65, 1, ArrayY(), 1, 1)
>'The LOWESS function will perform robust locally weighted regression and smoothing for 2D scatterplot data '(pairs of x and y data).
    LOWESS (ArrayX(), ArrayY(), .5, 2, 0, Xs(), Ys(), Rw(), Res())
End Sub

Here is the code for the pre-made function "LOWESS". The error comes in the "ec = STBLOWESS" line.

Function LOWESS (ByRef x() As Double, ByRef Y() As Double, _
             ByVal f As Double, ByVal nsteps As Long, ByVal delta As Double, _
             ByRef Xs() As Double, ByRef Ys() As Double, ByRef Rw() As Double, ByRef Res() As Double) As Integer
Dim d1 As Long, d2 As Long, d3 As Long, d4 As Long, d5 As Long, d6 As Long
Dim ec As Integer
d1 = UBound(x,1)-LBound(x,1)+1
d2 = UBound(Y,1)-LBound(Y,1)+1
d3 = UBound(Xs,1)-LBound(Xs,1)+1
d4 = UBound(Ys,1)-LBound(Ys,1)+1
d5 = UBound(Rw,1)-LBound(Rw,1)+1
d6 = UBound(Res,1)-LBound(Res,1)+1
ec = STBLOWESS (x(LBound(x)), Y(LBound(Y)), f, nsteps, delta, Xs(LBound(Xs)), _
                Ys(LBound(Ys)), Rw(LBound(Rw)), Res(LBound(Res)), d1, d2, d3, d4, d5, d6)
If ec = 0 Then
    DisplaySTBError
End If
LOWESS = ec
End Function

Thank you very much for your help.