ci.var: Confidence Interval for the Variance and Standard Deviation

View source: R/ci.var.R

ci.varR Documentation

Confidence Interval for the Variance and Standard Deviation

Description

The function ci.var computes the confidence interval for the variance, and the function ci.sd computes the confidence interval for the standard deviation for one or more variables, optionally by a grouping and/or split variable.

Usage

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

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

Arguments

...

a numeric vector, matrix or data frame with numeric variables, 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.var(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 "chisq", or "bonett" (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 confidence interval based on the chi-square distribution is computed by specifying method = "chisq", while the Bonett (2006) confidence interval is requested by specifying method = "bonett". By default, the Bonett confidence interval interval is computed which performs well under moderate departure from normality, while the confidence interval based on the chi-square distribution is highly sensitive to minor violations of the normality assumption and its performance does not improve with increasing sample size. Note that at least four valid observations are needed to compute the Bonett confidence interval.

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

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

Bonett, D. G. (2006). Approximate confidence interval for standard deviation of nonnormal distributions. Computational Statistics and Data Analysis, 50, 775-782. https://doi.org/10.1016/j.csda.2004.10.003

See Also

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

Examples

# Example 1a: Two-Sided 95% CI for the variance for 'mpg'
ci.var(mtcars$mpg)

# Example 1b: Alternative specification using the 'data' argument
ci.var(mpg, data = mtcars)

# Example 2a: Two-Sided 95% CI for the standard deviation for 'mpg'
ci.sd(mtcars$mpg)

# Example 2b: Alternative specification using the 'data' argument
ci.sd(mpg, data = mtcars)

# Example 3: Two-Sided 95% CI using chi square distribution
ci.var(mtcars$mpg, method = "chisq")

# Example 4: One-Sided 95% CI
ci.var(mtcars$mpg, alternative = "less")

# Example 5: Two-Sided 99% CI
ci.var(mtcars$mpg, conf.level = 0.99)

# Example 6: Two-Sided 95% CI, print results with 3 digits
ci.var(mtcars$mpg, digits = 3)

# Example 7a: Two-Sided 95% CI for 'mpg', 'disp', and 'hp',
# listwise deletion for missing data
ci.var(mtcars[, c("mpg", "disp", "hp")])

# Example 7b: Alternative specification using the 'data' argument
ci.var(mpg:hp, data = mtcars)

# Example 8a: Two-Sided 95% CI, analysis by 'vs' separately
ci.var(mtcars[, c("mpg", "disp", "hp")], group = mtcars$vs)

# Example 8b: Alternative specification using the 'data' argument
ci.var(mpg:hp, data = mtcars, group = "vs")

# Example 9: Two-Sided 95% CI for, analysis by 'vs' separately, sort by variables
ci.var(mtcars[, c("mpg", "disp", "hp")], group = mtcars$vs, sort.var = TRUE)

# Example 10: Two-Sided 95% CI, split analysis by 'vs'
ci.var(mtcars[, c("mpg", "disp", "hp")], split = mtcars$vs)

# Example 11a: Two-Sided 95% CI, analysis by 'vs' separately, split analysis by 'am'
ci.var(mtcars[, c("mpg", "disp", "hp")], group = mtcars$vs, split = mtcars$am)

# Example 11b: Alternative specification using the 'data' argument
ci.var(mpg:hp, data = mtcars, group = "vs", split = "am")

## Not run: 
# Example 12: Write results into a text file
ci.var(mpg:hp, data = mtcars, group = "vs", split = "am", write = "Variance.txt")

## End(Not run)

misty documentation built on June 29, 2024, 9:07 a.m.

Related to ci.var in misty...