freq_t_test: Frequentist Test Comparisons Between Means

Description Usage Arguments Value Note Examples

View source: R/freq_t_test.R

Description

Creates a summarized data frame out of a raw dataframe with an indication on whether differences between mean results across a subgroup are statistically significant.

Usage

1
2
3
freq_t_test(df, x, subgroup, level = NULL, weight = NULL,
  min_sample = NULL, alpha = 0.05, p.adjust.method = "holm",
  nlabels = FALSE, newline = FALSE)

Arguments

df

A raw data frame that includes a subgroup variable, a variable to be tested, and optionally a weight variable.

x

A numeric variable name to be tested, in quotes.

subgroup

A factor variable name that subgroups cases, in quotes.

level

Optional. A level of the subgroup factor variable that would be compared to the rest of the sample, in quotes.

weight

A post-stratification weight variable name, in quotes.

min_sample

A numeric value that removes comparisons if one of the subgroups' sample size is below that value.

alpha

The p-value level for which it is determined whether a difference is statistically significant or not. Default is 0.05.

p.adjust.method

A type of adjustment method, as per the pairwise.prop.test function. The default method is "holm".

nlabels

A logical argument. Default is FALSE. If TRUE, the subgroup levels will be changed to include the unweighted sample sizes ("subgroup (n=xx)").

newline

A logical argument. Default is FALSE. If TRUE, the unweighted sample sizes will be shown on a separate line.

Value

A summary data frame that provides the results of the significance tests for each possible comparison, along with group's sample sizes and their means.

Note

If the level argument is used, the rest of the sample will be called "Rest of Sample". This assumes that you are not comparing a subgroup level that happens to have that name to the rest of the sample!

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#Prepping the data first
gss_data1 <- dplyr::filter(gss_data, year == "2016", coninc > 0)

#With weights
freq_t_test(gss_data1, "coninc", "degree", weight = "wtssall")

#Without weights
freq_t_test(gss_data1, "coninc", "degree")

#Comparing one level (here the "Bachelor" level of education) to the rest of the sample
freq_t_test(gss_data1, "coninc", "degree", level = "BACHELOR", weight = "wtssall")

philstraforelli/ggsigmark documentation built on May 20, 2019, 1:59 p.m.