Matrix

R2learn

New Member
Joined
May 15, 2018
Messages
2
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
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top