Generic functions for the variance and standard deviation, and methods for individual and grouped data.
The default methods for individual data are the functions from the stats package.
var(x, ...)# S3 method for default
var(x, y = NULL, na.rm = FALSE, use, ...)
# S3 method for grouped.data
var(x, ...)
sd(x, ...)
# S3 method for default
sd(x, na.rm = FALSE, ...)
# S3 method for grouped.data
sd(x, ...)
A named vector of variances or standard deviations.
a vector or matrix of individual data, or an object of class
"grouped data"
.
see stats::var
.
see stats::var
.
see stats::var
.
further arguments passed to or from other methods.
Vincent Goulet vincent.goulet@act.ulaval.ca. Variance and standard deviation methods for grouped data contributed by Walter Garcia-Fontes walter.garcia@upf.edu.
This page documents variance and standard deviation computations for
grouped data. For individual data, see var
and
sd
from the stats package.
For grouped data with group boundaries var
computes the sample variance
The sample variance for grouped data differs from the variance
computed from the empirical raw moments with emm
in two
aspects. First, it takes into account the degrees of freedom. Second,
it applies Sheppard's correction factor to compensate for the
overestimation of the true variation in the data. For groups of equal
width
Klugman, S. A., Panjer, H. H. and Willmot, G. E. (1998), Loss Models, From Data to Decisions, Wiley.
Heumann, C., Schomaker, M., Shalabh (2016), Introduction to Statistics and Data Analysis, Springer.
grouped.data
to create grouped data objects;
mean.grouped.data
for the mean and emm
for
higher moments.
data(gdental)
var(gdental)
sd(gdental)
## Illustration of Sheppard's correction factor
cj <- c(0, 2, 4, 6, 8)
nj <- c(1, 5, 3, 2)
gd <- grouped.data(Group = cj, Frequency = nj)
(sum(nj) - 1)/sum(nj) * var(gd)
(emm(gd, 2) - emm(gd)^2) - 4/12
Run the code above in your browser using DataLab