Analysis of the Weighted Kappa and Its Maximum with Markov Moves

In this paper, the notion of Markov move from algebraic statistics is used to analyze the weighted kappa indices in rater agreement problems. In particular, the problem of the maximum kappa and its dependence on the choice of the weighting schemes are discussed. The Markov moves are also used in a simulated annealing algorithm to actually find the configuration of maximum agreement.

A second issue this paper deals with is the dependence of the kappa-type statistics on the choice of the weights. The unweighted version of the Cohen's κ only distinguishes between agreement cells and disagreement cells, and thus, it is used in case of ratings on a nominal scale. When the rating scale is ordinal, or in general when there are some disagreements to be considered more serious than others, then the weighted κ w should be preferred. In this case, the choice of the weights is a delicate issue, and it is known that different weighting schemes lead to quite different results. In addition, the main weighting schemes (i.e., linear or quadratic) have been studied extensively, but there is a need of further analyses to better understand the role played by the weights in the behavior of kappa-type statistics. In a recent paper by Kvålseth Kvålseth (2018), the dependence of the weighted κ w on the choice of the weights is highlighted, and the relevance of the interpretation of the κ w values as functions of the weighting schemes is discussed extensively. The author motivates its study on the properties of the weights claiming that, without a clear understanding of the connections between the weights and the κ w , the weighted κ w itself is not a satisfactory index to describe the agreement in an ordinal context. Thus, also this problem will be considered here.
Both the points described above are analyzed in this paper with the aid of algebraic statistics. We give insights and new results to provide a precise understanding of the action of weights in the computation of the kappa, and this will help for a correct interpretation of weighted kappa statistics. This analysis is carried out here by means of the Markov moves, well-known tools in algebraic statistics for the analysis of contingency tables. In particular, we show how the properties of the weights affect the configuration of maximum agreement. Our results allow a precise understanding of the role of the weights and their impact on the structure of the configuration with maximum agreement. The use of algebraic statistics for rater agreement analysis has been considered in other works, but mainly for computational purposes. For instance, the use of Markov bases to make exact tests in this framework can be found in Rapallo (2003) and Rapallo (2005).
Without introducing here formal definitions, for which the reader can refer to the next section, let us present a simple example, taken from von Eye and Mun (2004), page 74. Two psychiatrists P 1 and P 2 rate the severity of depression of 129 patients using a three-level ordinal scale. The observed data are in Fig. 1 (left). A table with the same margins and maximum agreement with linear weights is in Fig. 1 (center), while the table with the same margins and maximum agreement with quadratic weights is in Fig. 1 (right). Already from this simple example, we can highlight some counterintuitive facts. For instance, not always the maximum agreement is obtained by maximizing the counts on the diagonal. With quadratic weights the maximum is not attained in a table which fulfills the main diagonal as much as possible. We will show that to fulfill the diagonal is a good strategy to increase the agreement only if the weights define a distance on the ground set, and this is not the case, for instance, when quadratic weights are used. On that point, the available resources to compute the maximum agreement fail. The R package rel, LoMartire (2020) and, for the two-rater setting, some online calculators, e.g., in Lowry (2020) at the date of submission, do not give the correct answer.
Another interesting point concerning the above example is that with linear weights there are several configurations with the same value of kappa. The tables in Fig. 1 (center and right) share the same value of weighted kappa with linear weights (0.6089), although they appear rather different at a first sight, and the weighted kappa with quadratic weights ranges from 0.6007 to 0.6909. We will see that in this simple example all tables with the maximum agreement under linear weights can be obtained in an easy way, as only one Markov move can be applied.
Finally, we exploit again the Markov moves, and we introduce a simple simulated annealing algorithm to find the maximum agreement. In particular, we assume the marginal distributions as fixed and we consider all multivariate tables with fixed one-way margins. The proposed algorithm can be applied with a general weighting scheme, not limited to linear or quadratic. Notice that the problem can be tackled also within the theory of integer linear programming (maximize the kappa statistics taking fixed the margins), but Markov moves provide a flexible tool and a solution easy to explain.
The paper is organized as follows. In Sect. 1 we recall the notation and the basic definitions about the Cohen's κ, the weighted Cohen's κ w , and the Conger's κ C and κ C,w for the multi-rater case. In Sect. 2, we compute the Markov bases for the rater agreement problem in the two-rater and in the multi-rater cases. Such Markov bases are used in Sect. 3 to state some results on the structure of the configuration of maximum agreement in connection with the (metric) properties of the weighting schemes. Section 4 is devoted to the illustration of a simulated annealing algorithm to actually find the configuration of maximum agreement, while in Sect. 5 the results of a simulation study are presented and discussed. Finally, Sect. 6 contains some concluding remarks and pointers to future directions.

