+ Reply to Thread
Results 1 to 5 of 5

Calculate Covariance in a single cell

  1. #1
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Cool Calculate Covariance in a single cell

    Hi guys

    Covariance = 1/n Sum (xi-mx)*(yi-my)

    above is the fomula for Covariance.
    mx = mean of the X values
    my = mean of the Y values


    I have a list of X and Y values. I want to calculate the Covariance between the X and Y.

    Currently I need to make a 3rd and 4th column of "xi-mx" and "yi-my" and then a 5th column of "(xi-mx)*(yi-my)"

    I am looking for a way to create a single cell that would give the value of the covarince without the 3rd 4th and 5th columns.

    I think I will need to use Ctrl+Shift+Enter to do this.

    Any ideas?

    Thanks
    Jimmy
    Thanks,

    JimmyWilliams

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

    Re: Calculate Covariance in a single cell

    Would you be allowed to use one of the built in covariance functions? COVARIANCE.S() help file: https://support.office.com/en-us/art...f-1f5320314977 I don't know if you need the .S or .P or the backwards compatible COVAR() function, but it seems like the easiest way to make this a single cell function is to use one of the built in function.

    If you were previously unaware that these functions existed, you might take some time to review the list of statistics functions (https://support.office.com/en-us/art...rs=en-US&ad=US ) and see what other statistics functions you are unaware of.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Re: Calculate Covariance in a single cell

    Hi Mrshorty,

    I know that these functions exist, but I want to find a solution without using them; so that I can write more complicated equations for other things.

  4. #4
    Forum Expert
    Join Date
    05-01-2014
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    1,795

    Re: Calculate Covariance in a single cell

    First, the mathematic formula is better written:

    Covariance = Sum( (xi-mx)*(yi-my) ) / n

    And it should be noted that that is equivalent to COVAR or COVARIANCE.P, not COVARIANCE.S.

    COVAR(A1:A7, B1:B7) is equal to the following (normally Enter; just press Enter as usual):

    =SUMPRODUCT((A1:A7 - AVERAGE(A1:A7)), (B1:B7 - AVERAGE(B1:B7))) / COUNT(A1:A7)
    Last edited by joeu2004; 09-24-2018 at 10:01 AM. Reason: cosmetic improvements

  5. #5
    Forum Expert
    Join Date
    05-01-2014
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    1,795

    Re: Calculate Covariance in a single cell

    Quote Originally Posted by joeu2004 View Post
    =SUMPRODUCT((A1:A7 - AVERAGE(A1:A7)), (B1:B7 - AVERAGE(B1:B7))) / COUNT(A1:A7)
    That presumes that all of A1:A7 and B1:B7 are numeric values. And of course, COUNT can be replaced by 7, in this case.

    But COVAR ignores empty cells and text; in fact, COVAR includes only rows where both values are numeric. If you need that degree of compatibility, array-enter (press ctrl+shift+Enter, not just Enter) the following:

    Please Login or Register  to view this content.
    (Assumes that there is at least 1 row with a pair of numeric values.)

+ 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. Calculate Time Range In Single Cell
    By A_H in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-11-2017, 12:06 AM
  2. How to calculate the Covariance for my Excel File?
    By albert_teo77 in forum Excel General
    Replies: 1
    Last Post: 02-16-2014, 10:33 AM
  3. Replies: 6
    Last Post: 09-30-2013, 10:14 AM
  4. Formula to calculate single cell based on many variables
    By malawimick in forum Excel General
    Replies: 7
    Last Post: 12-15-2011, 02:13 AM
  5. COVARIANCE.S to build a covariance matrix
    By steve.lorimer in forum Excel General
    Replies: 6
    Last Post: 06-05-2011, 09:37 AM
  6. [SOLVED] Is there a way to calculate 4x10 in a single cell?
    By Excell novice in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-15-2006, 06:25 PM
  7. Replies: 2
    Last Post: 12-16-2005, 02:45 PM

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