ci.prop: Confidence Interval for Proportions

View source: R/ci.prop.R

ci.propR Documentation

Confidence Interval for Proportions

Description

This function computes a confidence interval for proportions for one or more variables, optionally by a grouping and/or split variable.

Usage

ci.prop(..., data = NULL, method = c("wald", "wilson"),
        alternative = c("two.sided", "less", "greater"), conf.level = 0.95,
        group = NULL, split = NULL, sort.var = FALSE, na.omit = FALSE,
        digits = 3, as.na = NULL, write = NULL, append = TRUE, check = TRUE,
        output = TRUE)

Arguments

...

a numeric vector, matrix or data frame with numeric variables with 0 and 1 values, i.e., factors and character variables are excluded from x before conducting the analysis. Alternatively, an expression indicating the variable names in data e.g., ci.prop(x1, x2, x3, data = dat). Note that the operators ., +, -, ~, :, ::, and ! can also be used to select variables, see 'Details' in the df.subset function.

data

a data frame when specifying one or more variables in the argument .... Note that the argument is NULL when specifying a numeric vector, matrix or data frame for the argument ....

method

a character string specifying the method for computing the confidence interval, must be one of "wald", or "wilson" (default).

alternative

a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater" or "less".

conf.level

a numeric value between 0 and 1 indicating the confidence level of the interval.

group

either a character string indicating the variable name of the grouping variable in ... or data, or a vector representing the grouping variable.

split

either a character string indicating the variable name of the split variable in ... or data, or a vector representing the split variable.

sort.var

logical: if TRUE, output table is sorted by variables when specifying group.

na.omit

logical: if TRUE, incomplete cases are removed before conducting the analysis (i.e., listwise deletion) when specifying more than one outcome variable.

digits

an integer value indicating the number of decimal places to be used.

as.na

a numeric vector indicating user-defined missing values, i.e. these values are converted to NA before conducting the analysis. Note that as.na() function is only applied to x, but not to group or split.

write

a character string naming a text file with file extension ".txt" (e.g., "Output.txt") for writing the output into a text file.

append

logical: if TRUE (default), output will be appended to an existing text file with extension .txt specified in write, if FALSE existing text file will be overwritten.

check

logical: if TRUE (default), argument specification is checked.

output

logical: if TRUE (default), output is shown on the console.

Details

The Wald confidence interval which is based on the normal approximation to the binomial distribution are computed by specifying method = "wald", while the Wilson (1927) confidence interval (aka Wilson score interval) is requested by specifying method = "wilson". By default, Wilson confidence interval is computed which have been shown to be reliable in small samples of n = 40 or less, and larger samples of n > 40 (Brown, Cai & DasGupta, 2001), while the Wald confidence intervals is inadequate in small samples and when p is near 0 or 1 (Agresti & Coull, 1998).

Value

Returns an object of class misty.object, which is a list with following entries:

call

function call

type

type of analysis

data

list with the input specified in ..., data, group, and split

args

specification of function arguments

result

result table

Author(s)

Takuya Yanagida takuya.yanagida@univie.ac.at

References

Agresti, A. & Coull, B.A. (1998). Approximate is better than "exact" for interval estimation of binomial proportions. American Statistician, 52, 119-126.

Brown, L. D., Cai, T. T., & DasGupta, A., (2001). Interval estimation for a binomial proportion. Statistical Science, 16, 101-133.

Rasch, D., Kubinger, K. D., & Yanagida, T. (2011). Statistics in psychology - Using R and SPSS. John Wiley & Sons.

Wilson, E. B. (1927). Probable inference, the law of succession, and statistical inference. Journal of the American Statistical Association, 22, 209-212.

See Also

ci.mean, ci.mean.diff, ci.median, ci.prop.diff, ci.var, ci.sd, descript

Examples

# Example 1a: Two-Sided 95% CI for 'vs'
ci.prop(mtcars$vs)
#
# Example 1b: Alternative specification using the 'data' argument
ci.prop(vs, data = mtcars)

# Example 2: Two-Sided 95% CI using Wald method
ci.prop(mtcars$vs, method = "wald")

# Example 3: One-Sided 95% CI
ci.prop(mtcars$vs, alternative = "less")

# Example 4: Two-Sided 99% CI
ci.prop(mtcars$vs, conf.level = 0.99)

# Example 5: Two-Sided 95% CI, print results with 4 digits
ci.prop(mtcars$vs, digits = 4)

# Example 6a: Two-Sided 95% CI for 'vs' and 'am',
# listwise deletion for missing data
ci.prop(mtcars[, c("vs", "am")], na.omit = TRUE)

# Example 6b: Alternative specification using the 'data' argument
# listwise deletion for missing data
ci.prop(vs, am, data = mtcars, na.omit = TRUE)

# Example 7a: Two-Sided 95% CI, analysis by 'gear' separately
ci.prop(mtcars[, c("vs", "am")], group = mtcars$gear)

# Example 7b: Alternative specification using the 'data' argument
ci.prop(vs, am, data = mtcars, group = "gear")

# Example 8: Two-Sided 95% CI, analysis by 'gear' separately, sort by variables
ci.prop(mtcars[, c("vs", "am")], group = mtcars$gear, sort.var = TRUE)

# Example 9: Two-Sided 95% CI, split analysis by 'cyl'
ci.prop(mtcars[, c("vs", "am")], split = mtcars$cyl)

# Example 10a: Two-Sided 95% CI, analysis by 'gear' separately, split by 'cyl'
ci.prop(mtcars[, c("vs", "am")], group = mtcars$gear, split = mtcars$cyl)

# Example 10b: Alternative specification using the 'data' argument
ci.prop(vs, am, data = mtcars, group = "gear", split = "cyl")

## Not run: 
# Example 11: Write results into a text file
ci.prop(vs, am, data = mtcars, group = "gear", split = "cyl", write = "Prop.txt")

## End(Not run)

misty documentation built on Oct. 24, 2024, 5:10 p.m.

Related to ci.prop in misty...