The NM-method or Naszodi–Mendonca method is the operation that can be applied in statistics, econometrics, economics, sociology, and demography to construct counterfactual contingency tables. The method finds the matrix () which is "closest" to matrix ( called the seed table) in the sense of being ranked the same but with the row and column totals of a target matrix . While the row totals and column totals of are known, matrix itself may not be known.

Since the solution for matrix is unique, the NM-method is a function: , where is a row vector of ones of size , while is a column vector of ones of size .

The NM-method was developed by Naszodi and Mendonca (2023) (and first applied by Naszodi and Mendonca (2019) to solve for matrix in problems, where matrix is not a sample from the population characterized by the row totals and column totals of matrix , but represents another population.

Their application aimed at quantifying intergenerational changes in the strength of educational homophily and thus measuring the historical change in social inequality between different educational groups in the US between 1980 and 2010. The trend in inequality was found to be U-shaped, supporting the view that with appropriate social and economic policies inequality can be reduced.

Definition of matrix ranking The closeness between two matrices of the same size can be defined in several ways. The Euclidean distance, and the Kullback–Leibler divergence are two well-known examples.

The NM-method is consistent with a definition relying on the ordinal Liu–Lu index which is the slightly modified version of the Coleman-index defined by Eq. (15) in James Coleman (1958). According to this definition, matrix is "closest" to matrix , if their Liu–Lu values are the same. In other words, if they are ranked the same by the ordinal Liu–Lu index.

If is a 2×2 matrix, its scalar-valued Liu–Lu index is defined as

, where

.

Following James Coleman (1958), this index is interpreted as the “actual minus expected over maximum minus minimum”, where is the actual value of the entry of the seed matrix ; is its expected (integer) value under the counterfactual assumptions that the corresponding row total and column total of are predetermined, while its interior is random. Also, is its minimum value if the association between the row variable and the column variable of is non-negative. Finally, is the maximum value of () for given row total and column total .

For matrix of size n×m (, ), the Liu–Lu index was generalized by Naszodi and Mendonca (2023) to a matrix-valued index. One of the preconditions for the generalization is that the row variable and the column variable of matrix have to be ordered. Equating the generalized, matrix-valued Liu–Lu index of with that of matrix is equivalent to dichotomizing their ordered row variable and ordered column variable in ways by explointing the ordered nature of the row and column variables. Than, equating the original, scalar-valued Liu–Lu indices of the 2×2 matrices obtained with the dichotomizations. I.e., for any pair of (, and ) the restriction is imposed, where is the matrix with its being of size , and its being of size . Similarly, is the matrix given by the transpose of with its being of size , and its being of size .

Constraints on the row totals and column totals Matrix should satisfy not only but also the pair of constraints on its row totals and column totals: and .

Solution Assuming that for all pairs of (where , and ), the solution for is unique, deterministic, and given by a closed-form formula.

For matrices and of size , the solution is

.

The other 3 cells of are uniquely determined by the row totals and column totals. So, this is how the NM-method works for 2×2 seed tables.

For , and matrices of size (, ), the solution is obtained by dichotomizing their ordered row variable and ordered column variable in all possible meaningful ways before solving number of problems of 2×2 form. Each problem is defined for an pair ( and ) with , and the target row totals and column totals: , and , respectively. Each problem is to be solved separately by the formula for . The set of solutions determine number of entries of matrix . Its remaining elements are uniquely determined by the target row totals and column totals.

Next, let us see how the NM-method works if matrix is such that the second precondition of is not met for .

If for all pairs of , the solution for is also unique, deterministic, and given by a closed-form formula. However, the corresponding concept of matrix ranking is slightly different from the one discussed above. Liu and Lu (2006) define it as , where ; is the smallest integer being larger than or equal to .

Finally, neither the NM-method, nor is defined if pair such that , while for another pair of .

A numerical example Consider the following complemented with its row totals and column totals and the targets, i.e., the and : Z1234TOTALTARGET1240223531854140TOTAL210230185175800TARGET1,000

As a first step of the NM-method, is multiplied by the , and matrices for each pair of (, and ). It yields the following 9 matrices of size 2×2 with their target row totals and column totals:

++ 1 2 TOTAL TARGET1120120240400290470560600TOTAL210590800TARGET4006001,000+ 1 2 TOTAL TARGET 1 190 50 240 400 2 250 30 560 600 TOTAL 440 360 800 TARGET 700 300 1,000 1 2 TOTAL TARGET 1 220 20 240 400 2 405 155 560 600 TOTAL 625 175 800 TARGET 900 100 1,000 1 2 TOTAL TARGET 1 170 305 475 700 2 40 285 325 300 TOTAL 210 590 800 TARGET 400 600 1,000 1 2 TOTAL TARGET 1 340 135 475 700 2 100 225 325 300 TOTAL 440 360 800 TARGET 700 300 1,00012TOTALTARGET1420554757002205120325300TOTAL625175800TARGET9001001,00012TOTALTARGET1200460660850210130140150TOTAL210590800TARGET4006001,000 1 2 TOTAL TARGET 1 410 250 660 850 2 30 110 140 150 TOTAL 440 360 800 TARGET 700 300 1,000 1 2 TOTAL TARGET 1 565 95 660 850 2 60 80 140 150 TOTAL 625 175 800 TARGET 900 100 1,000

The next step is to calculate the generalized matrix-valued Liu–Lu index , (where ) by applying the formula of the original scalar-valued Liu–Lu index to each of the 9 matrices: 0.39 0.54 0.62 0.53 0.44 0.47 0.73 0.61 0.45

Apparently, matrix is positive. Therefore, the NM-method is defined. Solving each of the 9 problems of the 2×2 form yields 9 entries of the matrix. Its other 7 entries are uniquely determined by the target row totals and column totals. The solution for is: 1234TOTAL1253.191.440.515.1400291.1147.139.821.9300339.636.864.29.3150416.224.755.553.6150TOTAL4003002001001,000

Another numerical example taken from Abbott et al.(2019) Consider the following complemented with its row totals and column totals and the targets, i.e., the and : Z123TOTALTARGET11,36025,84032,800TOTAL1,3905,6702,94010,000TARGET10,000

As a first step of the NM-method, is multiplied by the , and matrices for each pair of (, and ). It yields the following 4 matrices of size 2×2 with their target row totals and column totals:

++ 1 2 TOTAL TARGET11,0702901,3601,60023208,3208,6408,400TOTAL1,3908,61010,000TARGET1,3908,61010,000+ 1 2 TOTAL TARGET 1 1,340 20 1,360 1,600 2 5,720 2,920 8,640 8,400 TOTAL 7,060 2,940 10,000 TARGET 7,060 2,940 10,000 1 2 TOTAL TARGET 1 1,370 5,830 7,200 7,500 2 20 2,780 2,800 2,500 TOTAL 1,390 8,610 10,000 TARGET 1,390 8,610 10,000 1 2 TOTAL TARGET 1 6,620 580 7,200 7,500 2 440 2,360 2,800 2,500 TOTAL 7,060 2,940 10,000 TARGET 7,060 2,940 10,000

The next step is to calculate the generalized matrix-valued Liu–Lu index , (where ) by applying the formula of the original scalar-valued Liu–Lu index to each of the 4 matrices: 0.75 0.95 0.95 0.78

Apparently, matrix is positive. Therefore, the NM-method is defined. Solving each of the 4 problems of the 2×2 form yields 4 entries of the matrix. Its other 5 entries are uniquely determined by the target row totals and column totals. The solution for is: 123TOTAL11,101476241,60022714,8198095,9003183752,1072,500TOTAL1,3905,6702,94010,000

Implementation The NM-method is implemented in Excel, Visual Basic, R, and also in Stata.

Applications The NM-method can be applied to study various phenomena including assortative mating, intergenerational mobility as a type of social mobility, residential segregation, recruitment and talent management.

In all of these applications, matrices , , and represent joint distributions of one-to-one matched entities (e.g. husbands and wives, or first born children and mothers, or dwellings and main tenants, or CEOs and companies, or chess instructors and their most talended students) characterized either by a dichotomous categorical variable (e.g. taking values vegetarian/non-vegetarian, Grandmaster/or not), or an ordered multinomial categorical variable (e.g. level of final educational attainment, skiers' ability level, income bracket, category of rental fee, credit rating, FIDE titles). Although the NM-method has a wide range of applicability, all the examples to be presented next are about assortative mating along the education level. In these applications, the two preconditions (of ordered trait variable, and positive assortative mating in all educational groups) are not debated to be met.

Assume that matrix characterizes the joint educational distribution of husbands and wives in Zimbabwe, while matrix characterizes the same in Yemen. Matrix to be constructed with the NM-method tells us what would be the joint educational distribution of couples in Zimbabwe, if the educational distributions of husbands and wives were the same as in Yemen, while the overall desire for homogamy (also called as aggregate marital preferences in economics, or marital matching social norms/social barriers in sociology) were unchanged.

In a second application, matrices and characterize the same country in two different years. Matrix is the joint educational distribution of American newlyweds in 2040, where the husbands are from Generation Z and being young adults when observed. Matrix is the same but for Generation Y observed in year 2024. By constructing matrix , one can study in the future what would be the educational distribution among the just married American young couples if they sorted into marriages the same way as the males in Generation Z and their partners do, while the education level were the same as among the males in Generation Y and their partners.

In a third application, matrices and characterize again the same country in two different years. In this application, matrix is the joint educational distribution of Portuguese young couples (where the male partners' age is between 30 and 34 years) in 2011. And is the same but it is observed in year 1981. One may aim to construct matrix in order to study what would have been the educational distribution of Portuguese young couples if they had sorted into marriages like their peers did in 2011, while their gender-specific educational distributions were the same as in 1981.

In each of the first two applications, matrix represents a counterfactual joint distribution. It can be used to quantify certain ceteris paribus effects. More precisely, to quantify on a cardinal scale the difference between the directly unobservable degree of marital sorting in Zimbabwe and Yemen, or in Generation Z and Generation Y with a counterfactual decomposition. For the decomposition, the counterfactual table is used to calculate the contribution of each of the driving forces (i.e., the observed structural availability of potential partners with various education levels determining the opportunities at the population level; and the unobservable non-structural drivers, e.g., aggregate matching preferences, desires, norms, barriers) and that of their interaction (i.e., the effect of changes in aggregate preferences/desires/norms/barriers due to changes in structural availability) to an observable cardinal scaled statistics (e.g. the share of educationally homogamous couples).