This tutorial shows the basic use of the package and includes the main functions to create the necessary inputs to implement both quality standards.
We will use two datasets:
Both datasets are loaded into the package and they can be used when the package is loaded in the session 1. The data edition in the case of ENE has the purpuse of creating some subpopulations (work force, unemployed and unemployed).
library(survey) library(calidad) library(dplyr) ene <- ene %>% mutate(fdt = if_else(cae_especifico >= 1 & cae_especifico <= 9, 1, 0), # labour force ocupado = if_else(cae_especifico >= 1 & cae_especifico <= 7, 1, 0), # employed desocupado = if_else(cae_especifico >= 8 & cae_especifico <= 9, 1, 0)) # unemployed # One row per household epf <- epf_personas %>% group_by(folio) %>% slice(1) %>% ungroup()
Before starting to use the package, it is necessary to declare the
sample design of the survey, for which we use the
package. The primary sample unit, the stratum and weights must be
declared. It is also possible to use a design with only weights,
nevertheless in that case the variance will be estimated under simple
random sampling assumption. In this case we will declare a complex
design for the two surveys (EPF and ENE). Additionally, it may be useful
to declare an option for strata that only have one PSU.
To assess the quality of an estimate, the INE methodology establishes differentiated criteria for estimates of proportion (or ratio), on the one hand, and estimates of mean, size and total, on the other. In the case of proportion estimation, it is necessary to have the sample size, the degrees of freedom and the standard error. The other estimates require the sample size, the degrees of freedom, and the coefficient of variation.
The package includes separate functions to create the inputs for estimates of mean, proportion, totals and size. The following example shows how the proportion and size functions are used.
var: variable to be estimated. Must be a dummy variable
domains: required domains.
subpop: reference subpopulation. It is optional and works as a filter (must be a dummy variable)
design: sample design
The function returns all the neccesary inputs to implement the standard
To get more domains, we can use the “+” symbol as follows:
A useful parameter is
eclac_input. It allows to return
the ECLAC inputs. By default this parameter is FALSE and with the option
TRUE we can activate it.
In some cases it may be of interest to assess the quality of a sum.
For example, the sum of all the income of the EPF at the geographical
area level (Gran Santiago and other regional capitals). For this, there
create_total function. This function receives a
continuous variable such as hours, expense, or income and generates
totals at the requested level. The ending “with” of the function alludes
to the fact that a continuous variable is being used.
If we want to assess the estimate of a mean, we have the function
create_mean. In this case, we will calculate the average
expenditure of households, according to geographical area.
The default usage is not to disaggregate, in which case the functions should be used as follows:
# ENE dataset insumos_prop_nacional <- create_prop("desocupado", subpop = "fdt", design = dc_ene) insumos_total_nacional <- create_total("desocupado", subpop = "fdt", design = dc_ene) # EPF dataset insumos_suma_nacional <- create_total("gastot_hd", design = dc_epf) insumos_media_nacional <- create_mean("gastot_hd", design = dc_epf)
Once the inputs have been generated, we can do the evaluation. To do
this, we use the
The output is a
dataframe that, in addition to
containing the information already generated, includes a column that
indicates whether the estimate is unreliable, less reliable or
assess has a parameter that allows us to
know if the table should be published or not. Following the criteria of
the standard, if more than 50% of the estimates of a table are not
reliable, it should not be published.
The data contained within the package has some editions. It is important to note that haven::labelled objects may have some collision with quality functions. If you want to import a dta file, all variables that are of type haven::labelled must be converted to numeric or character.↩︎