Polynomial regression in VBA

datanewb

Board Regular
Joined
May 8, 2009
Messages
76
Hey there,

I have two arrays of data on which I would like to be able to run a polynomial regression in VBA.

However, when write the following in VBA:

Code:
Dim poly_3 as Variant
Dim arr1 as Variant
Dim arr2 as Variant
 
poly_3 = WorksheetFunction.LinEst(arr1, my_arr2 ^ {1, 2, 3})

I get a compile error, as {} are not valid characters. I've tried substituting parenthesis and leaving the brackets out completely, but that does not work either.

Anyone know how to perform a polynomial regression in VBA?

Working with two ranges of cells in a worksheet, the Linest function works just fine. ie, =LINEST(H18:H34, G18:G34^{1,2,3}), so I don't know why it would not be the same in VBA.



Office 2007
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
you might try declaring the size of your two arrays arr1 and arr2, and also breaking out {1,2,3} as a separate array, and including the array name in your formula?
 
Upvote 0
Right, sorry for posting incomplete code. I should have left the declarations out completely for the sake of simplicity. It was careless of me to quickly include them with the errors you mentioned. Please forget about the array declarations.

The problem is figuring out how to do a polynomial regression in VBA.

The following line of code does not work.
Code:
poly_3 = WorksheetFunction.LinEst(new_array, my_array ^ {1, 2, 3})

I think you are on to the answer. The {1,2,3} needs to be a separate array.
 
Upvote 0

Forum statistics

Threads
1,214,639
Messages
6,120,679
Members
448,977
Latest member
dbonilla0331

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