Title: | Confidence Intervals |
---|---|
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. |
Authors: | Michael Mayer [aut, cre] |
Maintainer: | Michael Mayer <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0.3 |
Built: | 2024-11-21 04:35:32 UTC |
Source: | https://github.com/mayer79/confintr |
This function calculates CIs for the non-centrality parameter (NCP) of the
-distribution. A positive lower
-confidence
limit for the NCP goes hand-in-hand with a significant association test at level
.
ci_chisq_ncp( x, probs = c(0.025, 0.975), correct = TRUE, type = c("chi-squared", "bootstrap"), boot_type = c("bca", "perc", "norm", "basic"), R = 9999L, seed = NULL, ... )
ci_chisq_ncp( x, probs = c(0.025, 0.975), correct = TRUE, type = c("chi-squared", "bootstrap"), boot_type = c("bca", "perc", "norm", "basic"), R = 9999L, seed = NULL, ... )
x |
The result of |
probs |
Lower and upper probabilities, by default |
correct |
Should Yates continuity correction be applied to the 2x2 case? The
default is |
type |
Type of CI. One of "chi-squared" (default) or "bootstrap". |
boot_type |
Type of bootstrap CI. Only used for |
R |
The number of bootstrap resamples. Only used for |
seed |
An integer random seed. Only used for |
... |
Further arguments passed to |
By default, CIs are computed by Chi-squared test inversion. This can be unreliable for very large test statistics. The default bootstrap type is "bca".
An object of class "cint", see ci_mean()
for details.
Smithson, M. (2003). Confidence intervals. Series: Quantitative Applications in the Social Sciences. New York, NY: Sage Publications.
ci_chisq_ncp(mtcars[c("am", "vs")]) ci_chisq_ncp(mtcars[c("am", "vs")], type = "bootstrap", R = 999) # Use larger R
ci_chisq_ncp(mtcars[c("am", "vs")]) ci_chisq_ncp(mtcars[c("am", "vs")], type = "bootstrap", R = 999) # Use larger R
This function calculates CIs for a population correlation coefficient.
For Pearson correlation, "normal" CIs are available (by stats::cor.test()
).
Also bootstrap CIs are supported (by default "bca", and the only option for
rank correlations).
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 = 9999L, seed = NULL, ... )
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 = 9999L, seed = NULL, ... )
x |
A numeric vector or a |
y |
A numeric vector (only used if |
probs |
Lower and upper probabilities, by default |
method |
Type of correlation coefficient, one of "pearson" (default), "kendall", or "spearman". For the latter two, only bootstrap CIs are supported. |
type |
Type of CI. One of "normal" (the default) or "bootstrap" (the only option for rank-correlations). |
boot_type |
Type of bootstrap CI. Only used for |
R |
The number of bootstrap resamples. Only used for |
seed |
An integer random seed. Only used for |
... |
Further arguments passed to |
An object of class "cint", see ci_mean()
for details.
ci_cor(iris[1:2]) ci_cor(iris[1:2], type = "bootstrap", R = 999) # Use larger R ci_cor(iris[1:2], method = "spearman", type = "bootstrap", R = 999) # Use larger R
ci_cor(iris[1:2]) ci_cor(iris[1:2], type = "bootstrap", R = 999) # Use larger R ci_cor(iris[1:2], method = "spearman", type = "bootstrap", R = 999) # Use larger R
This function calculates CIs for the population Cramer's V. By default, a parametric approach based on the non-centrality parameter (NCP) of the chi-squared distribution is utilized. Alternatively, bootstrap CIs are available (default "bca"), also by boostrapping CIs for the NCP and then mapping the result back to Cramer's V.
ci_cramersv( x, probs = c(0.025, 0.975), type = c("chi-squared", "bootstrap"), boot_type = c("bca", "perc", "norm", "basic"), R = 9999L, seed = NULL, test_adjustment = TRUE, ... )
ci_cramersv( x, probs = c(0.025, 0.975), type = c("chi-squared", "bootstrap"), boot_type = c("bca", "perc", "norm", "basic"), R = 9999L, seed = NULL, test_adjustment = TRUE, ... )
x |
The result of |
probs |
Lower and upper probabilities, by default |
type |
Type of CI. One of "chi-squared" (default) or "bootstrap". |
boot_type |
Type of bootstrap CI. Only used for |
R |
The number of bootstrap resamples. Only used for |
seed |
An integer random seed. Only used for |
test_adjustment |
Adjustment to allow for test of association, see Details.
The default is |
... |
Further arguments passed to |
A positive lower -confidence limit for the NCP goes
hand-in-hand with a significant association test at level
. 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 the lower bound for Cramer's V as well.
Without this slightly conservative adjustment, the lower limit for V would always be
positive since the CI for V is found by
, where
is the
smaller number of levels in the two variables (see Smithson, p.40).
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.
Further note that no continuity correction is applied for 2x2 tables,
and that large chi-squared test statistics might provide unreliable results with
method "chi-squared", see stats::pchisq()
.
An object of class "cint", see ci_mean()
for details.
Smithson, M. (2003). Confidence intervals. Series: Quantitative Applications in the Social Sciences. New York, NY: Sage Publications.
# Example from Smithson, M., page 41 test_scores <- as.table( rbind( Private = c(6, 14, 17, 9), Public = c(30, 32, 17, 3) ) ) suppressWarnings(X2 <- stats::chisq.test(test_scores)) ci_cramersv(X2)
# Example from Smithson, M., page 41 test_scores <- as.table( rbind( Private = c(6, 14, 17, 9), Public = c(30, 32, 17, 3) ) ) suppressWarnings(X2 <- stats::chisq.test(test_scores)) ci_cramersv(X2)
Based on the inversion principle, parametric CIs for the non-centrality parameter (NCP) Delta of the F distribution are calculated. To keep the input interface simple, we do not provide bootstrap CIs here.
ci_f_ncp(x, df1 = NULL, df2 = NULL, probs = c(0.025, 0.975))
ci_f_ncp(x, df1 = NULL, df2 = NULL, probs = c(0.025, 0.975))
x |
The result of |
df1 |
The numerator df. Only used if |
df2 |
The denominator df. Only used if |
probs |
Lower and upper probabilities, by default |
A positive lower -confidence limit for the NCP goes
hand-in-hand with a significant F test at level
.
According to
stats::pf()
, the results might be unreliable for very large F values.
An object of class "cint", see ci_mean()
for details.
Smithson, M. (2003). Confidence intervals. Series: Quantitative Applications in the Social Sciences. New York, NY: Sage Publications.
fit <- lm(Sepal.Length ~ ., data = iris) ci_f_ncp(fit) ci_f_ncp(fit, probs = c(0.05, 1))
fit <- lm(Sepal.Length ~ ., data = iris) ci_f_ncp(fit) ci_f_ncp(fit, probs = c(0.05, 1))
This function calculates bootstrap CIs (by default "bca") for the population interquartile range (IQR), i.e., the difference between first and third quartile.
ci_IQR( x, probs = c(0.025, 0.975), type = "bootstrap", boot_type = c("bca", "perc", "norm", "basic"), R = 9999L, seed = NULL, ... )
ci_IQR( x, probs = c(0.025, 0.975), type = "bootstrap", boot_type = c("bca", "perc", "norm", "basic"), R = 9999L, seed = NULL, ... )
x |
A numeric vector. |
probs |
Lower and upper probabilities, by default |
type |
Type of CI. Currently not used as the only type is |
boot_type |
Type of bootstrap CI c("bca", "perc", "norm", "basic"). |
R |
The number of bootstrap resamples. Only used for |
seed |
An integer random seed. Only used for |
... |
Further arguments passed to |
An object of class "cint", see ci_mean()
for details.
x <- rnorm(100) ci_IQR(x, R = 999) # Use larger R
x <- rnorm(100) ci_IQR(x, R = 999) # Use larger R
This function calculates bootstrap CIs for the population kurtosis. Note that we use the version of the kurtosis that equals 3 under a normal distribution, i.e., we are not calculating the excess kurtosis. By default, bootstrap type "bca" is used.
ci_kurtosis( x, probs = c(0.025, 0.975), type = "bootstrap", boot_type = c("bca", "perc", "norm", "basic"), R = 9999L, seed = NULL, ... )
ci_kurtosis( x, probs = c(0.025, 0.975), type = "bootstrap", boot_type = c("bca", "perc", "norm", "basic"), R = 9999L, seed = NULL, ... )
x |
A numeric vector. |
probs |
Lower and upper probabilities, by default |
type |
Type of CI. Currently not used as the only type is |
boot_type |
Type of bootstrap CI. Only used for |
R |
The number of bootstrap resamples. Only used for |
seed |
An integer random seed. Only used for |
... |
Further arguments passed to |
An object of class "cint", see ci_mean()
for details.
x <- 1:20 ci_kurtosis(x, R = 999) # Use larger R
x <- 1:20 ci_kurtosis(x, R = 999) # Use larger R
This function calculates bootstrap CIs (default: "bca") for the population median
absolute deviation (MAD), see stats::mad()
for more information.
ci_mad( x, probs = c(0.025, 0.975), constant = 1.4826, type = "bootstrap", boot_type = c("bca", "perc", "norm", "basic"), R = 9999L, seed = NULL, ... )
ci_mad( x, probs = c(0.025, 0.975), constant = 1.4826, type = "bootstrap", boot_type = c("bca", "perc", "norm", "basic"), R = 9999L, seed = NULL, ... )
x |
A numeric vector. |
probs |
Lower and upper probabilities, by default |
constant |
Scaling factor applied. The default (1.4826) ensures that the MAD equals the standard deviation for a theoretical normal distribution. |
type |
Type of CI. Currently not used as the only type is |
boot_type |
Type of bootstrap CI c("bca", "perc", "norm", "basic"). |
R |
The number of bootstrap resamples. Only used for |
seed |
An integer random seed. Only used for |
... |
Further arguments passed to |
An object of class "cint", see ci_mean()
for details.
x <- rnorm(100) ci_mad(x, R = 999) # Use larger R
x <- rnorm(100) ci_mad(x, R = 999) # Use larger R
This function calculates CIs for the population mean. By default, Student's t method is used. Alternatively, Wald and bootstrap CIs are available.
ci_mean( x, probs = c(0.025, 0.975), type = c("t", "Wald", "bootstrap"), boot_type = c("stud", "bca", "perc", "norm", "basic"), R = 9999L, seed = NULL, ... )
ci_mean( x, probs = c(0.025, 0.975), type = c("t", "Wald", "bootstrap"), boot_type = c("stud", "bca", "perc", "norm", "basic"), R = 9999L, seed = NULL, ... )
x |
A numeric vector. |
probs |
Lower and upper probabilities, by default |
type |
Type of CI. One of "t" (default), "Wald", or "bootstrap". |
boot_type |
Type of bootstrap CI. Only used for |
R |
The number of bootstrap resamples. Only used for |
seed |
An integer random seed. Only used for |
... |
Further arguments passed to |
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).
An object of class "cint" containing these components:
parameter
: Parameter specification.
interval
: CI for the parameter.
estimate
: Parameter estimate.
probs
: Lower and upper probabilities.
type
: Type of interval.
info
: Additional description.
Smithson, M. (2003). Confidence intervals. Series: Quantitative Applications in the Social Sciences. New York, NY: Sage Publications.
Efron, B. and Tibshirani R. J. (1994). An Introduction to the Bootstrap. Chapman & Hall/CRC.
x <- 1:100 ci_mean(x) ci_mean(x, type = "bootstrap", R = 999, seed = 1) # Use larger R
x <- 1:100 ci_mean(x) ci_mean(x, type = "bootstrap", R = 999, seed = 1) # Use larger R
This function calculates CIs 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 CIs are available.
ci_mean_diff( x, y, probs = c(0.025, 0.975), var.equal = FALSE, type = c("t", "bootstrap"), boot_type = c("stud", "bca", "perc", "norm", "basic"), R = 9999L, seed = NULL, ... )
ci_mean_diff( x, y, probs = c(0.025, 0.975), var.equal = FALSE, type = c("t", "bootstrap"), boot_type = c("stud", "bca", "perc", "norm", "basic"), R = 9999L, seed = NULL, ... )
x |
A numeric vector. |
y |
A numeric vector. |
probs |
Lower and upper probabilities, by default |
var.equal |
Should the two variances be treated as being equal?
The default is |
type |
Type of CI. One of "t" (default), or "bootstrap". |
boot_type |
Type of bootstrap CI. Only used for |
R |
The number of bootstrap resamples. Only used for |
seed |
An integer random seed. Only used for |
... |
Further arguments passed to |
The default bootstrap type is "stud" (bootstrap t) as it has a stable variance
estimator (see Efron, p. 188). Resampling is done within sample.
When boot_type = "stud"
, the standard error is estimated by Welch's method
if var.equal = FALSE
(the default), and by pooling otherwise.
Thus, var.equal
not only has an effect for the classic Student approach
(type = "t"
) but also for boot_type = "stud"
.
An object of class "cint", see ci_mean()
for details.
Efron, B. and Tibshirani R. J. (1994). An Introduction to the Bootstrap. Chapman & Hall/CRC.
x <- 10:30 y <- 1:30 ci_mean_diff(x, y) t.test(x, y)$conf.int ci_mean_diff(x, y, type = "bootstrap", R = 999) # Use larger R
x <- 10:30 y <- 1:30 ci_mean_diff(x, y) t.test(x, y)$conf.int ci_mean_diff(x, y, type = "bootstrap", R = 999) # Use larger R
This function calculates CIs for the population median by calling ci_quantile()
.
ci_median( x, probs = c(0.025, 0.975), type = c("binomial", "bootstrap"), boot_type = c("bca", "perc", "norm", "basic"), R = 9999L, seed = NULL, ... )
ci_median( x, probs = c(0.025, 0.975), type = c("binomial", "bootstrap"), boot_type = c("bca", "perc", "norm", "basic"), R = 9999L, seed = NULL, ... )
x |
A numeric vector. |
probs |
Lower and upper probabilities, by default |
type |
Type of CI. One of "binomial" (default), or "bootstrap". |
boot_type |
Type of bootstrap CI. Only used for |
R |
The number of bootstrap resamples. Only used for |
seed |
An integer random seed. Only used for |
... |
Further arguments passed to |
An object of class "cint", see ci_mean()
for details.
ci_median(1:100)
ci_median(1:100)
This function calculates bootstrap CIs for the population value of
median(x) - median(y) by calling ci_quantile_diff()
.
ci_median_diff( x, y, probs = c(0.025, 0.975), type = "bootstrap", boot_type = c("bca", "perc", "norm", "basic"), R = 9999L, seed = NULL, ... )
ci_median_diff( x, y, probs = c(0.025, 0.975), type = "bootstrap", boot_type = c("bca", "perc", "norm", "basic"), R = 9999L, seed = NULL, ... )
x |
A numeric vector. |
y |
A numeric vector. |
probs |
Lower and upper probabilities, by default |
type |
Type of CI. Currently, "bootstrap" is the only option. |
boot_type |
Type of bootstrap CI. Only used for |
R |
The number of bootstrap resamples. Only used for |
seed |
An integer random seed. Only used for |
... |
Further arguments passed to |
An object of class "cint", see ci_mean()
for details.
x <- 10:30 y <- 1:30 ci_median_diff(x, y, R = 999) # Use larger value for R
x <- 10:30 y <- 1:30 ci_median_diff(x, y, R = 999) # Use larger value for R
This function calculates a CI for the odds ratio in a 2x2 table/matrix or a
data frame with two columns. The CI is obtained through stats::fisher.test()
.
Bootstrap CIs are not available.
ci_oddsratio(x, probs = c(0.025, 0.975))
ci_oddsratio(x, probs = c(0.025, 0.975))
x |
A 2x2 matrix/table of counts, or a |
probs |
Lower and upper probabilities, by default |
An object of class "cint", see ci_mean()
for details.
x <- cbind(c(10, 5), c(4, 4)) ci_oddsratio(x)
x <- cbind(c(10, 5), c(4, 4)) ci_oddsratio(x)
This function calculates CIs for a population proportion. By default,
"Clopper-Pearson" CIs are calculated (via stats::binom.test()
).
Further possibilities are "Wilson" (without continuity correction),
"Agresti-Coull" (using normal quantile instead of +2 correction),
and "bootstrap" (by default "bca").
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 = 9999L, seed = NULL, ... )
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 = 9999L, seed = NULL, ... )
x |
A numeric vector with one value (0/1) per observation, or the number of successes. |
n |
The sample size. Only needed if |
probs |
Lower and upper probabilities, by default |
type |
Type of CI. One of "Clopper-Pearson" (the default), "Agresti–Coull", "Wilson", "bootstrap". |
boot_type |
Type of bootstrap CI. Only used for |
R |
The number of bootstrap resamples. Only used for |
seed |
An integer random seed. Only used for |
... |
Further arguments passed to |
Note that we use the formulas for the Wilson and Agresti-Coull intervals in
https://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval.
They agree with binom::binom.confint(x, n, method = "ac"/"wilson")
.
An object of class "cint", see ci_mean()
for details.
Clopper, C. and Pearson, E. S. (1934). The use of confidence or fiducial limits illustrated in the case of the binomial. Biometrika. 26 (4).
Wilson, E. B. (1927). Probable inference, the law of succession, and statistical inference. Journal of the American Statistical Association, 22 (158).
Agresti, A. and Coull, B. A. (1998). Approximate is better than 'exact' for interval estimation of binomial proportions. The American Statistician, 52 (2).
x <- rep(0:1, times = c(50, 100)) ci_proportion(x) ci_proportion(x, type = "Wilson") ci_proportion(x, type = "Agresti-Coull")
x <- rep(0:1, times = c(50, 100)) ci_proportion(x) ci_proportion(x, type = "Wilson") ci_proportion(x, type = "Agresti-Coull")
This function calculates CIs for a population quantile. By default, distribution-free CIs based on the binomial distribution are calculated, see Hahn and Meeker. Alternatively, bootstrap CIs are available (default "bca").
ci_quantile( x, q = 0.5, probs = c(0.025, 0.975), type = c("binomial", "bootstrap"), boot_type = c("bca", "perc", "norm", "basic"), R = 9999L, seed = NULL, ... )
ci_quantile( x, q = 0.5, probs = c(0.025, 0.975), type = c("binomial", "bootstrap"), boot_type = c("bca", "perc", "norm", "basic"), R = 9999L, seed = NULL, ... )
x |
A numeric vector. |
q |
A single probability value determining the quantile (0.5 for median). |
probs |
Lower and upper probabilities, by default |
type |
Type of CI. One of "binomial" (default), or "bootstrap". |
boot_type |
Type of bootstrap CI. Only used for |
R |
The number of bootstrap resamples. Only used for |
seed |
An integer random seed. Only used for |
... |
Further arguments passed to |
An object of class "cint", see ci_mean()
for details.
Hahn, G. and Meeker, W. (1991). Statistical Intervals. Wiley 1991.
x <- 1:100 ci_quantile(x, q = 0.25)
x <- 1:100 ci_quantile(x, q = 0.25)
This function calculates bootstrap CIs for the population value of q-quantile(x) - q-quantile(y), by default using "bca" bootstrap. Resampling is done within sample.
ci_quantile_diff( x, y, q = 0.5, probs = c(0.025, 0.975), type = "bootstrap", boot_type = c("bca", "perc", "norm", "basic"), R = 9999L, seed = NULL, ... )
ci_quantile_diff( x, y, q = 0.5, probs = c(0.025, 0.975), type = "bootstrap", boot_type = c("bca", "perc", "norm", "basic"), R = 9999L, seed = NULL, ... )
x |
A numeric vector. |
y |
A numeric vector. |
q |
A single probability value determining the quantile (0.5 for median). |
probs |
Lower and upper probabilities, by default |
type |
Type of CI. Currently, "bootstrap" is the only option. |
boot_type |
Type of bootstrap CI. Only used for |
R |
The number of bootstrap resamples. Only used for |
seed |
An integer random seed. Only used for |
... |
Further arguments passed to |
An object of class "cint", see ci_mean()
for details.
x <- 10:30 y <- 1:30 ci_quantile_diff(x, y, R = 999) # Use larger R
x <- 10:30 y <- 1:30 ci_quantile_diff(x, y, R = 999) # Use larger R
This function calculates parametric CIs for the population .
It is based on CIs for the non-centrality parameter
of the F
distribution found by test inversion. Values of
are mapped to
by
,
where the
are the degrees of freedom of the F test statistic.
A positive lower
-confidence limit for the
goes hand-in-hand with a significant F test at level
.
ci_rsquared(x, df1 = NULL, df2 = NULL, probs = c(0.025, 0.975))
ci_rsquared(x, df1 = NULL, df2 = NULL, probs = c(0.025, 0.975))
x |
The result of |
df1 |
The numerator df. Only used if |
df2 |
The denominator df. Only used if |
probs |
Lower and upper probabilities, by default |
According to stats::pf()
, the results might be unreliable for very large F values.
Note that we do not provide bootstrap CIs here to keep the input interface simple.
An object of class "cint", see ci_mean()
for details.
Smithson, M. (2003). Confidence intervals. Series: Quantitative Applications in the Social Sciences. New York, NY: Sage Publications.
fit <- lm(Sepal.Length ~ ., data = iris) summary(fit)$r.squared ci_rsquared(fit) ci_rsquared(fit, probs = c(0.05, 1))
fit <- lm(Sepal.Length ~ ., data = iris) summary(fit)$r.squared ci_rsquared(fit) ci_rsquared(fit, probs = c(0.05, 1))
This function calculates CIs for the population standard deviation.
They are derived from CIs for the variance by taking the square-root, see ci_var()
.
ci_sd( x, probs = c(0.025, 0.975), type = c("chi-squared", "bootstrap"), boot_type = c("bca", "perc", "stud", "norm", "basic"), R = 9999L, seed = NULL, ... )
ci_sd( x, probs = c(0.025, 0.975), type = c("chi-squared", "bootstrap"), boot_type = c("bca", "perc", "stud", "norm", "basic"), R = 9999L, seed = NULL, ... )
x |
A numeric vector. |
probs |
Lower and upper probabilities, by default |
type |
Type of CI. One of |
boot_type |
Type of bootstrap CI. Only used for |
R |
The number of bootstrap resamples. Only used for |
seed |
An integer random seed. Only used for |
... |
Further arguments passed to |
An object of class "cint", see ci_mean()
for details.
x <- 1:100 ci_sd(x) ci_sd(x, type = "bootstrap", R = 999) # Use larger R
x <- 1:100 ci_sd(x) ci_sd(x, type = "bootstrap", R = 999) # Use larger R
This function calculates bootstrap CIs for the population skewness. By default, bootstrap type "bca" is used.
ci_skewness( x, probs = c(0.025, 0.975), type = "bootstrap", boot_type = c("bca", "perc", "norm", "basic"), R = 9999L, seed = NULL, ... )
ci_skewness( x, probs = c(0.025, 0.975), type = "bootstrap", boot_type = c("bca", "perc", "norm", "basic"), R = 9999L, seed = NULL, ... )
x |
A numeric vector. |
probs |
Lower and upper probabilities, by default |
type |
Type of CI. Currently not used as the only type is |
boot_type |
Type of bootstrap CI. Only used for |
R |
The number of bootstrap resamples. Only used for |
seed |
An integer random seed. Only used for |
... |
Further arguments passed to |
An object of class "cint", see ci_mean()
for details.
x <- 1:20 ci_skewness(x, R = 999) # Use larger R
x <- 1:20 ci_skewness(x, R = 999) # Use larger R
This function calculates CIs for the population variance.
ci_var( x, probs = c(0.025, 0.975), type = c("chi-squared", "bootstrap"), boot_type = c("bca", "perc", "stud", "norm", "basic"), R = 9999L, seed = NULL, ... )
ci_var( x, probs = c(0.025, 0.975), type = c("chi-squared", "bootstrap"), boot_type = c("bca", "perc", "stud", "norm", "basic"), R = 9999L, seed = NULL, ... )
x |
A numeric vector. |
probs |
Lower and upper probabilities, by default |
type |
Type of CI. One of |
boot_type |
Type of bootstrap CI. Only used for |
R |
The number of bootstrap resamples. Only used for |
seed |
An integer random seed. Only used for |
... |
Further arguments passed to |
By default, classic CIs are calculated based on the chi-squared distribution, assuming normal distribution (see Smithson). Bootstrap CIs are also available (default: "bca"). We recommend them for the non-normal case.
The stud
(bootstrap t) bootstrap uses the standard error of the sample variance
given in Wilks.
An object of class "cint", see ci_mean()
for details.
Smithson, M. (2003). Confidence intervals. Series: Quantitative Applications in the Social Sciences. New York, NY: Sage Publications.
S.S. Wilks (1962), Mathematical Statistics, Wiley & Sons.
x <- 1:100 ci_var(x) ci_var(x, type = "bootstrap", R = 999) # Use larger R
x <- 1:100 ci_var(x) ci_var(x, type = "bootstrap", R = 999) # Use larger R
This function calculates Cramer's V, a measure of association between two categorical variables.
cramersv(x)
cramersv(x)
x |
The result of |
Cramer's V is a scaled version of the chi-squared test statistic and
takes values in
. It is calculated as
, where
is the number of observations,
and
is the smaller of the number of levels of the two variables.
Yates continuity correction is never applied. So in the 2x2 case, if x
is the
result of stats::chisq.test()
, make sure no continuity correction was applied.
Otherwise, results can be inconsistent.
A numeric vector of length one.
Cramer, Harald. 1946. Mathematical Methods of Statistics. Princeton: Princeton University Press, page 282 (Chapter 21. The two-dimensional case).
cramersv(mtcars[c("am", "vs")])
cramersv(mtcars[c("am", "vs")])
Checks if an object inherits class "cint".
is.cint(x)
is.cint(x)
x |
Any object. |
A logical vector of length one.
is.cint(ci_proportion(5, 20)) is.cint(c(1, 2))
is.cint(ci_proportion(5, 20)) is.cint(c(1, 2))
Defined as the ratio of the 4th central moment and the squared second central moment. Under perfect normality, the kurtosis equals 3. Put differently, we do not show "excess kurtosis" but rather kurtosis.
kurtosis(z, na.rm = TRUE)
kurtosis(z, na.rm = TRUE)
z |
A numeric vector. |
na.rm |
Logical flag indicating whether to remove missing values or not.
Default is |
Numeric vector of length 1.
kurtosis(1:10) kurtosis(rnorm(1000))
kurtosis(1:10) kurtosis(rnorm(1000))
Calculates central or non-central sample moments.
moment(z, p = 1, central = TRUE, na.rm = TRUE)
moment(z, p = 1, central = TRUE, na.rm = TRUE)
z |
A numeric vector. |
p |
Order of moment. |
central |
Should central moment be calculated? Default is |
na.rm |
Logical flag indicating whether to remove missing values or not.
Default is |
Numeric vector of length 1.
moment(1:10, p = 1) moment(1:10, p = 1, central = FALSE) moment(1:10, p = 2) / stats::var(1:10)
moment(1:10, p = 1) moment(1:10, p = 1, central = FALSE) moment(1:10, p = 2) / stats::var(1:10)
This function calculates the odds ratio of a 2x2 table/matrix, or a data frame with two columns.
oddsratio(x)
oddsratio(x)
x |
A 2x2 matrix/table of counts, or a |
The numerator equals the ratio of the top left entry and the bottom left entry of the
2x2 table, while the denominator equals the ratio of the top right entry and
the bottom right entry. The result is usually slightly different from the one of
stats::fisher.test()
, which is based on the ML estimate of the odds ratio.
A numeric vector of length one.
tab <- cbind(c(10, 5), c(4, 4)) oddsratio(tab)
tab <- cbind(c(10, 5), c(4, 4)) oddsratio(tab)
Print method for an object of class "cint".
## S3 method for class 'cint' print(x, digits = getOption("digits"), ...)
## S3 method for class 'cint' print(x, digits = getOption("digits"), ...)
x |
A on object of class "cint". |
digits |
Number of digits used to format numbers. |
... |
Further arguments passed from other methods. |
Invisibly, the input is returned.
ci_mean(1:100)
ci_mean(1:100)
Functions to calculate standard errors of different statistics. The availability of a standard error (or statistic proportional to it) allows to apply "stud" (bootstrap t) bootstrap.
se_mean(z, na.rm = TRUE, ...) se_mean_diff(z, y, na.rm = TRUE, var.equal = FALSE, ...) se_var(z, na.rm = TRUE, ...) se_proportion(z, na.rm = TRUE, ...)
se_mean(z, na.rm = TRUE, ...) se_mean_diff(z, y, na.rm = TRUE, var.equal = FALSE, ...) se_var(z, na.rm = TRUE, ...) se_proportion(z, na.rm = TRUE, ...)
z |
Numeric vector. |
na.rm |
Should missing values be removed before calculation? Default is |
... |
Further arguments to be passed from other methods. |
y |
Numeric vector. |
var.equal |
Should the variances be treated as being equal? Default is |
A numeric vector of length one.
se_mean(1:100)
se_mean(1:100)
Calculates sample skewness. A value of 0 refers to a perfectly symmetric distribution.
skewness(z, na.rm = TRUE)
skewness(z, na.rm = TRUE)
z |
A numeric vector. |
na.rm |
Logical flag indicating whether to remove missing values or not.
Default is |
Numeric vector of length 1.
skewness(1:10) skewness(rexp(100))
skewness(1:10) skewness(rexp(100))