


























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



























Type Package
Title Confidence Intervals
Version 0.1.
Date 2022-01-
Maintainer Michael Mayer
Description Calculates classic and/or bootstrap confidence intervals for many parameters such as the population mean, variance, interquartile range (IQR), median absolute deviation (MAD), skewness, kurtosis, Cramer's V, odds ratio, R-squared, quantiles (incl. median), proportions, different types of correlation measures, difference in means, quantiles and medians. Many of the classic confidence intervals are described in Smithson, M. (2003, ISBN: 978-0761924999). Bootstrap confidence intervals are calculated with the R package 'boot'. Both one- and two-sided intervals are supported.
License GPL (>= 2)
Depends R (>= 3.1.0)
Encoding UTF-
RoxygenNote 7.1.
URL https://github.com/mayer79/confintr
BugReports https://github.com/mayer79/confintr/issues
Suggests rmarkdown, knitr, testthat (>= 3.0.0)
VignetteBuilder knitr
Config/testthat/edition 3
Imports boot, stats
NeedsCompilation no
Author Michael Mayer [aut, cre]
Repository CRAN
Date/Publication 2022-01-28 20:00:02 UTC
2 ci_boot
R topics documented:
ci_boot........................................... 2 ci_chisq_ncp........................................ 3 ci_cor............................................ 4 ci_cramersv......................................... 6 ci_f_ncp........................................... 8 ci_IQR............................................ 9 ci_kurtosis.......................................... 10 ci_mad............................................ 12 ci_mean........................................... 13 ci_mean_diff........................................ 14 ci_median.......................................... 16 ci_median_diff....................................... 17 ci_oddsratio......................................... 18 ci_proportion........................................ 19 ci_quantile.......................................... 21 ci_quantile_diff....................................... 22 ci_rsquared......................................... 24 ci_sd............................................. 25 ci_skewness......................................... 26 ci_var............................................ 28 cramersv........................................... 29 is.cint............................................ 30 moments........................................... 31 oddsratio.......................................... 31 print.cint........................................... 32 se.............................................. 33
Index 34
ci_boot Bootstrap Confidence Interval
Description
Internel wrapper to boot::boot.ci. Contains the logic for one-sided and asymmetric confidence intervals.
Usage
ci_boot(S, boot_type = c("norm", "basic", "stud", "perc", "bca"), probs, ...)
Arguments
S Result of boot. boot_type Confidence interval type passed to boot::boot.ci. probs Probability cuts for the confidence intervals. ... Further arguments passed to boot::boot.ci.
4 ci_cor
Value
A list with class cint containing these components:
References
See Also
ci_cramersv.
Examples
ci_chisq_ncp(mtcars[c("am", "vs")]) ci_chisq_ncp(mtcars[c("am", "vs")], type = "bootstrap", R = 999) ir <- iris ir$PL <- ir$Petal.Width > 1 ci_chisq_ncp(ir[, c("Species", "PL")]) ci_chisq_ncp(ir[, c("Species", "PL")], probs = c(0.05, 1))
ci_cor Confidence Interval for Correlation Coefficients
Description
This function calculates confidence intervals for a population correlation coefficient. For Pearson correlation, "normal" confidence intervals are available (by stats::cor.test). Also bootstrap confidence intervals are supported and are the only option for rank correlations.
ci_cor 5
Usage
ci_cor( x, y = NULL, probs = c(0.025, 0.975), method = c("pearson", "kendall", "spearman"), type = c("normal", "bootstrap"), boot_type = c("bca", "perc", "norm", "basic"), R = 9999, seed = NULL, ... )
Arguments
x A numeric vector or a matrix/data.frame with exactly two numeric columns. y A numeric vector (only used if x is a vector). probs Error probabilites. The default c(0.025, 0.975) gives a symmetric 95% confi- dence interval. method Type of correlation coefficient, one of "pearson" (default), "kendall", or "spear- man". For the latter two, only bootstrap confidence intervals are supported. The names can be abbreviated. type Type of confidence interval. One of "normal" (the default) or "bootstrap" (the only option for rank-correlations). boot_type Type of bootstrap confidence interval ("bca", "perc", "norm", "basic"). Only used for type = "bootstrap". R The number of bootstrap resamples. Only used for type = "bootstrap". seed An integer random seed. Only used for type = "bootstrap". ... Further arguments passed to boot::boot.
Details
Bootstrap confidence intervals are calculated by the package "boot", see references. The default bootstrap type is "bca" (bias-corrected accelerated) as it enjoys the property of being second order accurate as well as transformation respecting (see Efron, p. 188).
Value
A list with class cint containing these components:
ci_cramersv 7
test_adjustment Adjustment to allow for test of association, see Details. The default is TRUE. ... Further arguments passed to resample::CI.boot_type.
Details
A positive lower (1-alpha)*100%-confidence limit for the ncp goes hand-in-hand with a significant association test at level alpha. In order to allow such test approach also with Cramer’s V, if the lower bound for the ncp is 0, we round down to 0 also the lower bound for Cramer’s V. Without this slightly conservative adjustment, the lower limit for V would always be positive since ci for V = sqrt((ci for ncp + df)/(n (k - 1))), where k is the smaller number of levels in the two variables (see Smithson for this formula). Use test_adjustment = FALSE to switch off this behaviour. Note that this is also a reason to bootstrap V via ncp instead of directly bootstrapping V. Bootstrap confidence intervals are calculated by the package "boot", see references. The default bootstrap type is "bca" (bias-corrected accelerated) as it enjoys the property of being second order accurate as well as transformation respecting (see Efron, p. 188). Note that no continuity correction is applied for 2x2 tables. Further note that large chi-squared test statistics might provide unreliable results with method "chi-squared" (see ?pchisq).
Value
A list with class cint containing these components:
References
See Also
ci_chisq_ncp.
Examples
ir <- iris ir$PL <- ir$Petal.Width > 1 ci_cramersv(ir[, c("Species", "PL")]) ci_cramersv(ir[, c("Species", "PL")], type = "bootstrap", R = 999) ci_cramersv(ir[, c("Species", "PL")], probs = c(0.05, 1))
8 ci_f_ncp
ci_cramersv(mtcars[c("am", "vs")]) ci_cramersv(mtcars[c("am", "vs")], test_adjustment = FALSE)
ci_f_ncp Confidence Interval for the Non-Centrality Parameter of the F Distri- bution
Description
Based on the inversion principle, parametric confidence intervals for the non-centrality parameter Delta of the F distribution are calculated. Note that we do not provide bootstrap confidence intervals here to keep the input interface simple. A positive lower (1-alpha)*100%-confidence limit for the ncp goes hand-in-hand with a significant F test at level alpha.
Usage
ci_f_ncp(x, df1 = NULL, df2 = NULL, probs = c(0.025, 0.975))
Arguments
x The result of lm or the F test statistic. df1 The numerator degree of freedom, e.g. the number of parameters (including the intercept) of a linear regression. Only used if x is a test statistic. df2 The denominator degree of freedom, e.g. n - df1 - 1 in a linear regression. Only used if x is a test statistic. probs Error probabilites. The default c(0.025, 0.975) gives a symmetric 95% confi- dence interval.
Details
Note that, according to ?pf, the results might be unreliable for very large F values.
Value
A list with class cint containing these components:
References
Smithson, M. (2003). Confidence intervals. Series: Quantitative Applications in the Social Sci- ences. New York, NY: Sage Publications.
10 ci_kurtosis
Value
A list with class cint containing these components:
References
Examples
set.seed(1) x <- rnorm(100) ci_IQR(x, R = 999)
ci_kurtosis Confidence Interval for the Kurtosis
Description
This function calculates bootstrap confidence intervals for the population kurtosis, see Details. Note that we use the version of the kurtosis that equals 3 for a theoretical normal distribution.
Usage
ci_kurtosis( x, probs = c(0.025, 0.975), type = "bootstrap", boot_type = c("bca", "perc", "norm", "basic"), R = 9999, seed = NULL, ... )
ci_kurtosis 11
Arguments
x A numeric vector. probs Error probabilites. The default c(0.025, 0.975) gives a symmetric 95% confi- dence interval. type Type of confidence interval. Currently not used as the only type is "bootstrap". boot_type Type of bootstrap confidence interval c("bca", "perc", "norm", "basic"). R The number of bootstrap resamples. seed An integer random seed. ... Further arguments passed to boot::boot.
Details
Bootstrap confidence intervals are calculated by the package "boot", see references. The default bootstrap type is "bca" (bias-corrected accelerated) as it enjoys the property of being second order accurate as well as transformation respecting (see Efron, p. 188).
Value
A list with class cint containing these components:
References
See Also
moments, ci_skewness.
Examples
set.seed(1) x <- rnorm(100) ci_kurtosis(x, R = 999)
ci_mean 13
References
Examples
set.seed(1) x <- rnorm(100) ci_mad(x, R = 999)
ci_mean Confidence Interval for the Population Mean
Description
This function calculates confidence intervals for the population mean. By default, Student’s t method is used. Alternatively, Wald and bootstrap confidence intervals are available.
Usage
ci_mean( x, probs = c(0.025, 0.975), type = c("t", "Wald", "bootstrap"), boot_type = c("stud", "bca", "perc", "norm", "basic"), R = 9999, seed = NULL, ... )
Arguments
x A numeric vector. probs Error probabilites. The default c(0.025, 0.975) gives a symmetric 95% confi- dence interval. type Type of confidence interval. One of "t" (default), "Wald", or "bootstrap". boot_type Type of bootstrap confidence interval ("stud", "bca", "perc", "norm", "basic"). Only used for type = "bootstrap".
14 ci_mean_diff
R The number of bootstrap resamples. Only used for type = "bootstrap". seed An integer random seed. Only used for type = "bootstrap". ... Further arguments passed to boot::boot.
Details
Bootstrap confidence intervals are calculated by the package "boot", see references. The default bootstrap type for the mean is "stud" (bootstrap t) as it enjoys the property of being second order accurate and has a stable variance estimator (see Efron, p. 188).
Value
A list with class cint containing these components:
References
Examples
x <- 1: ci_mean(x) ci_mean(x, type = "bootstrap", R = 999, seed = 1) ci_mean(x, type = "bootstrap", R = 999, probs = c(0.025, 1), seed = 1) ci_mean(x, type = "bootstrap", R = 999, probs = c(0, 0.975), seed = 1)
ci_mean_diff Confidence Interval for the Population Mean Difference
Description
This function calculates confidence intervals for the population value of mean(x) - mean(y). The default is Student’s method with Welch’s correction for unequal variances, but also bootstrap confi- dence intervals are available.
16 ci_median
References
Examples
x <- 10: y <- 1: ci_mean_diff(x, y) t.test(x, y)$conf.int ci_mean_diff(x, y, type = "bootstrap", R = 999)
ci_median Confidence Interval for the Population Median
Description
This function calculates confidence intervals for the population median by calling ci_quantile(...,q = 0.5). See ci_quantile for details.
Usage
ci_median( x, probs = c(0.025, 0.975), type = c("binomial", "bootstrap"), boot_type = c("bca", "perc", "norm", "basic"), R = 9999, seed = NULL, ... )
Arguments
x A numeric vector. probs Error probabilites. The default c(0.025, 0.975) gives a symmetric 95% confi- dence interval. type Type of confidence interval. One of "binomial" (default), or "bootstrap". boot_type Type of bootstrap confidence interval ("bca", "perc", "norm", "basic"). Only used for type = "bootstrap". R The number of bootstrap resamples. Only used for type = "bootstrap". seed An integer random seed. Only used for type = "bootstrap". ... Further arguments passed to boot::boot.
ci_median_diff 17
Value
A list with class cint containing these components:
See Also
ci_quantile.
Examples
ci_median(1:100) ci_quantile(1:100)
ci_median_diff Confidence Interval for the Population Median Difference of two Sam- ples
Description
This function calculates bootstrap confidence intervals for the population value of median(x) - me- dian(y) by calling ci_quantile_diff(, q = 0.5). See ci_quantile_diff for details.
Usage
ci_median_diff( x, y, probs = c(0.025, 0.975), type = "bootstrap", boot_type = c("bca", "perc", "norm", "basic"), R = 9999, seed = NULL, ... )
ci_proportion 19
Arguments
x A 2x2 table/matrix of frequencies, or a data.frame with exactly two columns. probs Error probabilites. The default c(0.025, 0.975) gives a symmetric 95% confi- dence interval.
Value
A list with class cint containing these components:
See Also
oddsratio.
Examples
x <- cbind(c(10, 5), c(4, 4)) ci_oddsratio(x)
ci_proportion Confidence Interval for a Population Proportion
Description
This function calculates confidence intervals for a population proportion. By default, "Clopper- Pearson" confidence intervals are calculated (via stats::binom.test). Further possibilities are "Wilson", "Agresti-Coull", and "bootstrap" (mainly added for consistency and didactic purposes).
Usage
ci_proportion( x, n = NULL, probs = c(0.025, 0.975), type = c("Clopper-Pearson", "Agresti-Coull", "Wilson", "bootstrap"), boot_type = c("bca", "perc", "stud", "norm", "basic"), R = 9999, seed = NULL, ... )
20 ci_proportion
Arguments
x A numeric vector of 0 and 1 or the number of successes. n The sample size. Only needed if x is a vector of length 1. probs Error probabilites. The default c(0.025, 0.975) gives a symmetric 95% confi- dence interval. type Type of confidence interval. One of "Clopper-Pearson" (the default), "Agresti–Coull", "Wilson", "bootstrap". boot_type Type of bootstrap confidence interval ("bca", "perc", "stud", "norm", "basic"). Only used for type = "bootstrap". R The number of bootstrap resamples. Only used for type = "bootstrap". seed An integer random seed. Only used for type = "bootstrap". ... Further arguments passed to boot::boot.
Details
Bootstrap confidence intervals are calculated by the package "boot", see references. The default bootstrap type for the proportion is "bca" (bias-corrected accelerated) as it enjoys the property of being second order accurate as well as transformation respecting (see Efron, p. 188). Note that we use the formula in https://en.wikipedia.org/wiki/Binomial_proportion_confidence_ interval which does not simplify the 0.975 quantile of the normal by 2 as sometimes in other references.
Value
A list with class cint containing these components:
References