多项式函数vba的LinEst

问题描述 投票:1回答:1

我正在尝试使用vba计算多项式回归。首先,我尝试了y = x ^ 2 + b:

输出= WorksheetFunction.Application.LinEst(A,Application.Power(C,2),True,True)其中A和C是数组而且输出很好。我可以使用Application.Index(OUTPUT,3)

从OUTPUT中读取r2

但是,当我想通过将Array添加到Array的参数来尝试y = x + x ^ 2 + b时:输出= WorksheetFunction.Application.LinEst(A,Application.Power(C,Array(1,2)),True,True)我无法使用Application.Index(OUTPUT,3)

从OUTPUT中读取r2

任何解决方案?我在做什么错?

excel vba
1个回答
0
投票

尝试关注..

Sub LinEst()
Dim yVal As Range, xVal As Range
Set yVal = Range("C5:C14")
Set xVal = Range("B5:B14")

'You tried following formula which gives incorrect results for polynomial order 2
Range("B17") = Application.Index(WorksheetFunction.LinEst(yVal, _
                Application.Power(xVal, 2), True, True), 3)

'For linear
Range("B18") = Application.Index(WorksheetFunction.LinEst(yVal, _
                xVal, True, True), 3)
'For polynomial order 2
Range("B19") = Application.Index(WorksheetFunction.LinEst(yVal, _
                Application.Power(xVal, Array(1, 2)), True, True), 3)
'For polynomial order 3
Range("B20") = Application.Index(WorksheetFunction.LinEst(yVal, _
                Application.Power(xVal, Array(1, 2, 3)), True, True), 3)

End Sub
© www.soinside.com 2019 - 2024. All rights reserved.