Range anyname.Columns .count

piresmdb

Board Regular
Joined
Feb 3, 2011
Messages
67
Dear all

I am trying to understand the logit regression code below and although it is a function I tried to run step by step as a sub to understand it. the xraw and y ranges in this context doesn't work, it gives me an error. then I've replaced the N and K by:

N = Cells(Rows.Count, 1).End(xlUp).Row
K = Cells(1, Columns.Count).End(xlToLeft).Column + constant

The first step is to create a vector of ones (1) when it goes to xraw(i, j - constant) it gives me an error
Also shall I state that constant is = 1?

Could you please advise?

__________________________________________________________________________________________



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

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
You haven't said what error you're getting, but I'm guessing it's a Run Time Error 9: Subscript out of Range.

It's also not clear from your post whether you're using:
Code:
N = y.Rows.Count
'or
[COLOR=#333333]N = Cells(Rows.Count, 1).End(xlUp).Row[/COLOR]

But either way, given you've got

Code:
For i = 1 To N
    '...
    x(i, j) = xraw(i, j - constant)

then you need xraw to have at last N rows. My guess is that the xraw you're passing to the function has less than N rows?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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