Notation and Basic Recalls
In this section, we briefly review the basic definitions about the kappa-type indices of agreement which will be used in the paper. We first focus on the two-rater setting.
Let us consider the ratings of the two raters as a pair of random variables X and Y on the set {1, . . . , k}, or more generally on a finite ground set {x 1 , . . . , x k }. Let us denote with p i j the probability of the cell (i, j), and with p i+ (i = 1, . . . , k) and p + j ( j = 1, . . . , k) the marginal distributions of X and Y , respectively. The Cohen's κ is defined as: where D = {(i, j) : i = j} is the set of the disagreement cells. Given a matrix of weights of agreement W = (w i j ) with 0 ≤ w i j < 1 for all i, j with i = j, and w ii = 1 for all i, the weighted kappa is: where in the second expression u i j = 1 − w i j . Although not strictly necessary for the theory of rater agreement, we suppose that the matrices W and U = (u i j ) are symmetric, because some of our results are based on the properties of the metric functions, where symmetry is one the axioms.
In the previous formulas, the u i j are weights of disagreement, and it is easily seen that u i j = 0 on the main diagonal and 0 < u i j ≤ 1 for i = j. When a sample is available, the indices κ and κ w are estimated by replacing in Eqs.
(1) and (2) the theoretical probabilities with the corresponding sample proportions. On a sample of size N , we denote with n i j the count of the cell (i, j) and therefore sample proportion isp i j = n i j /N . Among the most commonly used weighting schemes there are: (a) the quadratic weights (see Fleiss and Cohen 1973): (b) the linear weights (see Cicchetti and Allison 1971): Moreover, the unweighted κ in Eq. (1) can be considered as a special case of the weighted κ w by setting Recent discussions on the choice, use, and interpretation of the different weighting schemes can be found in Warrens (2013) and Kvålseth (2018). On one side, the main reasons in favor of the quadratic and linear weights are essentially of theoretical nature. In fact, the quadratic weights lead to the interpretation of the weighted kappa as the intraclass correlation coefficient, see Schuster (2004). On the other side, the linear weights allow us to define the weighted kappa as a weighted average of kappas for the 2 × 2 tables obtained by collapsing adjacent categories, see Vanbelle and Albert (2009). However, undesirable behaviors of the weighted kappa for some data set can be observed under both choices of the weights, and thus the interpretation of the value of kappa is not easy in general. We will come back to this issue later in the paper, when we will use Markov moves to find the maximum agreement. Another interesting interpretation of the linear and quadratic weights is discussed in Li (2016), where matrix W is decomposed into a sum of suitable rank one matrices. In order to illustrate our theory, we also consider a square-root version of the weights, namely: As a preliminary remark, notice that the linear weights in Eq. (4) and the square-root weights in Eq. (6) define a distance in R, while the quadratic weights in Eq. (3) do not, because the triangular inequality is not satisfied. Usually, functions like the quadratic weights are called dissimilarities. In this paper, when the matrix U is a distance matrix, we name the weights as "distance weights," and in particular, we refer to the weights in Eq. (6) as to the sqrt weights. Moreover, we use the notation κ q , κ l , κ s when quadratic, linear, or sqrt weights are used, while we denote with κ w the kappa with a general weight.
Observe that the distance defined by the linear weights is the usual Euclidean distance in R, and it has a special behavior in terms of the triangular inequality. In fact, for i < j < h the triangular inequality becomes an equality: u ih = u i j + u jh . We will exploit this property later in the paper.
In the multi-rater setting, we consider the ratings of r raters as r random variables X 1 , . . . , X r on the same set {1, . . . , k}, or more generally on {x 1 , . . . , x k }. The observed data form a k r table. We denote with p i 1 ...i r the probability of the cell (i 1 , . . . , i r ), and with n i 1 ...i r the corresponding observed count on a sample of size N . Moreover, we denote with p (u) the one-dimensional marginal distribution of X u , and with p (uv) the two-dimensional marginal distribution of the pair To measure the agreement in the multi-rater setting, it is customary to use the Conger's κ C , originally introduced in Conger (1980) and the re-analyzed in several papers, see, e.g., Vanbelle (2019). The Conger's κ c is based on a pairwise rater agreement analysis. It is defined as: where p o is the mean proportion of agreement between all r (r − 1)/2 pairs of raters, and similarly p e is the mean proportion of expected agreement between all r (r − 1)/2 pairs of raters under independence. In formulas, and Since the Conger's κ C is based on the two-way margins of the k r table, it is easy to define a weighted version of the Conger's kappa as follows: with and In the above definition, the weights are the same for all pairs u, v of raters, but the definition can be easily extended to the case of different weights on different two-way margins. Also notice that the Conger's κ C can be defined in the general case of g-wise agreement, as in the original paper Conger (1980). This is done by taking the κ C unchanged in Eq. (7), and computing the observed agreement and the expected agreement in Eqs. (8) and (9) on the g-way marginal tables instead of the two-way tables. However, when the weighted version κ C,w in Eqs. (10)-(12) is considered, the pairwise agreement is the most reasonable choice, and the extension to the g-wise agreement would require new definitions of the weighting schemes.

