freq_prop_test: Frequentist Test Comparisons Between Proportions

Description Usage Arguments Value Note See Also Examples

View source: R/freq_prop_test.R

Description

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

Usage

1
2
3
freq_prop_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 factor 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

Optional. 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 proportions.

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!

See Also

pairwise.prop.test

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#Prepping the data first
gss_data1 <- dplyr::filter(gss_data, year == "2016",
                                      conlegis %in% c("A GREAT DEAL", "ONLY SOME", "HARDLY ANY"))

#With weights
freq_prop_test(gss_data1, "conlegis", "region", weight = "wtssall")

#Without weights
freq_prop_test(gss_data1, "conlegis", "region")

#Comparing one level (here the "Pacific" region) to the rest of the sample
freq_prop_test(gss_data1, "conlegis", "region", level = "PACIFIC", weight = "wtssall")

#Warnings of chi-squares being approximated can be ignored.

philstraforelli/ggsigmark documentation built on April 3, 2018, 12:07 p.m.