首页 > 解决方案 > 如何在 Excel 中计算样本子组内的相关性

问题描述

我正在分析一项调查的结果,我有 2 个数组,现在我正在 Excel 中计算相关性,这很容易,但是我如何计算分散在数组中的子组的相关性,而无需手动执行。例如,我想计算 15-25 之间男性的 2 个变量之间的相关性,而不是整个样本

我已经尝试过的是,我根据所需的维度对样本进行排序,这意味着我将按年龄对整个样本进行排序,以便数据彼此跟随而不是分散,但这需要时间,并且不能用于 2年龄和性别等变量

标签: excelgoogle-sheetsexcel-formulagoogle-sheets-formula

解决方案


你可以这样做:

=CORREL(QUERY(A2:C, "select A where B='15-20' and C='F'", 0),
        QUERY(D2:F, "select D where E='15-20' and F='F'", 0))

或类似的东西:

=CORREL(FILTER(A2:A, B2:B="15-20", C2:C="F"),
        FILTER(D2:D, E2:E="15-20", F2:F="F"))

但这只有在这两个数组中具有相等的矩阵时才有效...CORREL函数的问题是它需要相等大小的范​​围,但是当您使用FILTER它或QUERY它时,输出范围会有所不同...

那么你可以试试这个:

=IFERROR(CORREL(QUERY({A2:C}, "select Col1 where Col2='15-20' and Col3='F'", 0),
               {QUERY({D2:F}, "select Col1 where Col2='15-20' and Col3='F'", 0);
                TRANSPOSE(SPLIT(REPT("♂♀",
                COUNTA(QUERY({A2:C}, "select Col1 where Col2='15-20' and Col3='F'", 0))-
                COUNTA(QUERY({D2:F}, "select Col1 where Col2='15-20' and Col3='F'", 0))),"♀"))}),
         CORREL(QUERY({D2:F}, "select Col1 where Col2='15-20' and Col3='F'", 0),
               {QUERY({A2:C}, "select Col1 where Col2='15-20' and Col3='F'", 0);
                TRANSPOSE(SPLIT(REPT("♂♀",
                COUNTA(QUERY({D2:F}, "select Col1 where Col2='15-20' and Col3='F'", 0))-
                COUNTA(QUERY({A2:C}, "select Col1 where Col2='15-20' and Col3='F'", 0))),"♀"))}))

注意:可悲的是,即使这样也有自己的局限性......

为了获得最大的舒适度,您可以使用它:

=IFERROR(IFERROR(CORREL(QUERY({A2:C}, "select Col1 where Col2='"&H9&"' and Col3='"&H10&"'", 0),
               {QUERY({D2:F}, "select Col1 where Col2='"&I9&"' and Col3='"&I10&"'", 0);
                TRANSPOSE(SPLIT(REPT("♂♀",
                COUNTA(QUERY({A2:C}, "select Col1 where Col2='"&H9&"' and Col3='"&H10&"'", 0))-
                COUNTA(QUERY({D2:F}, "select Col1 where Col2='"&I9&"' and Col3='"&I10&"'", 0))),"♀"))}),
         CORREL(QUERY({D2:F}, "select Col1 where Col2='"&I9&"' and Col3='"&I10&"'", 0),
               {QUERY({A2:C}, "select Col1 where Col2='"&H9&"' and Col3='"&H10&"'", 0);
                TRANSPOSE(SPLIT(REPT("♂♀",
                COUNTA(QUERY({D2:F}, "select Col1 where Col2='"&I9&"' and Col3='"&I10&"'", 0))-
                COUNTA(QUERY({A2:C}, "select Col1 where Col2='"&H9&"' and Col3='"&H10&"'", 0))),"♀"))})),
 IFERROR(CORREL(QUERY({A2:C}, "select Col1 where Col2='"&H9&"' and Col3='"&H10&"'", 0),
                QUERY({D2:F}, "select Col1 where Col2='"&I9&"' and Col3='"&I10&"'", 0)),
         CORREL(QUERY({D2:F}, "select Col1 where Col2='"&I9&"' and Col3='"&I10&"'", 0),
                QUERY({A2:C}, "select Col1 where Col2='"&H9&"' and Col3='"&H10&"'", 0))))

演示电子表格


推荐阅读