Markov Bases
In this section, we introduce the main tools from algebraic statistics needed in our framework. In particular, we define the notion of Markov basis and we compute the relevant Markov bases for the rater agreement problems.
Let n be an observed contingency table, possibly multi-way. An integer-valued statistic is a function T : N k r −→ N s . Since we need to compute the maximum agreement with fixed marginal distributions we are particularly interested in the function in the two-way case and in the general multi-rater case, where n (s) i is the i-th entry of the marginal distribution of the s-th rater.
Definition 1. Given a statistic T , the fiber (or reference set) of a contingency table n is the set Definition 2. A Markov move for the statistic T is an integer-valued table m such that T (m) = 0.

Definition 3. A Markov basis for the fiber F T (n) of a table n is a set of Markov moves
In words, a Markov basis is a set of moves which makes the fiber F T (n) connected and all intermediate steps are nonnegative. In algebraic statistics, this is the main tool to define a Metropolis-like Markov chain Monte Carlo algorithm for doing exact inference for contingency tables. For a comprehensive introduction to Markov bases and their use in statistics, the reader can refer to the books Sullivant (2018) and Aoki et al. (2012).
Since we are particularly interested in the computation of the maximum agreement given the marginal distributions, we need the Markov bases for the statistic T in Eqs. (13) and (14).
Four basic moves for the two-rater problem. a Two nonzero elements on the diagonal; b one nonzero element on the diagonal, the move lies on the upper triangle; c one nonzero element on the diagonal, the move lies on both the upper and the lower triangle; d no nonzero elements on the diagonal.
Following Diaconis and Sturmfels (1998), in the general case the computation of a Markov basis needs symbolic computation and is actually not feasible for large-sized tables. However, the Markov bases for the fibers considered in this paper can be theoretically characterized and therefore no symbolic computation is involved. For an overview on the computation of Markov bases through symbolic software, the underlying computational problems, and the actual limitations for large tables, the reader can refer to Aoki et al. (2012).
As a first step, we recall a result from Diaconis and Sturmfels (1998) about the Markov basis for two-way tables with fixed margins.
Definition 4. Let i, i be two distinct row indices and j, j be two distinct column indices. A basic move is a move m such that Some examples of basic moves in the case of 4 categories are given in Fig. 2. Such moves have different behavior in terms of agreement. We will discuss all these types of moves in the next section.

