This function calculates a t.test() for two groups in a srvyr survey object. It is particularly helpful when the grouping variable has more than two levels and you just want to compare two of them.

svy_cohen_d_pair(data, dv, iv, pair = NULL, ttest = TRUE, print = FALSE)

Arguments

data

A survey object

dv

Character. Name of the dependent variable for the t.test (numeric)

iv

Character. Name of the grouping variable for the t.test (factor)

pair

Character vector of length 2. Levels of iv to be compared in t.test. Can be NULL if iv only has two distinct values.

ttest

Logical. Should t.test be run? Otherwise, only Cohen's d is calculated. Defaults to TRUE.

print

Logical. Should results be printed.

Value

Returns a one-row tibble with tidy results of t-test and Cohen's d. If print is TRUE, results are returned invisibly.

Examples

library(srvyr)
#> 
#> Attaching package: ‘srvyr’
#> The following object is masked from ‘package:MASS’:
#> 
#>     select
#> The following object is masked from ‘package:stats’:
#> 
#>     filter

#Create weights (consists of two variables in ESS)
ess_health$svy_weight <- ess_health$pspwght * ess_health$pweight

ess_survey <- as_survey(ess_health,
                       weights = svy_weight)   

svy_cohen_d_pair(ess_survey, "health", "cntry", pair = c("DE", "GB"))
#> # A tibble: 1 × 8
#>   pair       d     t    df  p.value mean_diff mean_diff_ci.low mean_diff_ci.high
#>   <chr>  <dbl> <dbl> <dbl>    <dbl>     <dbl>            <dbl>             <dbl>
#> 1 DE & … 0.324 0.295  5301 7.94e-25     0.295            0.351             0.239