4.4 Cross-tabulations
In addition to analyzing each variable individually, it is especially relevant to study whether there is an association between two categorical variables. This type of analysis makes it possible to identify patterns and relationships that provide valuable information for decision-making and for understanding social phenomena. For example, in the field of public policy, education and employment can be related to design labor-market strategies; in the evaluation of social programs, differences in access to health services can be analyzed by income level; and in social research, demographic variables and living conditions can be studied together to understand population dynamics and trends.
Formally, let \(x\) and \(y\) be two categorical variables with \(R\) row categories and \(C\) column categories, respectively. In the context of sample surveys, the interest usually focuses on estimating the joint distribution of both variables, that is, the proportion of population units that simultaneously belong to each possible combination of categories. To do this, the entries of a cross-tabulation, also known as a contingency table, are estimated using weighted frequencies obtained from the expansion factors and the sampling design. The estimate of the population total associated with each cell \((r,c)\) is defined as:
\[ \hat{N}_{rc} = \sum_{h} \sum_{i} \sum_{k} w_{hik} \ I(x_{hik}=r,\ y_{hik}=c), \]
where \(w_{hik}\) represents the expansion factor associated with element \(k\) of PSU \(i\) belonging to stratum \(h\), while \(I(x_{hik}=r,\ y_{hik}=c)\) corresponds to an indicator function that takes the value one when the observed unit simultaneously belongs to category \(r\) of variable \(x\) and category \(c\) of variable \(y\), and takes the value zero in any other case.
In addition to joint frequencies, it is also possible to estimate marginal sizes by rows and columns, defined respectively as \(\hat{N}_{r+} = \sum_{c=1}^{C} \hat{N}_{rc}\) and \(\hat{N}_{+c} = \sum_{r=1}^{R} \hat{N}_{rc}\). The grand total is expressed as \(\hat{N}_{++} = \sum_{r=1}^{R}\sum_{c=1}^{C} \hat{N}_{rc}\). The general structure of a contingency table with \(R\) rows and \(C\) columns can be represented as follows:
| Variable 2 | Variable 1 | \(\cdots\) | Row marginal | ||
|---|---|---|---|---|---|
| \(1\) | \(2\) | \(\cdots\) | \(C\) | ||
| \(1\) | \(\hat{N}_{11}\) | \(\hat{N}_{12}\) | \(\cdots\) | \(\hat{N}_{1C}\) | \(\hat{N}_{1+}\) |
| \(2\) | \(\hat{N}_{21}\) | \(\hat{N}_{22}\) | \(\cdots\) | \(\hat{N}_{2C}\) | \(\hat{N}_{2+}\) |
| \(\vdots\) | \(\vdots\) | \(\vdots\) | \(\ddots\) | \(\vdots\) | \(\vdots\) |
| \(R\) | \(\hat{N}_{R1}\) | \(\hat{N}_{R2}\) | \(\cdots\) | \(\hat{N}_{RC}\) | \(\hat{N}_{R+}\) |
| Column marginal | \(\hat{N}_{+1}\) | \(\hat{N}_{+2}\) | \(\cdots\) | \(\hat{N}_{+C}\) | \(\hat{N}_{++}\) |
Traditionally, contingency tables are usually represented as two-dimensional arrays of dimension \(R \times C\). However, they can also be extended to incorporate one or more additional variables, generating subsets or subtables that make it possible to study more complex relationships between categorical variables. Based on the estimated sizes, proportions can also be estimated for each cell of the contingency table as follows:
\[ \hat{p}_{rc}=\frac{\hat{N}_{rc}}{\hat{N}_{++}} \]
Next, continuing with the example database, the percentage distribution of men and women by poverty status is estimated, also incorporating their respective standard errors and confidence intervals. The results are presented in Table 4.16. This type of analysis makes it possible to describe the composition of the poor population by sex and evaluate the precision of the estimates obtained from the sampling design.
poverty_design <- survey_design %>%
mutate(poor = factor(
poor,
levels = 0:1,
labels = c("Not poor", "Poor")
))poverty_design %>%
group_by(poor, Sex) %>%
summarise(proportion = survey_prop(vartype = c("se", "ci")))| poor | Sex | proportion | proportion_se | proportion_low | proportion_upp |
|---|---|---|---|---|---|
| Not poor | Female | 0.529 | 0.012 | 0.505 | 0.554 |
| Not poor | Male | 0.471 | 0.012 | 0.446 | 0.495 |
| Poor | Female | 0.524 | 0.016 | 0.492 | 0.555 |
| Poor | Male | 0.476 | 0.016 | 0.445 | 0.508 |
The results indicate that 52.3% of the population living in poverty is female, while 47.6% is male. For women, the 95% confidence interval is between 49.2% and 55.5%, while the corresponding interval for men is between 44.5% and 50.7%. These estimates make it possible to observe the relative distribution of poverty by sex, while also considering the uncertainty inherent in the sampling process.
Using the same srvyr approach, the contingency table can also be estimated with group_by() and summarise(). The following example estimates the distribution of poverty status by sex, also obtaining measures of precision such as standard errors and confidence intervals. The corresponding code and results are presented in Table 4.17.
sex_by_poverty_proportion <- poverty_design %>%
group_by(poor, Sex) %>%
summarise(proportion = survey_prop(vartype = c("se", "ci")))| poor | Sex | proportion | proportion_se | proportion_low | proportion_upp |
|---|---|---|---|---|---|
| Not poor | Female | 0.529 | 0.012 | 0.505 | 0.554 |
| Not poor | Male | 0.471 | 0.012 | 0.446 | 0.495 |
| Poor | Female | 0.524 | 0.016 | 0.492 | 0.555 |
| Poor | Male | 0.476 | 0.016 | 0.445 | 0.508 |
In addition, confidence intervals can be obtained using the confint() function, which automatically calculates the lower and upper limits associated with the estimates produced. The procedure for estimating the confidence intervals is presented in Table 4.18. Note that the intervals coincide with those generated previously using the group_by function.
| poor | Sex | proportion_low | proportion_upp |
|---|---|---|---|
| Not poor | Female | 0.505 | 0.554 |
| Not poor | Male | 0.446 | 0.495 |
| Poor | Female | 0.492 | 0.555 |
| Poor | Male | 0.445 | 0.508 |
Another analysis of interest related to two-way tables in household surveys consists of estimating the percentage of unemployed people by sex. The corresponding procedure and results are presented in Table 4.19.
sex_by_employment_proportion <- survey_design %>%
filter(!is.na(Employment)) %>%
group_by(Employment, Sex) %>%
summarise(proportion = survey_prop(vartype = c("se", "ci")))| Employment | Sex | proportion | proportion_se | proportion_low | proportion_upp |
|---|---|---|---|---|---|
| Unemployed | Female | 0.273 | 0.054 | 0.180 | 0.390 |
| Unemployed | Male | 0.727 | 0.054 | 0.610 | 0.820 |
| Inactive | Female | 0.770 | 0.023 | 0.721 | 0.813 |
| Inactive | Male | 0.230 | 0.023 | 0.187 | 0.279 |
| Employed | Female | 0.405 | 0.019 | 0.369 | 0.442 |
| Employed | Male | 0.595 | 0.019 | 0.558 | 0.631 |
From the previous output, it can be observed that 27.2% of women and 72.7% of men are unemployed, with standard errors for these estimates of 5.3% for both women and men. The corresponding confidence intervals are calculated below and presented in Table 4.20:
| Employment | Sex | proportion_low | proportion_upp |
|---|---|---|---|
| Unemployed | Female | 0.180 | 0.390 |
| Unemployed | Male | 0.610 | 0.820 |
| Inactive | Female | 0.721 | 0.813 |
| Inactive | Male | 0.187 | 0.279 |
| Employed | Female | 0.369 | 0.442 |
| Employed | Male | 0.558 | 0.631 |
If the objective is now to estimate poverty by region, the numeric variable poor is used within an srvyr workflow, as shown in Table 4.21.
region_poverty_proportion <- survey_design %>%
group_by(Region, poor) %>%
summarise(proportion = survey_prop(vartype = c("se", "ci")))| Region | poor | proportion | proportion_se | proportion_low | proportion_upp |
|---|---|---|---|---|---|
| Norte | 0 | 0.641 | 0.055 | 0.526 | 0.742 |
| Norte | 1 | 0.359 | 0.055 | 0.258 | 0.474 |
| Sur | 0 | 0.656 | 0.043 | 0.566 | 0.737 |
| Sur | 1 | 0.344 | 0.043 | 0.263 | 0.434 |
| Centro | 0 | 0.635 | 0.079 | 0.470 | 0.773 |
| Centro | 1 | 0.365 | 0.079 | 0.227 | 0.530 |
| Occidente | 0 | 0.599 | 0.047 | 0.504 | 0.687 |
| Occidente | 1 | 0.401 | 0.047 | 0.313 | 0.496 |
| Oriente | 0 | 0.548 | 0.088 | 0.374 | 0.711 |
| Oriente | 1 | 0.452 | 0.088 | 0.289 | 0.626 |
From the above, it can be concluded that in the North region, 35% of people are living in poverty, while in the South the figure is 34%. The highest poverty level is found in the East region, with 45% of people living in poverty. The standard errors of the estimates.