Learn R Programming

freqweights (version 0.0.1)

statsfreq: Descriptive statistics of a frequency table.

Description

Computes the descriptive statistics of a frequency table.

Usage

meanfreq(data, freq = ~freq)

quantilefreq(data, probs = c(0, 0.25, 0.5, 0.75, 1), freq = ~freq)

covfreq(data, freq = ~freq)

sdfreq(data, freq = ~freq)

corfreq(data, freq = ~freq)

Arguments

data
a data frame or matrix.
freq
a one-sided, single term formula specifying frequency weights. Default is ~freq.
probs
A vector of quantiles to compute. Default is 0 (min), .25, .5, .75, 1 (max).

Value

  • meanfreq and sdfreq return scalars. quantilefreq returns a vector with the same length as probs. covfreq and corfreq the estimated covariance matrix and correlation matrix, respectively.

Details

These functions compute various weighted versions of standard estimators.

meanfreq, sdfreq, quantilefreq, covfreq, corfreq estimate the mean, standard desviation, quantiles, covariances and correlation matrix, respectively. In this last two cases, resulst are equals to the pairwise.complete.obs option of cov and cor of the desaggregated data, respectively.

Missing values or cases with non-positive frequency weights are automatically removed.

Data set must contain the variables that compose the formula. These variables are removed from the data set in order to calculate the descriptive statistics.

The algorithm of quantilefreq are based on wtd.quantile.

References

Andrews, Chris, https://stat.ethz.ch/pipermail/r-help/2014-March/368350.html

See Also

tablefreq, wtd.quantile

Examples

Run this code
df <- tablefreq(iris[, c("Sepal.Length","Petal.Length")])
identical(meanfreq(df[,c(1,3)]), mean(iris[,1]))
identical(sdfreq(df[,c(1,3)]), sd(iris[,c("Sepal.Length")]))
all.equal(covfreq(df), cov(iris[,c("Sepal.Length","Petal.Length")],use="pairwise.complete.obs"))

Run the code above in your browser using DataLab