Proposition 1. The set of basic moves in Definition 4 is a Markov basis for the fiber in Eq. (15)
for the two-rater problem.
The basic moves in the multi-rater setting are defined by extending the previous definition to more than two dimensions. Informally, one takes two +1's in two cells with at least two distinct coordinates and then arranges the −1's in order to have the correct projections in all two-way margins. More formally, we can state the following definition.
Definition 5. A basic move m for the multi-rater problem is a table with 4 nonzero entries: Two basic moves for the three-rater problem. A move of type (a) and a move of type (b) from Proposition 2.
• m is equal to +1 in (i 1 , . . . i r ) and in (i 1 , . . . , i r ) with at least two different indices. Without loss of generality, suppose that the distinct indices are i 1 , . . . , It is easy to see that this definition reduces to Definition 4 when r = 2. Two examples of basic moves in the 3 3 case are illustrated in Fig. 3.
The fact that basic moves are enough to connect the fiber in Eq. (15) can be derived from the theory of toric fiber products to be found in Sullivant (2007). This allows us to avoid symbolic computations and to make available the relevant Markov bases also for large-sized tables. Proof. First, note that all basic moves in Definition 5 are in the kernel of the marginalization map T .
Since for r = 2 the basic moves in Definition 5 coincide with the basic moves in 4, the result is true when r = 2. We proceed by induction on r . Let us suppose that the result holds for r − 1 raters, and we prove it for r raters. We apply Theorem 13 in Sullivant (2007). Given a Markov basis M r −1 for the problem with (r − 1) raters, a Markov basis M r for the problem with r raters is the union of the following sets of moves (a) split each move of M r −1 by putting one +1 and one −1 at a given level h of X r (h = 1, . . . , k) and the other +1 and −1 at a level h of X r (h = h, . . . , k); (b) for any two distinct cells (i 1 , . . . , i r −1 ) and (i 1 , . . . , i r −1 ) on the (r − 1)-dimensional table, and for any two distinct levels h, h of X r , take the move with +1 in (i 1 , . . . , i r −1 , h) and in (i 1 , . . . , i r −1 , h ) and with −1 in (i 1 , . . . , i r −1 , h ) and in (i 1 , . . . , i r −1 , h).
Since all the moves defined in items (a) and (b) above are basic moves, the result is proved.
As noticed in Introduction, Markov bases in algebraic statistics are usually defined in algebraic statistics in order to perform exact tests with a Metropolis-Hastings algorithm, and therefore to generate all contingency tables with the same value of the sufficient statistics as the observed table. Here, we simply use Markov bases to compute all the tables with fixed margins.

The Effect of the Markov Moves on the Kappa Indices
Now, we use the basic moves of the Markov bases in order to better understand the meaning of the weighted kappa. The basic idea is to apply the definition of Markov basis to analyze the rater agreement in connection with the weighting schemes. We show here that most of the basic moves have a precise behavior in terms of their effect on the kappa indices and therefore we analyze how the rater agreement changes when a Markov move is applied. Moreover, the configuration of maximum agreement can be reached with a finite number of Markov moves, starting from the observed table, and the analysis with basic moves helps us in understanding the structure of the configurations with maximum agreement.
Since our analysis is performed with fixed marginal distributions, the kappa indices are monotonic with the observed agreement. So, to ease the formulas, we consider the quantities in the two-rater setting, and in the multi-rater setting.
Let us start with some results in the two-rater setting. If n i j > 0 and n ji > 0, then Proof. From Eq. (16) and using the disagreement weights, we get Lemma 1 is valid for all weighting schemes and tells us that if there are positive counts in symmetric cells, then it is always possible to construct an observed table with higher observed agreement by applying a simple move. This is quite intuitive, since Eq. (18) roughly says that moving counts on the diagonal increases the observed agreement.
Nonetheless, apart from the symmetric basic moves as displayed in Fig. 2a, for the other types of basic moves there is not a common behavior in terms of observed agreement. Remember that, earlier in the paper, we have noticed that some weighting schemes defines a distance on the ground set {x 1 , . . . , x k } while other schemes do not. The following proposition states a partial result when only one cell of the diagonal is involved in the basic move.

