std.dev: Calculate a Sample or Population Standard Deviation

Description Usage Arguments Value Note Author(s) Examples

Description

Calculates the standard deviation of a set of numeric values, making an appropriate adjustment if using population rather than sample data.

Usage

1
std.dev(x, na.rm=TRUE, sample=TRUE)

Arguments

x

A numeric vector.

na.rm

If TRUE (default) observations with a missing value of x are removed before applying the test.

sample

If TRUE (default), calculation uses n-1 in the denominator. If FALSE, uses n instead, as per standard statistical theory.

Value

Numeric. Returns the value of the calculated standard deviation.

Note

The sd function supplied as part of the base R xstats package assumes that the data are from a sample and offers no option to calculate the correct standard deviation for population data. The std.dev function offers this additional facility.

Author(s)

Paul Williamson

Examples

1
2
3
4
5
6
7
8
## Calculate standard deviation of a sample (default)
std.dev(survey$Height)

## For a sample, std.dev returns same result as stats:::sd function
std.dev(survey$Height) == sd(survey$Height)

## Calculation standard deviation of a population
std.dev(survey$Height, sample = FALSE)

DrPaulWilliamson/ENVS450 documentation built on May 9, 2019, 3:23 a.m.