LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Adjusted R Squared with VBA

I have two functions I've written to calculate adjusted r-squared.
The notes in the function headers tell the limitations of each. An ideal
solution would be one ADJRSQ function that works with non-contiguous X
variables AND can handle multiple regressions.

Any help is greatly appreciated. I'm thinking it can't be done, but maybe
someone out there has an idea.

Thanks!
-Jeremy

==================================================
Function ADJRSQ(Ys As Range, Xs As Range)
'Calculates Adjusted R-squared and functions exactly
'like the native RSQ function. i.e.- doesn't need
'contiguous data or even data on the same worksheet.
'Will not work with multiple Xs.

Dim Rsquare As Double
Dim MaxCount As Long

On Error GoTo FoundError
With Application.WorksheetFunction
MaxCount = .Count(Ys)
If .Count(Xs) < MaxCount Then MaxCount = .Count(Xs)
Rsquare = .RSq(Ys, Xs)
ADJRSQ = 1 - (MaxCount - 1) * (1 - Rsquare) / (MaxCount - 2)
End With
Exit Function

FoundError:
ADJRSQ = CVErr(xlErrValue)

End Function

Function ADJRSQ_Mult(Ys As Range, Xs As Range)
'Calculates Adjusted R-square for multiple regressions.
'Limited functionality just like the native Analysis Toolpak
'regression analysis; data must be on same sheet and contiguous.

Dim ErrorTerm As Double

On Error GoTo FoundError
With Application.WorksheetFunction
ErrorTerm = .Index(.LinEst(Ys, Xs, , True), 3, 2)
ADJRSQ_Mult = 1 - (ErrorTerm / .StDev(Ys)) ^ 2
End With
Exit Function

FoundError:
ADJRSQ_Mult = CVErr(xlErrValue)

End Function
==================================================



 
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
adjusted scores tab anibal lozada Excel Discussion (Misc queries) 1 December 2nd 08 12:52 PM
Cash Flows Inflation Adjusted Jes Johansen Excel Worksheet Functions 2 December 1st 08 06:11 PM
Adjusted Closing Price formula Fred Smith[_4_] Excel Worksheet Functions 1 February 13th 08 04:50 PM
Adjusted for inflation wages? Crackles McFarly Excel Worksheet Functions 10 January 2nd 08 10:27 PM
Can this adjusted GPA formual be accomplised? Chris Cred via OfficeKB.com Excel Discussion (Misc queries) 1 January 19th 06 01:59 PM


All times are GMT +1. The time now is 12:22 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"