Compare a sample proportion to a population proportion

single_prop(
  dataset,
  var,
  lev = "",
  comp_value = 0.5,
  alternative = "two.sided",
  conf_lev = 0.95,
  test = "binom",
  data_filter = "",
  envir = parent.frame()
)

Arguments

dataset

Dataset

var

The variable selected for the proportion comparison

lev

The factor level selected for the proportion comparison

comp_value

Population value to compare to the sample proportion

alternative

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

conf_lev

Span of the confidence interval

test

bionomial exact test ("binom") or Z-test ("z")

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 variables used in single_prop as an object of class single_prop

Details

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

See also

summary.single_prop to summarize the results

plot.single_prop to plot the results

Examples

single_prop(titanic, "survived") %>% str()
#> List of 16 #> $ res : tibble [1 × 8] (S3: tbl_df/tbl/data.frame) #> ..$ estimate : Named num 0.407 #> .. ..- attr(*, "names")= chr "probability of success" #> ..$ statistic : Named num 425 #> .. ..- attr(*, "names")= chr "number of successes" #> ..$ p.value : num 2.5e-09 #> ..$ parameter : Named num 1043 #> .. ..- attr(*, "names")= chr "number of trials" #> ..$ conf.low : num 0.377 #> ..$ conf.high : num 0.438 #> ..$ method : chr "Exact binomial test" #> ..$ alternative: chr "two.sided" #> $ dat_summary:'data.frame': 1 obs. of 8 variables: #> ..$ diff : num -0.0925 #> ..$ p : num 0.407 #> ..$ ns : int 425 #> ..$ n : int 1043 #> ..$ n_missing: int 0 #> ..$ sd : num 0.491 #> ..$ se : num 0.0152 #> ..$ me : num 0.0298 #> $ p : num 0.407 #> $ ns : int 425 #> $ n : int 1043 #> $ levs : chr [1:2] "Yes" "No" #> $ n_miss : int 0 #> $ df_name : chr "titanic" #> $ dataset : tibble [1,043 × 1] (S3: tbl_df/tbl/data.frame) #> ..$ 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__ #> $ var : chr "survived" #> $ lev : chr "Yes" #> $ comp_value : num 0.5 #> $ alternative: chr "two.sided" #> $ conf_lev : num 0.95 #> $ test : chr "binom" #> $ data_filter: chr "" #> - attr(*, "class")= chr [1:2] "single_prop" "list"
single_prop(titanic, "survived", lev = "Yes", comp_value = 0.5, alternative = "less") %>% str()
#> List of 16 #> $ res : tibble [1 × 8] (S3: tbl_df/tbl/data.frame) #> ..$ estimate : Named num 0.407 #> .. ..- attr(*, "names")= chr "probability of success" #> ..$ statistic : Named num 425 #> .. ..- attr(*, "names")= chr "number of successes" #> ..$ p.value : num 1.25e-09 #> ..$ parameter : Named num 1043 #> .. ..- attr(*, "names")= chr "number of trials" #> ..$ conf.low : num 0 #> ..$ conf.high : num 0.433 #> ..$ method : chr "Exact binomial test" #> ..$ alternative: chr "less" #> $ dat_summary:'data.frame': 1 obs. of 8 variables: #> ..$ diff : num -0.0925 #> ..$ p : num 0.407 #> ..$ ns : int 425 #> ..$ n : int 1043 #> ..$ n_missing: int 0 #> ..$ sd : num 0.491 #> ..$ se : num 0.0152 #> ..$ me : num 0.0298 #> $ p : num 0.407 #> $ ns : int 425 #> $ n : int 1043 #> $ levs : chr [1:2] "Yes" "No" #> $ n_miss : int 0 #> $ df_name : chr "titanic" #> $ dataset : tibble [1,043 × 1] (S3: tbl_df/tbl/data.frame) #> ..$ 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__ #> $ var : chr "survived" #> $ lev : chr "Yes" #> $ comp_value : num 0.5 #> $ alternative: chr "less" #> $ conf_lev : num 0.95 #> $ test : chr "binom" #> $ data_filter: chr "" #> - attr(*, "class")= chr [1:2] "single_prop" "list"