+ Reply to Thread
Results 1 to 2 of 2

Regression formula with more than 16 variables; need help with r-square, standard errors

  1. #1
    Registered User
    Join Date
    10-16-2018
    Location
    MD, United States
    MS-Off Ver
    2010, 2016
    Posts
    1

    Regression formula with more than 16 variables; need help with r-square, standard errors

    O.K. first post here.
    I was finally upset enough with Excel's 16 variable limit that I have attempted to create a formula that lets one use more than 16 variables. Here it is. Please feel free to suggest improvements to my code.
    I need help with r-squared, and standard errors.
    So if anyone else has already created formulas for r-squared or standard errors for each beta, it would be great if you shared some tips for that code.

    > Formula brings back an array. Variables in different columns.
    > Example: Y variable in cells A11:A562; X variables in cells B11:BL562 (1st X variable has to be all ones (1) to calculate the intercept, b0).
    Visually: (notice the column of 1s):
    Y X variables
    54 1 12 16...
    12 1 80 10
    15 1 79 8
    18 1 10 71
    84 1 15 56
    64 1 13 32
    ...
    > In cells B1 to BL1, one would have the following array based on the formula below: {=regression(A11:A562,B11:BL562)}

    ################
    Function regression(Yvar As Object, Xvar As Object) As Variant

    Dim n, i, j As Integer
    Dim a() As Double

    n = Yvar.Rows.Count
    ReDim a(1 To n, 1)
    For i = 1 To n
    a(i, 1) = Yvar.Cells(i, 1).Value
    Next i

    Dim nn, ii, jj, oo As Integer
    Dim aa() As Double

    nn = Xvar.Rows.Count
    oo = Xvar.Columns.Count
    ReDim aa(1 To nn, 1 To oo)
    For ii = 1 To nn
    For jj = 1 To oo
    aa(ii, jj) = Xvar.Cells(ii, jj).Value
    Next jj
    Next ii

    regression = WorksheetFunction.Transpose(WorksheetFunction.MMult(WorksheetFunction.MInverse(WorksheetFunction.MMult(WorksheetFunction.Transpose(Xvar), Xvar)), WorksheetFunction.MMult(WorksheetFunction.Transpose(Xvar), Yvar)))

    End Function
    ################

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,814

    Re: Regression formula with more than 16 variables; need help with r-square, standard erro

    This forum can be pretty strict about rules -- like putting code inside of code tags (https://www.excelforum.com/misc.php?do=bbcode ). You should edit your post to include them.

    How much of this question is specific to Excel, and how much is a more generic stats "how does anyone using any programming language compute these quantities." If it is the latter, I recommend reviewing some statistics tutorials to understand how these quantities are calculated. For example, this Wikipedia page has a matrix formula for computing the multiple correlation coefficient: https://en.wikipedia.org/wiki/Multiple_correlation

    Do you need to perform these additional calculations as part of the same UDF, or would it be easier to perform the additional calculations in separate UDFs (or even using Excel's built in functions)?
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Power regression - standard error values
    By David2017 in forum Excel General
    Replies: 8
    Last Post: 02-26-2017, 01:52 PM
  2. multiple variables regression
    By plumberef in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-19-2012, 02:06 AM
  3. What is the function to calculate standard errors of the mean?
    By Steph in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-17-2006, 09:45 AM
  4. regression lines and r-square in work sheets instead of charts
    By Mathematically challenged in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 12-01-2005, 10:10 PM
  5. [SOLVED] Regression - Standard Error X Variable 1
    By Claude S in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-19-2005, 06:15 AM
  6. Replies: 1
    Last Post: 10-24-2005, 08:05 PM
  7. [SOLVED] Regression with more than 16 variables
    By showcase48 in forum Excel General
    Replies: 6
    Last Post: 06-28-2005, 09:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1