LinEst in VBA - Dynamic Order of Regression

Ralajer

Active Member
Joined
Jul 24, 2008
Messages
416
I am trying to do something similar to this http://www.mrexcel.com/forum/showthread.php?t=352771
but I want the order the polynomial to be variable.

Here is what the code looks like with the static order equal to 2.
Code:
varDataP = Application.Power(Application.Transpose(arr2), Array(1, 2))
varDataL = Application.LinEst(arr1, Application.Transpose(varDataP))
Testing the the above static form with my input variables it works as it should.

My attempt to make Array() dynamic
Code:
order = 4     ' for testing
ReDim powers(1 to order)

    For i = 1 To order
        powers(i) = i
    Next

varDataP = Application.Power(Application.Transpose(arr2), powers)
varDataL = Application.LinEst(arr1, Application.Transpose(varDataP))

The dimensions appear to be the same for the Array(1,2,...,n) and the powers(1 to n). I've tried transposing the powers variable as well as other configurations and datatypes but I get "Type mis-match" or "Can't assign to array" errors.

A Select Case statement would work as the range is not too large but I would prefer to figure this out.

Thanks
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Thanks but that wasn't the problem. It turns out I confused myself between all the forums and other things a read and cut and paste from. I was using
Code:
Application.WorksheetFunction.power()
instead of
Code:
Application.power()
at different points of my debugging and didn't notice or assumed they were equivalent. Which it turns out the latter works while the former doesn't.

I was using integer but that seems to work fine, having corrected for the above.

My apologies, I'll try to get things straight for myself before posting in the future.
 
Upvote 0

Forum statistics

Threads
1,215,129
Messages
6,123,218
Members
449,091
Latest member
jeremy_bp001

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