Perform multipli regression with VBA

Prack

New Member
Joined
Feb 27, 2011
Messages
7
Hi, I'm trying to obtain one coefficient and its error term out of a multiple regression (linest) starting from a single series of data and using only VBA. This is the code I've written and that doesn't work. I believe my problem is determining the range data on which the regression is to be performed. Any help is more than welcome!

Function MultipleRegression(Series As Range)
n = Series.Rows.Count
Dim y(1 To n), x(1 To n, 2) As Variant
For i = 1 To n
y(i) = Series(i + 1) - Series(i)
x(i, 1) = Series(i + 2) - Series(i + 1)
x(i, 2) = Series(i + 3) - Series(i + 2)
Next i
Set y = Range(y(1), y(n))
Set x = Union(Range(x(1, 1), x(n, 1)), Range(x(1, 2), x(n, 2)))
Coefficient = Application.WorksheetFunction.Index(Application.WorksheetFunction.LinEst(y, x, True, True), 1, 1)
CoefficientError = Application.WorksheetFunction.Index(Application.WorksheetFunction.LinEst(y, x, True, True), 2, 1)
Result = Coefficient / CoefficientError
MultipleRegression = Result
End Function
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,224,585
Messages
6,179,706
Members
452,939
Latest member
WCrawford

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