#' Create a matrix of items
#'
#' @param n_items integer number of items to create (rows)
#' @param vec_length integer (even) number of features in each item, or vector length
#' @param all_unique logical default is FALSE, setting to TRUE ensures that all item entries are unique. Currently this is accomplished by brute force (iterating and checking until the entire matrix).
#'
#' @return matrix items across rows, and features across columns
#' @details This functions creates a matrix of items. Each item is a randomly permuted vector of 1s and -1s.
#' @export
#'
#' @examples
#'
#' mnrva_item_matrix(n_items = 5, vec_length = 10)
#' mnrva_item_matrix(n_items = 5, vec_length = 10, all_unique = TRUE)
#'
mnrva_item_matrix <- function(n_items = 5,
vec_length = 10,
all_unique = FALSE,
max_iteration = 5) {
# return matrix without checking for unique rows
if (all_unique == FALSE) {
temp_mat <- t(replicate(n_items, mnrva_single_rvector(vec_length)))
message(paste("rows are all unique: ",mnrva_check_unique(temp_mat)))
return(temp_mat)
}
# iterate until all rows are unique
if (all_unique == TRUE) {
max_iteration = 5
for(i in 1:max_iteration){
temp_mat <- t(replicate(n_items, mnrva_single_rvector(vec_length)))
if(mnrva_check_unique(temp_mat) == TRUE){
message(paste("rows are all unique: ",mnrva_check_unique(temp_mat)))
return(temp_mat)
}
if(i == max_iteration && mnrva_check_unique(temp_mat) == FALSE){
warning("Failed to find unique matrix")
}
}
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.