在CRAN上尝试使用pwr
包。
您可以使用cohen.ES()
函数:
library(pwr)
cohen.ES(test = 'f2', size = 'large')
或者根据您使用的比例、卡方检验、t检验、ANOVA等不同的效应量计算器。
例如:
pwr.anova.test(k = 4, n = 20, sig.level = 0.05, power = 0.8)
返回:
Balanced one-way analysis of variance power calculation
k = 4
n = 20
f = 0.3788014
sig.level = 0.05
power = 0.8
NOTE: n is number in each group
我也遇到了同样的问题,没有找到可用的函数来计算多元回归的f2。然而,我在Quick-R Power Analysis page上找到了公式,并编写了自己的代码来计算它:
# If we are evaluating the impact of a set of predictors on an outcome, then the f2 formula is:
R2 = # input your R2
f2 = R2/(1 - R2)
# Else, if we are evaluating the impact of one set of predictors above and beyond a second set of predictors (or covariates), then the f2 formula is:
R2AB = # input your R2AB
R2A = # input your R2A
f2 = (R2AB - R2A)/(1 - R2AB)
如果你有多层数据,然而你可能需要调整这个公式。