Weighted summaries
A frequency table is usually performed for a categorical variable, displaying
the frequencies of the respective categories. Note that general variables
containing text are not necessarily factors, despite having a small number of
characters.
A general table of frequencies, using the base function table()
, ignores
the defined missing values (which are all stored as NAs). The
reimplementation of this function in w_table()
takes care of this detail,
and presents frequencies for each separately defined missing values. Similar
reimplementations for the other functions have the same underlying objective.
It is also possible to perform a frequency table for numerical variables, if
the number of values is limited (an arbitrary and debatable upper limit of 15
is used). An example of such variable can be the number of children, where
each value can be interpreted as a class, containing a single value (for
instance 0 meaning the category of people with no children).
Objects of class declared
are not pure categorical variables (R factors)
but they are nevertheless interpreted as if they were factors, to allow
producing frequency tables. Given the high similarity with package
haven
, objects of class haven_labelled_spss
are automatically
coerced to objects of class declared
and treated accordingly.
The argument values
makes sense only when the input is of family class
declared
, otherwise for regular (base R) factors the values are
just a sequence of numbers.
The later introduced argument observed
is useful in situations when a
variable has a very large number of potential values, and a smaller subset of
actually observed ones. As an example, the variable “Occupation” has
hundreds of possible values in the ISCO08 codelist, and not all of them might
be actually observed. When activated, this argument restricts the printed
frequency table to the subset of observed values only.
The argument method
can be one of "unbiased"
or "ML"
.
When this is set to "unbiased"
, the result is an unbiased estimate
using Bessel's correction. When this is set to "ML"
, the result is the
maximum likelihood estimate for a Gaussian distribution.
The argument wt
refers only to frequency weights. Users should be
aware of the differences between frequency weights, analytic weights,
probability weights, design weights, post-stratification weights etc. For
purposes of inferential testing, Thomas Lumley's package survey
should be employed.
If no frequency weights are provided, the result is identical to the
corresponding base functions.
The function w_quantile()
extensively borrowed ideas from packages
stats
and Hmisc
, to ensure a constant interpolation that would
produce the same quantiles if no weights are provided or if all
weights are equal to 1.
Other arguments can be passed to the stats function quantile()
via the
three dots ...
argument, and their extensive explanation is found in the
corresponding stats function's help page.
For all functions, the argument na.rm
refers to the empty missing values
and its default is set to TRUE. The declared missing values are automatically
eliminated from the summary statistics, even if this argument is deactivated.
The function w_mode()
returns the weighted mode of a variable. Unlike the
other functions where the prefix w_
signals a weighted version of the
base function with the same name, this has nothing to do with the base
function mode()
which refers to the storage mode / type of an R object.