TEST.prop: Test on the proportion

View source: R/UBStats_Main_Visible_ALL_202406.R

TEST.propR Documentation

Test on the proportion

Description

TEST.prop() tests hypotheses on the proportion of successes in a population.

Usage

TEST.prop(
  x,
  success = NULL,
  p0 = 0.5,
  alternative = "two.sided",
  digits = 2,
  force.digits = FALSE,
  use.scientific = FALSE,
  data,
  ...
)

Arguments

x

An unquoted string identifying the variable of interest. x can be the name of a vector or a factor in the workspace or the name of one of the columns in the data frame specified in the data argument.

success

If x is a factor, a character vector, or a numeric non-binary vector, success must be used to indicate the category/value corresponding to success. The argument can be omitted (NULL, default) if x is a binary numeric vector (takes values 0 or 1 only; in this case success is assumed to be 1) or a logical vector (in these cases success is assumed to be TRUE).

p0

Numeric value that specifies the null hypothesis to test for (default is 0).

alternative

A length-one character vector specifying the direction of the alternative hypothesis. Allowed values are "two.sided" (population proportion differs from p0; default), or "less" (population proportion is lower than p0), or "greater" (population proportion is higher than p0).

digits

Integer value specifying the number of decimals used to round statistics; default to 2. If the chosen rounding formats some non-zero values as zero, the number of decimals is increased so that all values have at least one significant digit, unless the argument force.digits is set to TRUE.

force.digits

Logical value indicating whether reported values should be forcedly rounded to the number of decimals specified in digits even if non-zero values are rounded to zero (default to FALSE).

use.scientific

Logical value indicating whether numbers in tables should be displayed using scientific notation (TRUE); default to FALSE.

data

An optional data frame containing x. If not found in data, x is taken from the environment from which TEST.prop() is called.

...

Additional arguments to be passed to low level functions.

Value

A table reporting the results of the test on the population proportion of successes.

Author(s)

Raffaella Piccarreta raffaella.piccarreta@unibocconi.it

See Also

CI.prop() to build confidence intervals for the population proportion of successes.

Examples

data(MktDATA, package = "UBStats")

# Success = one value of a character vector or factor
# - Bilateral test
TEST.prop(WouldSuggest, success = "Yes", p0 = 0.7, 
         data = MktDATA)
# - Unilateral test, change digits
TEST.prop(Education, success = "Post-Grad", p0 = 0.3, 
          alternative = "less", digits = 4,data = MktDATA)

# Success = numeric value; bilateral test
TEST.prop(Children, success = 2, p0 = 0.3, data = MktDATA)

# Binary variable (success = 1 by default); unilateral
TEST.prop(LastCampaign, p0 = 0.1, alternative = "greater", 
          digits = 3, data = MktDATA)

# Logical variable (success = TRUE by default); unilateral test
TEST.prop(Deals.ge50, p0 = 0.13, alternative = "greater", 
          digits = 3, data = MktDATA)

# Success based on combined conditions
# - Build a (logical) vector 
IsTop <- MktDATA$CustClass == "Gold" |
  MktDATA$CustClass == "Platinum"
TEST.prop(IsTop, p0 = 0.2, data = MktDATA)

HighAOV <- MktDATA$AOV>150
TEST.prop(HighAOV, p0 = 0.1)
TEST.prop(HighAOV, p0 = 0.1, force.digits = TRUE)
TEST.prop(HighAOV, p0 = 0.1, use.scientific = TRUE)

# Output results
out_test_prop<-TEST.prop(IsTop, p0 = 0.2, data = MktDATA)


UBStats documentation built on Sept. 11, 2024, 6:52 p.m.