This function takes a matrix where each line defines a linear function of the parameters to estimate a marginal mean (aka least squares mean) and return the matrix that define the contrasts among these means. All pairwise contrasts are returned (aka Tukey contrasts). The matrix with these contrasts can be passed to glht() to estimate them or used in explicit matricial calculus.

apc(lfm, lev = NULL)

Arguments

lfm

a \(k \times p\) matrix where each line defines a linear function to estimate a lsmean. In general, these matrices are obtained by using LE_matrix().

lev

a character vector with length equals to the numbers of lines of lfm matrix, (\(k\)). Default is NULL and the row names of codelfm is used. If row names is also NULL, incremental integer values are used to identify the comparisons.

Value

a \(K\times p\) matrix with the linear functions that define all pairwise contrasts. \(K\) is \({k}\choose{2}\).

See also

Examples

X <- diag(3) rownames(X)
#> NULL
apc(X)
#> [,1] [,2] [,3] #> 1-2 1 -1 0 #> 1-3 1 0 -1 #> 2-3 0 1 -1
rownames(X) <- letters[nrow(X):1] apc(X)
#> [,1] [,2] [,3] #> c-b 1 -1 0 #> c-a 1 0 -1 #> b-a 0 1 -1
apc(X, lev = LETTERS[1:nrow(X)])
#> [,1] [,2] [,3] #> A-B 1 -1 0 #> A-C 1 0 -1 #> B-C 0 1 -1
# Objects from doBy::LE_matrix() have an "grid" attribute. attr(X, "grid") <- data.frame(n = LETTERS[1:nrow(X)]) rownames(X) <- NULL apc(X)
#> [,1] [,2] [,3] #> A-B 1 -1 0 #> A-C 1 0 -1 #> B-C 0 1 -1