Skip to contents

Calculates Cohen's f-squared for the group effect in a linear regression model of the form y ~ covariate + group. Cohen's f-squared represents the proportion of variance uniquely explained by the group variable relative to the unexplained variance. This function is vectorized and can handle multiple values for the d parameter.

Usage

f2_from_params_ancova_cont_2arms(
  d,
  beta_cov,
  sigma,
  equal_groups = TRUE,
  p_group = 0.5
)

Arguments

d

Numeric or vector of numerics. Cohen's d for the group effect (standardized mean difference). This represents the difference in group means divided by the pooled standard deviation, after adjusting for the covariate.

beta_cov

Numeric. True coefficient for the covariate (assumes covariate ~ N(0,1)).

sigma

Numeric. Residual standard deviation after fitting the full model.

equal_groups

Logical. If TRUE (default), assumes equal group sizes (n1 = n2). If FALSE, requires p_group to be specified.

p_group

Numeric. Proportion in group 1 (only used if equal_groups = FALSE).

Value

Numeric vector. Cohen's f-squared for the group effect(s).

Details

Cohen's f-squared is calculated as the ratio of variance uniquely explained by the group to the unexplained variance: $$f^{2} = \frac{R^{2}_{\text{full}} - R^{2}_{\text{reduced}}}{1 - R^{2}_{\text{full}}}$$

where \(R^{2}_{\text{full}}\) includes both predictors and \(R^{2}_{\text{reduced}}\) includes only the covariate.

Examples

# \donttest{
# Single value
f2_from_params_ancova_cont_2arms(d = 0.5, beta_cov = 0.4, sigma = 1)
#> [1] 0.0625

# Multiple d values (vectorized)
f2_from_params_ancova_cont_2arms(d = c(0.2, 0.5, 0.8), beta_cov = 0.4, sigma = 1)
#> [1] 0.0100 0.0625 0.1600

# Unequal groups (70/30 split)
f2_from_params_ancova_cont_2arms(d = 0.5, beta_cov = 0.4, sigma = 1,
                                  equal_groups = FALSE, p_group = 0.7)
#> [1] 0.0525
# }