#' Summarize invariance matrices by group
#'
#' \code{StatByGroup} applies a descriptive statistic over the rows of each
#' invariance matrix in a list and returns this as a list of named vectors.
#'
#' This function can be used to indicate how invariant each group was with the
#' other groups, in general (e.g., by setting \code{stat.function = median}.
#'
#' @param matrix.list A list of invariance matrices from
#' \code{\link{InvarianceMatrices}}
#' @param stat.function The function to apply over rows
#' @return Thus function returns a list of named vectors. Each vector contains 1
#' element for each group.
#'
#' @export
StatByGroup <- function(matrix.list, stat.function) {
# creating list to fill in and output
out.list <- list()
# for each invariance matrix, apply the stat.function to each row/column
for(matrix.number in 1:length(matrix.list)){
# subset matrix.list to a matrix
temp.matrix <- matrix.list[[matrix.number]]
# apply the stat.function over rows
out.list[[matrix.number]] <-
sort(apply(temp.matrix, 1, stat.function, na.rm = T))
# create names for output list
names(out.list)[matrix.number] <- names(matrix.list)[matrix.number]
}
return(out.list)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.