Dear all.
I am reading a book "Credit: risk modeling using excel and vba" and came across the code below (only part of it) that creates a function for logistic regression.
I have some understanding about VBA but I have never used matrix and it seems that the code starts to create a dummy matrix, please correct me if I am wrong.
I don't understand why it addresses y and xrow to the variables N and K respectively, then in the end it passes the values of xraw(I, j - constant) to the matrix x.
I understand the part of addressing 1 to the matrix x in order to have the interception what I am not too sure is about the value of the other columns. Is it to be set as 1 as well?
Also at this stage n and K have no value addressed to it isn't it?
_________________________________________________________________________________________________________
Function logit(y As Range, xraw As Range, Optional constant, Optional stats)
If IsMissing(constant) Then constant = 1
If IsMissing(stats) Then stats = 0
'Count variables
Dim i As Integer, j As Integer, jj As Integer
'Read data dimensions
Dim K As Integer, N As Integer
N = y.Rows.Count
K = xraw.Columns.Count + constant
'Some error checking
If xraw.Rows.Count <> N Then MsgBox "error"
'Adding a vector of ones to the x matrix if constant=1, name xraw=x from now on
Dim x() As Double
ReDim x(1 To N, 1 To K)
For i = 1 To N
x(i, 1) = 1
For j = 1 + constant To K
x(i, j) = xraw(i, j - constant)
Next j
Next I
I am reading a book "Credit: risk modeling using excel and vba" and came across the code below (only part of it) that creates a function for logistic regression.
I have some understanding about VBA but I have never used matrix and it seems that the code starts to create a dummy matrix, please correct me if I am wrong.
I don't understand why it addresses y and xrow to the variables N and K respectively, then in the end it passes the values of xraw(I, j - constant) to the matrix x.
I understand the part of addressing 1 to the matrix x in order to have the interception what I am not too sure is about the value of the other columns. Is it to be set as 1 as well?
Also at this stage n and K have no value addressed to it isn't it?
_________________________________________________________________________________________________________
Function logit(y As Range, xraw As Range, Optional constant, Optional stats)
If IsMissing(constant) Then constant = 1
If IsMissing(stats) Then stats = 0
'Count variables
Dim i As Integer, j As Integer, jj As Integer
'Read data dimensions
Dim K As Integer, N As Integer
N = y.Rows.Count
K = xraw.Columns.Count + constant
'Some error checking
If xraw.Rows.Count <> N Then MsgBox "error"
'Adding a vector of ones to the x matrix if constant=1, name xraw=x from now on
Dim x() As Double
ReDim x(1 To N, 1 To K)
For i = 1 To N
x(i, 1) = 1
For j = 1 + constant To K
x(i, j) = xraw(i, j - constant)
Next j
Next I