Proposition 3. Let n be an observed agreement table, let i < j < h be three indices, and let m be the basic move with
. If n i j > 0 and n jh > 0 and a distance weighting scheme is used, then The same holds if i > j > h.
Proof. Let us consider the case i < j < h. (The other case has a similar proof.) From Eq. (16) and using the disagreement weights, we get by virtue of the triangular inequality.
In Proposition 3, the move m has one nonzero element on the diagonal. In the case i < j < h the move lies in the upper triangle of the table, while in the case i > j > h lies in the lower one.
Some remarks are now in order. First, note that in Proposition 3 the assumption of distance weights is essential. For weighting schemes derived or not derived from a distance we observe opposite behaviors of the weighted kappa. For instance, let us consider the observed table below: Comparing the value of κ w of n and n we note that: • With a distance weight we have κ w (n ) > κ w (n) by virtue of Proposition 3; • With quadratic weights we have κ q (n ) < κ q (n); • With linear weights we get κ l (n ) = κ l (n).
While with distance weights the maximum agreement is achieved by maximizing the counts in the diagonal cells, with quadratic weights a certain amount of moderate disagreement is preferred to a small amount of strong disagreement.
Moreover, from the above example, we observe there is a special behavior of the linear weights, because some Markov moves do not change the value of the weighted kappa. This affects also the problem of finding the configuration with maximum agreement, since in general such a configuration is not unique. We state below a result for linear weights, and we will discuss this issue in the next section from the point of view of computations.
Proposition 4. Let us consider four indices i 1 < i 2 ≤ j 1 < j 2 or j 1 < j 2 ≤ i 1 < i 2 , and take the basic move m with m i 1 j 1 = m i 2 j 2 = +1 and m i 1 j 2 = m i 2 j 1 = −1. If n is a table with n i 1 j 2 > 0 and n i 2 j 1 > 0. Using the linear weights we get κ l (n) = κ l (n + m) .
Proof. As in the previous proposition, let us consider only the case i 1 < i 2 ≤ j 1 < j 2 .
Notice that the conditions n i 1 j 2 > 0 and n i 2 j 1 > 0 are needed in order to have a nonnegative table n = n + m. Since n and n have the same margins, it is enough to compare the observed agreement. From Eq. (17), we get: The condition i 1 < i 2 ≤ j 1 < j 2 means that we apply a move on one side of the table w.r.t. the diagonal, and one nonzero element of the move is on the diagonal when i 2 = j 1 . Under such a condition, the move does not affect the value of the weighted kappa.
In view of Proposition 4, the uniqueness of the table with a given value of κ w is not guaranteed under any of weighting schemes, but this issue is especially relevant for the linear weights. To illustrate this, let us consider the table (with synthetic data) in Fig. 4a. By direct enumeration of the 644, 850 tables of the fiber, one finds 1527 tables with the same margins and with the same value of the weighted kappa with linear weights as the observed table, i.e., κ l = 0.5023. Among those tables, the weighted kappa with quadratic weights ranges from κ q = 0.3774 to κ q = 0.7406. The minimum is achieved in 3 tables, one of which is in Fig. 4b, while the maximum is achieved in 3 tables, one of which is in Fig. 4c.
Let us now turn to the multi-rater setting. From Eqs. (10), (8), (9) it is easy to argue that the effect of a basic move on the value of the Conger's κ C is yielded by the two-way margins of the move. Each two-way projection applies to a two-way margin and gives its own contribution in the sum in Eq. (8).
The following proposition collects the properties of the two-way margins of a basic move, and its proof is immediate.
Proposition 5. Let m be a basic move in the multi-rater case with r raters. Suppose that m is equal to +1 in (i 1 , . . . , i r ) and in (i 1 , . . . , i r ) and is equal to −1 in ( j 1 , . . . , j r ) and in ( j 1 , . . . , j r ). The projection of m on the pair (U, V ) is: • a basic move for the two-way problem, if the four pairs (i u are all distinct; • a null move, otherwise.
Note that, following the definition of basic move in Definition 5, it is easy to see that a multi-rater basic move m always yields at least one basic move on some two-dimensional margin.
For example, both the moves for the three-rater problem displayed in Fig. 3 produce a basic move on two two-way margins and a null move on one margin.
In general, the analysis of the effect of the basic moves on the Conger's κ C is more difficult than in the two-rater case. Nevertheless, we can state the following lemma, which generalizes Lemma 1.  If n + m is nonnegative, then Proof. It is enough to observe that all two-way margins of m are either a null move or a basic move satisfying the hypothesis of Lemma 1.
Also the multi-rater case the issue of non-uniqueness is especially relevant under linear weights. For instance, let us consider the three way table in Fig. 5. Although the table is rather sparse (the sample size is 16 in a contingency table with 27 cells), there are 2, 324 tables with the same value of κ C,l = 0.4872. Under quadratic weights, such tables yield values of κ C,q ranging from 0.3364 to 0.6313.

Simulated Annealing for Maximum Agreement
In this section, we show how to use a simulated annealing algorithm to determine the maximum value of the weighted kappa with fixed marginal distributions and to find a table where the maximum is actually reached. The Markov bases introduced in Sect. 2 are used in the algorithm to define the neighbors of the contingency tables and to navigate the fiber of an observed table.
While the computation of the maximum agreement is simple for the unweighted κ in the two-rater setting, the problem is not trivial when the weighted κ w is considered, or we use the Conger's κ C or κ C w for the multi-rater problem.
The Markov chain simulated annealing algorithm starts from the observed table and runs at each step b (b = 1, . . . , B) as follows. First, we choose a move m in the relevant Markov basis M and we define n = n + m; if n is a nonnegative table, then we move the chain from n to n with a transition probability depending on two factors. On the one hand, the transition probability is equal to 1 if the move causes an increase in the observed agreement, while it is less than one if the move causes a decrease in the observed agreement, and this probability is lower the more the decrease is high. On the other hand, the transition probability decreases with the time.
In practice, in the first part of the walk the Markov chain performs exploration, while in the second part it performs exploitation, because the probability of an actual move toward a table with smaller observer agreement decreases with the time. With our notation, the formula for the transition probability is:  where A o,w is the observed agreement in the table n, and τ b is the temperature at time b.
As a special feature of this algorithm, we have added a final step to apply all possible moves with two +1 on the main diagonal, thus exploiting the results in Lemmas 1 and 2. The pseudo-code of the algorithm is in Fig. 6.
The reader can refer to Suman and Kumar (2006) for a general introduction to simulated annealing in the discrete case and for a discussion on the computational details of the algorithm, as, for instance, the choice of the temperature function τ b . In particular, from our experiments, the choice of the function for the temperature decrease does not affect the performance of the algorithm, and thus, we have used a temperature of the form τ = τ 0 · d b .
Notice that the non-uniqueness of the configuration is still an issue also when finding the maximum, especially using the linear weights. As an example in the two-rater framework, consider again the observed table in Fig. 4a. With linear weights, there are 5 tables which reach the maximum value of κ l = 0.7511, and among these tables the κ q ranges from 0.7665 to 0.8703, the latter being also the maximum with quadratic weights. The maximum with the sqrt weights is κ s = 0.7528. The three configurations obtained with our algorithm are displayed in Fig. 7. In accordance with the findings in the previous sections, we note that quadratic weights avoid strong disagreement cells, while sqrt weights fill the diagonal as much as possible. Again, the table with maximum linear weight is not unique, and in fact, the three tables in Fig. 7 share the same of κ l .
The algorithm converges very fast, at least for small-and medium-sized tables, yielding the maximum value of the weighted kappa and a table where such a maximum is reached in less than 1 second on a standard PC. For large tables, the convergence takes long times, and the problem becomes fast unfeasible when the number of cells is large. In fact, on the one side large tables are usually sparse, on the other side, the relevant Markov basis is large, and at each step, the probability of an applicable move is very low. As a consequence, for large tables the number of Markov chain steps B must be quite large to ensure convergence. Some experiments are shown through a simulation study in the next section. In our experiments, we have found a fast convergence: for instance, on a standard PC the algorithm for the two-rater problem runs in less than 1 s for tables up to k = 10 rating categories (100 cells), and in less than 10 s for tables up to k = 18 rating categories (324 cells). Note that one can replace the fixed run length B with a stopping rule, and this is the strategy implemented in our simulation study. For instance, in small problems one can stop the algorithm when the algorithm does produce actual moves for 1000 consecutive steps. For large tables, the stopping rule must take into account also the cardinality of the Markov basis. More details on this point are discussed in the next section.
In general, the use of algebraic statistics in the case of large tables is problematic, and the curse of dimensionality is a known issue of this discipline. The definition of new techniques to speed up the convergence of Markov chain-based algorithms within algebraic statistics is still a current research topic, see, for instance, Windisch (2016), and only ad hoc solutions for special problems are currently available.

Simulation Study
In order to show the practical applicability of the algorithm introduced in the previous section, and to study its convergence properties, we have designed and performed a simulation study with several scenarios. For the two-rater case, we have considered three values of the number of levels k (k = 3, 5, 7) and two sample sizes (N = 20, 100). Moreover, two types of marginal distributions are considered: a first case with homogeneous uniform margins and a second case with non-homogeneous margins. In the first case, the tables are generated from a multinomial distribution with probabilities given by μ ⊗ μ, with μ = (1/k, . . . , 1/k), while in the second case the probability parameter of the multinomial distribution is μ ⊗ ν with μ = ν. In the nonhomogeneous case, the parameters μ and ν are chosen to account for the tendency of a rater to choose rating levels higher or lower than those of the other rater. For instance, in the 3 × 3 case, we have used μ = (2/5, 2/5, 1/5) and ν = (1/5, 2/5, 2/5). Notice that, with this procedure, we obtain different observed marginal distributions also when the parameter of the multinomial distribution is of the form μ ⊗ μ, and thus, the problem of finding the maximum weighted kappa is not trivial even in these scenarios. Also a simulation study for the three-rater case is presented, but limited to two numbers of categories k = 3, 5.
The convergence of the algorithm is measured as follows. The algorithm stops when there is a sufficiently large number c of consecutive steps with no change in the observed agreement (and therefore without changes in the weighted kappa). The number c must take into account the number of moves in the Markov basis. We have defined here c = max{10 · #M; 1, 000}. This choice of c is a reasonable trade-off between accuracy and speed. For each scenario, a sample of 1, 000 tables is generated and the distribution of the stopping time ST is approximated through the 1, 000 observed values. The simulation study has been performed using three weighting schemes: quadratic, linear, and sqrt.
The results are displayed in Table 1 for the two-rater scenarios and in Table 2 for the thererater scenarios. The mean, the standard deviation, and the 99th percentile of the convergence time ST are reported. In such tables, only the results for tables with homogeneous margins are considered. Since the results for tables with non-homogeneous margins are very similar, they are reported as Tables 3 and 4 in "Appendix." From the results, we see that the time to convergence increases with the sample size and with the dimension of the table, and this is particularly relevant in the three-rater case. As discussed in the previous sections, when the number of raters increases, the number of basic moves in the Markov basis grows, and the probability of selecting a non-applicable move becomes high, especially in the case of sparse tables. To overcome this problem, the definition of the stopping time c requires a large number of steps when the Markov basis is large and consequently the execution Time to convergence (mean, standard deviation and 99th percentile) of the simulated annealing algorithm for different numbers of levels k and sample sizes N .
time increases. For large sparse tables, the algorithm needs special attention in the choice of the numerical parameters and in the optimization of the selection of the moves. A thorough study in this direction is beyond the scopes of the present paper. That is why we do not present the case of 7 × 7 × 7 tables. Finally, with regard to the choice of the weights, we observe that the algorithm is a bit faster with the linear weights.

Concluding Remarks
The analysis of the kappa-type indices through basic Markov moves presented in this paper allows us to better understand the effect of the choice of the weights and, in particular, shows that the configuration with maximum kappa strongly depends on the weights, making the normalization of the kappa statistics a non-trivial task. We have shown that, when the weights satisfy the triangular inequality, the table with maximum kappa looks quite different from that obtained with quadratic weights, and therefore, the use of distance weights should be considered as an option when choosing the weights. Since the basic moves make connected the fiber of all tables with the same margins, we have implemented a simulated annealing algorithm to actually find the configuration with maximum kappa with fixed margins in a general framework.
Future works will include the analysis of the maximum agreement when not all raters classify the same set of objects, and the speed up of the simulated annealing algorithm, especially for large sparse tables. The convergence of Markov chain-based algorithms with Markov bases for large sparse tables is a general problem in algebraic statistics, and thus, any advance in this direction would represent a notable progress also in other fields of application. Finally, we have shown that the set of all tables with a given value of weighted kappa with linear weights can be a rather large set, and it can be explored through suitable Markov bases.
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/. Time to convergence (mean, standard deviation and 99th percentile) of the simulated annealing algorithm for different numbers of levels k and sample sizes N .