Description Usage Arguments Value Note See Also Examples
View source: R/freq_prop_test.R
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.
1 2 3 |
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. |
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.
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!
pairwise.prop.test
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.
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.