Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
legTools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
leg
legTools
Commits
913472a3
Commit
913472a3
authored
9 years ago
by
Walmes Zeviani
Browse files
Options
Downloads
Patches
Plain Diff
Add 'apcMatrix', all pairwise comparisons matrices.
parent
ba496654
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
R/apcMatrix.R
+75
-0
75 additions, 0 deletions
R/apcMatrix.R
with
75 additions
and
0 deletions
R/apcMatrix.R
0 → 100644
+
75
−
0
View file @
913472a3
#' @title All pairwise comparisons matrix (Tukey contrasts)
#'
#' @name apcMatrix
#'
#' @description This function takes a matrix where each line defines a
#' linear function of the parameters to estimate a marginal mean
#' (aka least squares means) 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 \code{multcomp::glht()} to estimate them or used in
#' explicit matricial calculus.
#'
#' @param lfm a \eqn{k\times p} matrix where each line defines a linear
#' function to estimate a lsmean (or any linear function). In
#' general, these matrices are obtained using
#' \code{doBy::LSmatrix()}.
#'
#' @param lev a character vector with dimension equals to the numbers of
#' lines of \code{lfm} matrix (\eqn{k}). Default is \code{NULL} and
#' the row names of code{lfm} is used. If row names is also
#' \code{NULL}, an integer sequence is used to identify the
#' comparisons.
#'
#' @return a \eqn{K\times p} matrix with the linear functions that
#' define all pairwise contrasts. \eqn{K} is \eqn{\binom{k}{2}}.
#'
#' @seealso \link[doBy]{LSmatrix}.
#'
#' @author Walmes Zeviani, \email{walmes@@ufpr.br}
#'
#' @export
#'
#' @examples
#'
#' ## A matrix of linear functions corresponding to the cell means
#' ## parametrization.
#' X <- diag(4)
#'
#' ## If no rownames an integer sequence is used.
#' rownames(X)
#' apcMatrix(X)
#'
#' ## With rownames, those are used.
#' rownames(X) <- letters[nrow(X):1]
#' apcMatrix(X)
#'
#' ## Passing names by the argument `lev=`.
#' apcMatrix(X, lev=LETTERS[1:nrow(X)])
#'
#' ## Using the special case with attribute "grid" present in matrices
#' ## returned by doBy::LSmeans() and doBy::LSmatrix().
#' attr(X, "grid") <- data.frame(n=LETTERS[1:nrow(X)])
#' apcMatrix(X)
#'
apcMatrix
<-
function
(
lfm
,
lev
=
NULL
){
nlev
<-
nrow
(
lfm
)
rn
<-
rownames
(
lfm
)
a
<-
attr
(
lfm
,
"grid"
)
if
(
is.null
(
lev
)){
if
(
!
is.null
(
a
)){
lev
<-
apply
(
a
,
1
,
paste
,
collapse
=
":"
)
}
else
if
(
!
is.null
(
rn
)){
lev
<-
rn
}
else
{
lev
<-
as.character
(
1
:
nlev
)
}
}
cbn
<-
combn
(
seq_along
(
lev
),
2
)
M
<-
lfm
[
cbn
[
1
,],]
-
lfm
[
cbn
[
2
,],]
if
(
is.vector
(
M
)){
dim
(
M
)
<-
c
(
1
,
length
(
M
))
}
rownames
(
M
)
<-
paste
(
lev
[
cbn
[
1
,]],
lev
[
cbn
[
2
,]],
sep
=
"-"
)
return
(
M
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment