excel - 如何在 Excel 中计算样本子组内的相关性
问题描述
我正在分析一项调查的结果,我有 2 个数组,现在我正在 Excel 中计算相关性,这很容易,但是我如何计算分散在数组中的子组的相关性,而无需手动执行。例如,我想计算 15-25 之间男性的 2 个变量之间的相关性,而不是整个样本
我已经尝试过的是,我根据所需的维度对样本进行排序,这意味着我将按年龄对整个样本进行排序,以便数据彼此跟随而不是分散,但这需要时间,并且不能用于 2年龄和性别等变量
解决方案
你可以这样做:
=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))))
演示电子表格
推荐阅读
- python - for 循环中的 2 个计数器变量不适用于等于条件
- javascript - Vue JS - 如何使用单选按钮显示或隐藏元素
- parameters - Anylogic 参数变化实验:我以哪种方式使用“表达式”列在其允许的状态下改变布尔参数?
- node.js - 管理拍卖组件中的剩余时间
- java - Selenium 出现问题,无头运行时出现意外行为
- node.js - MongoDB/Mongoose 如何管理一些数字字段的增量
- android - IAP 未准备好。检查 Google Play 服务是否可用
- mysql - 将 Google 表格列映射到 MySQL 数据类型
- swift - 如何在 Swift 中获得标准输入/输出/错误的“管道”?
- java - 需要帮助正确打印出值而不在 java 中重复它们