Takes in a square matrix of counts and outputs them in a form that is accessible to the brat and bratt family functions.

Brat(mat, ties = 0 * mat, string = c(">", "=="), whitespace = FALSE)

Arguments

mat

Matrix of counts, which is considered \(M\) by \(M\) in dimension when there are ties, and \(M+1\) by \(M+1\) when there are no ties. The rows are winners and the columns are losers, e.g., the 2-1 element is now many times Competitor 2 has beaten Competitor 1. The matrices are best labelled with the competitors' names.

ties

Matrix of counts. This should be the same dimension as mat. By default, there are no ties. The matrix must be symmetric, and the diagonal should contain NAs.

string

Character. The matrices are labelled with the first value of the descriptor, e.g., "NZ > Oz" `means' NZ beats Australia in rugby. Suggested alternatives include " beats " or " wins against ". The second value is used to handle ties.

whitespace

Logical. If TRUE then a white space is added before and after string; it generally enhances readability. See CommonVGAMffArguments for some similar-type information.

Details

In the VGAM package it is necessary for each matrix to be represented as a single row of data by brat and bratt. Hence the non-diagonal elements of the \(M+1\) by \(M+1\) matrix are concatenated into \(M(M+1)\) values (no ties), while if there are ties, the non-diagonal elements of the \(M\) by \(M\) matrix are concatenated into \(M(M-1)\) values.

Value

A matrix with 1 row and either \(M(M+1)\) or \(M(M-1)\) columns.

References

Agresti, A. (2013). Categorical Data Analysis, 3rd ed. Hoboken, NJ, USA: Wiley.

Author

T. W. Yee

Note

This is a data preprocessing function for brat and bratt.

Yet to do: merge InverseBrat into brat.

See also

brat, bratt, InverseBrat.

Examples

journal <- c("Biometrika", "Comm Statist", "JASA", "JRSS-B")
mat <- matrix(c( NA, 33, 320, 284,   730, NA, 813, 276,
                498, 68,  NA, 325,   221, 17, 142, NA), 4, 4)
dimnames(mat) <- list(winner = journal, loser = journal)
Brat(mat)  # Less readable
#>   Comm Statist>Biometrika JASA>Biometrika JRSS-B>Biometrika
#> 1                      33             320               284
#>   Biometrika>Comm Statist JASA>Comm Statist JRSS-B>Comm Statist Biometrika>JASA
#> 1                     730               813                 276             498
#>   Comm Statist>JASA JRSS-B>JASA Biometrika>JRSS-B Comm Statist>JRSS-B
#> 1                68         325               221                  17
#>   JASA>JRSS-B
#> 1         142
#> attr(,"ties")
#>   Comm Statist==Biometrika JASA==Biometrika JRSS-B==Biometrika
#> 1                        0                0                  0
#>   Biometrika==Comm Statist JASA==Comm Statist JRSS-B==Comm Statist
#> 1                        0                  0                    0
#>   Biometrika==JASA Comm Statist==JASA JRSS-B==JASA Biometrika==JRSS-B
#> 1                0                  0            0                  0
#>   Comm Statist==JRSS-B JASA==JRSS-B
#> 1                    0            0
#> attr(,"are.ties")
#> [1] FALSE
Brat(mat, whitespace = TRUE)  # More readable
#>   Comm Statist > Biometrika JASA > Biometrika JRSS-B > Biometrika
#> 1                        33               320                 284
#>   Biometrika > Comm Statist JASA > Comm Statist JRSS-B > Comm Statist
#> 1                       730                 813                   276
#>   Biometrika > JASA Comm Statist > JASA JRSS-B > JASA Biometrika > JRSS-B
#> 1               498                  68           325                 221
#>   Comm Statist > JRSS-B JASA > JRSS-B
#> 1                    17           142
#> attr(,"ties")
#>   Comm Statist == Biometrika JASA == Biometrika JRSS-B == Biometrika
#> 1                          0                  0                    0
#>   Biometrika == Comm Statist JASA == Comm Statist JRSS-B == Comm Statist
#> 1                          0                    0                      0
#>   Biometrika == JASA Comm Statist == JASA JRSS-B == JASA Biometrika == JRSS-B
#> 1                  0                    0              0                    0
#>   Comm Statist == JRSS-B JASA == JRSS-B
#> 1                      0              0
#> attr(,"are.ties")
#> [1] FALSE
vglm(Brat(mat, whitespace = TRUE) ~ 1, brat, trace = TRUE)
#> Iteration 1: loglikelihood = -20597.93
#> Iteration 2: loglikelihood = -20525.99
#> Iteration 3: loglikelihood = -20520.45
#> Iteration 4: loglikelihood = -20520.38
#> Iteration 5: loglikelihood = -20520.38
#> 
#> Call:
#> vglm(formula = Brat(mat, whitespace = TRUE) ~ 1, family = brat, 
#>     trace = TRUE)
#> 
#> 
#> Coefficients:
#> (Intercept):1 (Intercept):2 (Intercept):3 
#>    -0.2689541    -3.2180264    -0.7485238 
#> 
#> Degrees of Freedom: 3 Total; 0 Residual
#> Log-likelihood: -20520.38