首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何获得多个因素的统计量(cohensd)

如何获得多个因素的统计量(cohensd)
EN

Stack Overflow用户
提问于 2022-03-06 22:22:07
回答 1查看 57关注 0票数 1

我希望同时计算多个因子的cohens值。

因此,例如,在虹膜数据集中,我们可以很容易地计算出刚毛和云芝之间萼片长度的cohens d:

代码语言:javascript
复制
virginica <- subset(iris, Species =="virginica")
versicolor <- subset(iris, Species =="versicolor")

cohen.d(virginica$Sepal.Length, versicolor$Sepal.Length)

当然,对于剩下的因素,我们可以再次复制这个过程。

总之,我想要的是衡量每一个因素,而不是所有相互对立的因素。因此,这就像产生几个cohensd,但只是一个步骤。

在这种情况下,云天色对刚毛和云天色对处女。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-07 01:00:21

我不认为这是你想要的答案,但这是一个会奏效的答案。

与其尝试使函数适合您的数据,不如让您的数据与该函数相匹配。

首先,查找所有可能的组组合--我知道您使用了Iris数据,但很可能您只是将其作为一个示例。

代码语言:javascript
复制
library(tidyverse)
library(psych)
library(RcppAlgos)

# find unique pairs
iS = RcppAlgos::comboGeneral(unique(iris$Species), 
                             2, F) # all unique combinations of 2 options

然后使用这些可能的组,并得到它们之间的效果大小。

代码语言:javascript
复制
res = map(1:nrow(iS), 
          .f = function(x){
            filter(iris, Species %in% c(iS[x, 1], iS[x, 2])) %>% 
                       cohen.d(., group = "Species")
          })
names(res) <- paste0(iS[,1], "-",iS[,2])
res

各组之间的影响大小:

代码语言:javascript
复制
# [[1]]
# Call: cohen.d(x = ., group = "Species")
# Cohen d statistic of difference between two means
#              lower effect upper
# Sepal.Length  1.55   2.13  2.69
# Sepal.Width  -2.45  -1.91 -1.36
# Petal.Length  6.35   7.98  9.57
# Petal.Width   5.47   6.89  8.27
# 
# Multivariate (Mahalanobis) distance between groups
# [1] 10
# r equivalent of difference between two means
# Sepal.Length  Sepal.Width Petal.Length  Petal.Width 
#         0.73        -0.69         0.97         0.96 
# 
# [[2]]
# Call: cohen.d(x = ., group = "Species")
# Cohen d statistic of difference between two means
#              lower effect upper
# Sepal.Length  2.38   3.11  3.83
# Sepal.Width  -1.77  -1.30 -0.83
# Petal.Length  8.01  10.10 12.08
# Petal.Width   6.89   8.64 10.36
# 
# Multivariate (Mahalanobis) distance between groups
# [1] 14
# r equivalent of difference between two means
# Sepal.Length  Sepal.Width Petal.Length  Petal.Width 
#         0.84        -0.55         0.98         0.97 
# 
# [[3]]
# Call: cohen.d(x = ., group = "Species")
# Cohen d statistic of difference between two means
#              lower effect upper
# Sepal.Length  0.68   1.14  1.58
# Sepal.Width   0.23   0.65  1.06
# Petal.Length  1.90   2.55  3.18
# Petal.Width   2.25   2.95  3.65
# 
# Multivariate (Mahalanobis) distance between groups
# [1] 3.8
# r equivalent of difference between two means
# Sepal.Length  Sepal.Width Petal.Length  Petal.Width 
#         0.49         0.31         0.79         0.83 
#  
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71374660

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档