Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default VBA Linest function for polynomial regression on horizontal range

Hello,
I made a function to calculate values and derivatives of polynomial
trends. It works perfect on vertical X en Y ranges but not on
horizontal ranges. I use the Dutch version of Excel 2007. Any ideas
what could clear the problem? I'll be very gratefull.

It goes like this :

Function Polytrend(Xas, Yas, Punt, Graad, ResultType, Optional Per) As
Double
Dim a6 As Double, a5 As Double, a4 As Double, a3 As Double, a2 As
Double, a1 As Double, a0 As Double
Dim Res1 As Double, Res2 As Double
Dim varr()
If IsMissing(Per) Or Per = 0 Then Per = 1
Select Case Graad
Case Is = 1
varr = Evaluate("LINEST(" & Yas.Address & "," & Xas.Address &
"^{1})")
a6 = 0: a5 = 0: a4 = 0: a3 = 0: a2 = 0
a1 = varr(1): a0 = varr(2)
Case Is = 2
varr = Evaluate("LINEST(" & Yas.Address & "," & Xas.Address &
"^{1,2})")
a6 = 0: a5 = 0: a4 = 0: a3 = 0
a2 = varr(1): a1 = varr(2): a0 = varr(3)
Case Is = 3
varr = Evaluate("LINEST(" & Yas.Address & "," & Xas.Address &
"^{1,2,3})")
a6 = 0: a5 = 0: a4 = 0
a3 = varr(1): a2 = varr(2): a1 = varr(3): a0 = varr(4)
Case Is = 4
varr = Evaluate("LINEST(" & Yas.Address & "," & Xas.Address &
"^{1,2,3,4})")
a6 = 0: a5 = 0
a4 = varr(1): a3 = varr(2): a2 = varr(3): a1 = varr(4): a0 =
varr(5)
Case Is = 5
varr = Evaluate("LINEST(" & Yas.Address & "," & Xas.Address &
"^{1,2,3,4,5})")
a6 = 0
a5 = varr(1): a4 = varr(2): a3 = varr(3): a2 = varr(4): a1 =
varr(5): a0 = varr(6)
Case Is = 6
varr = Evaluate("LINEST(" & Yas.Address & "," & Xas.Address &
"^{1,2,3,4,5,6})")
a6 = varr(1): a5 = varr(2): a4 = varr(3): a3 = varr(4): a2 =
varr(5): a1 = varr(6): a0 = varr(7)
End Select
Polytrend = a6 * Punt ^ 6 + a5 * Punt ^ 5 + a4 * Punt ^ 4 + a3 * Punt
^ 3 + a2 * Punt ^ 2 + a1 * Punt + a0


End Function
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
polynomial regression Lucile Excel Programming 4 January 16th 09 02:06 AM
polynomial regression Gary''s Student Excel Programming 1 January 9th 09 04:44 PM
Quadratic Polynomial fit with LINEST() SamCar Excel Programming 3 March 22nd 07 07:05 PM
Automating Polynomial Order Selection in Linest Nick Flyger Excel Worksheet Functions 3 October 4th 06 09:51 AM
using linest to generate 3rd order polynomial coefficients Incoherent Excel Worksheet Functions 4 September 14th 05 02:57 PM


All times are GMT +1. The time now is 10:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"