Compare sample proportions across groups

compare_props(
  dataset,
  var1,
  var2,
  levs = "",
  alternative = "two.sided",
  conf_lev = 0.95,
  comb = "",
  adjust = "none",
  data_filter = "",
  envir = parent.frame()
)

Arguments

dataset

Dataset

var1

A grouping variable to split the data for comparisons

var2

The variable to calculate proportions for

levs

The factor level selected for the proportion comparison

alternative

The alternative hypothesis ("two.sided", "greater" or "less")

conf_lev

Span of the confidence interval

comb

Combinations to evaluate

adjust

Adjustment for multiple comparisons ("none" or "bonf" for Bonferroni)

data_filter

Expression entered in, e.g., Data > View to filter the dataset in Radiant. The expression should be a string (e.g., "price > 10000")

envir

Environment to extract data from

Value

A list of all variables defined in the function as an object of class compare_props

Details

See https://radiant-rstats.github.io/docs/basics/compare_props.html for an example in Radiant

See also

summary.compare_props to summarize results

plot.compare_props to plot results

Examples

compare_props(titanic, "pclass", "survived") %>% str()
#> List of 22 #> $ dat_summary:'data.frame': 3 obs. of 9 variables: #> ..$ pclass : Factor w/ 3 levels "1st","2nd","3rd": 1 2 3 #> ..$ Yes : int [1:3] 179 115 131 #> ..$ No : int [1:3] 103 146 369 #> ..$ p : num [1:3] 0.635 0.441 0.262 #> ..$ n : int [1:3] 282 261 500 #> ..$ n_missing: int [1:3] 0 0 0 #> ..$ sd : num [1:3] 0.481 0.496 0.44 #> ..$ se : num [1:3] 0.0287 0.0307 0.0197 #> ..$ me : num [1:3] 0.0562 0.0602 0.0385 #> $ E : num [1:2, 1:2] 84.4 161.6 176.6 338.4 #> ..- attr(*, "dimnames")=List of 2 #> .. ..$ : NULL #> .. ..$ : chr [1:2] "Yes" "No" #> $ pinp : num [1:2, 1:2] 115 131 146 369 #> ..- attr(*, "dimnames")=List of 2 #> .. ..$ : chr [1:2] "2nd" "3rd" #> .. ..$ : chr [1:2] "Yes" "No" #> $ ind : int [1:2] 2 3 #> $ res :'data.frame': 3 obs. of 9 variables: #> ..$ group1 : chr [1:3] "1st" "1st" "2nd" #> ..$ group2 : chr [1:3] "2nd" "3rd" "3rd" #> ..$ chisq.value: num [1:3] 20.6 104.7 25 #> ..$ p.value : num [1:3] 5.73e-06 1.42e-24 5.71e-07 #> ..$ df : num [1:3] 1 1 1 #> ..$ ci_low : num [1:3] 0.112 0.305 0.107 #> ..$ ci_high : num [1:3] 0.277 0.441 0.25 #> ..$ sim : num [1:3] 0 0 0 #> ..$ sig_star : chr [1:3] "***" "***" "***" #> $ cmb :'data.frame': 3 obs. of 2 variables: #> ..$ group1: chr [1:3] "1st" "1st" "2nd" #> ..$ group2: chr [1:3] "2nd" "3rd" "3rd" #> $ prop_input : num [1:3, 1:2] 179 115 131 103 146 369 #> ..- attr(*, "dimnames")=List of 2 #> .. ..$ : chr [1:3] "1st" "2nd" "3rd" #> .. ..$ : chr [1:2] "Yes" "No" #> $ rn : chr [1:3] "1st" "2nd" "3rd" #> $ not_vary : chr(0) #> $ lv : chr [1:3] "1st" "2nd" "3rd" #> $ n_miss_df : tibble [3 × 2] (S3: tbl_df/tbl/data.frame) #> ..$ pclass: Factor w/ 3 levels "1st","2nd","3rd": 1 2 3 #> ..$ n_miss: int [1:3] 0 0 0 #> $ vars : chr "pclass, survived" #> $ df_name : chr "titanic" #> $ dataset : tibble [1,043 × 2] (S3: tbl_df/tbl/data.frame) #> ..$ pclass : Factor w/ 3 levels "1st","2nd","3rd": 1 1 1 1 1 1 1 1 1 1 ... #> ..$ survived: Factor w/ 2 levels "Yes","No": 1 1 2 2 2 1 1 2 1 2 ... #> ..- attr(*, "description")= chr "## Titanic\n\nThis dataset describes the survival status of individual passengers on the Titanic. The titanic d"| __truncated__ #> $ var1 : chr "pclass" #> $ var2 : chr "survived" #> $ levs : chr "" #> $ alternative: chr "two.sided" #> $ conf_lev : num 0.95 #> $ comb : chr "" #> $ adjust : chr "none" #> $ data_filter: chr "" #> - attr(*, "class")= chr [1:2] "compare_props" "list"