ci.mean: Confidence Interval for the Arithmetic Mean and Median

View source: R/ci.mean.R

ci.meanR Documentation

Confidence Interval for the Arithmetic Mean and Median

Description

The function ci.mean computes a confidence interval for the arithmetic mean with known or unknown population standard deviation or population variance and the function ci.median computes the confidence interval for the median for one or more variables, optionally by a grouping and/or split variable.

Usage

ci.mean(..., data = NULL, sigma = NULL, sigma2 = NULL, adjust = FALSE,
        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.median(..., data = NULL, 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.mean(x1, x2, 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 ....

sigma

a numeric vector indicating the population standard deviation when computing confidence intervals for the arithmetic mean with known standard deviation Note that either argument sigma or argument sigma2 is specified and it is only possible to specify one value for the argument sigma even though multiple variables are specified in x.

sigma2

a numeric vector indicating the population variance when computing confidence intervals for the arithmetic mean with known variance. Note that either argument sigma or argument sigma2 is specified and it is only possible to specify one value for the argument sigma2 even though multiple variables are specified in x.

adjust

logical: if TRUE (default), difference-adjustment for the confidence intervals for the arithmetic means is applied.

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. Note that a grouping variable can only be used when computing confidence intervals with unknown population standard deviation and population variance.

split

either a character string indicating the variable name of the split variable in ... or data, or a vector representing the split variable. Note that a grouping variable can only be used when computing confidence intervals with unknown population standard deviation and population variance.

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.

check

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

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.

output

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

Details

A difference-adjusted confidence interval (Baguley, 2012) for the arithmetic mean can be computed by specifying adjust = TRUE.

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

Baguley, T. S. (2012). Serious stats: A guide to advanced statistics for the behavioral sciences. Palgrave Macmillan.

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

See Also

test.z, test.t, ci.mean.diff, ci.prop, ci.var, ci.sd, descript

Examples

# Example 1a: Two-Sided 95% Confidence Interval for the Arithmetic Mean for 'mpg'
ci.mean(mtcars$mpg)

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

# Example 2: Two-Sided 95% Confidence Interval for the Median
ci.median(mtcars$mpg)

# Example 3: Two-Sided 95% Difference-Adjusted Confidence Interval
ci.mean(mtcars$mpg, adjust = TRUE)

# Example 4: Two-Sided 95% Confidence Interval with known standard deviation
ci.mean(mtcars$mpg, sigma = 1.2)

# Example 5: Two-Sided 95% Confidence Interval with known variance
ci.mean(mtcars$mpg, sigma2 = 2.5)

# Example 6: One-Sided 95% Confidence Interval
ci.mean(mtcars$mpg, alternative = "less")

# Example 7: Two-Sided 99% Confidence Interval
ci.mean(mtcars$mpg, conf.level = 0.99)

# Example 8: Two-Sided 95% Confidence Interval, print results with 3 digits
ci.mean(mtcars$mpg, digits = 3)

# Example 9a: Two-Sided 95% Confidence Interval for 'mpg', 'cyl', and 'disp',
# listwise deletion for missing data
ci.mean(mtcars[, c("mpg", "cyl", "disp")], na.omit = TRUE)
#
# Example 9b: Alternative specification using the 'data' argument
ci.mean(mpg:disp, data = mtcars, na.omit = TRUE)

# Example 10a: Two-Sided 95% Confidence Interval, analysis by 'vs' separately
ci.mean(mtcars[, c("mpg", "cyl", "disp")], group = mtcars$vs)

# Example 10b: Alternative specification using the 'data' argument
ci.mean(mpg:disp, data = mtcars, group = "vs")

# Example 11: Two-Sided 95% Confidence Interval, analysis by 'vs' separately,
# sort by variables
ci.mean(mtcars[, c("mpg", "cyl", "disp")], group = mtcars$vs, sort.var = TRUE)

# Example 12: Two-Sided 95% Confidence Interval, split analysis by 'am'
ci.mean(mtcars[, c("mpg", "cyl", "disp")], split = mtcars$am)

# Example 13a: Two-Sided 95% Confidence Interval for 'mpg', 'cyl', and 'disp'
# analysis by 'vs' separately, split analysis by 'am'
ci.mean(mtcars[, c("mpg", "cyl", "disp")], group = mtcars$vs, split = mtcars$am)

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

## Not run: 
# Example 14: Write results into a text file
ci.mean(mpg:disp, data = mtcars, group = "vs", split = "am", write = "Means.txt")

## End(Not run)

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

Related to ci.mean in misty...