svy_cohen_d_pair: t.test for survey object with Cohen's d

View source: R/stat_tests.R

svy_cohen_d_pairR Documentation

t.test for survey object with Cohen's d

Description

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.

Usage

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)

#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"))
  

LukasWallrich/timesaveR documentation built on Nov. 29, 2024, 4:47 a.m.