From 74d8d425ad7a8d086d15817180af3fe1d44f2f17 Mon Sep 17 00:00:00 2001 From: debruine Date: Fri, 3 May 2019 17:11:03 +0100 Subject: [PATCH] Make everything cleaner --- DESCRIPTION | 2 +- NAMESPACE | 1 + NEWS.md | 7 +- R/check_design.R | 118 +++++++++- R/check_sim_stats.R | 10 +- R/long2wide.R | 36 ++- R/make_id.R | 20 +- R/rnorm_multi.R | 10 +- R/select_num_grp.R | 24 +- R/sim_design.R | 20 +- R/sim_df.R | 10 +- R/sim_mixed_df.R | 24 +- README.Rmd | 23 ++ README.md | 24 +- docs/articles/rnorm_multi.html | 2 +- docs/articles/sim_design.html | 6 +- docs/articles/sim_df.html | 2 +- docs/index.html | 17 ++ docs/news/index.html | 9 + docs/reference/check_design.html | 85 ++++++- docs/reference/check_sim_stats.html | 38 ++-- docs/reference/get_design_long.html | 186 ++++++++++++++++ docs/reference/index.html | 6 + docs/reference/long2wide.html | 30 ++- docs/reference/make_id.html | 12 +- docs/reference/rnorm_multi.html | 309 +++++++++++++++++--------- docs/reference/select_num_grp.html | 36 +-- docs/reference/sim_design.html | 12 +- docs/reference/sim_design_.html | 12 +- docs/reference/sim_df.html | 12 +- docs/reference/sim_mixed_df.html | 214 +++++++++--------- docs/reference/wide2long.html | 278 ++++++++++++++++++++++- man/check_design.Rd | 2 +- man/check_sim_stats.Rd | 6 +- man/get_design_long.Rd | 24 ++ man/long2wide.Rd | 12 +- man/make_id.Rd | 7 +- man/rnorm_multi.Rd | 9 +- man/select_num_grp.Rd | 6 +- man/sim_design.Rd | 8 +- man/sim_design_.Rd | 8 +- man/sim_df.Rd | 8 +- man/sim_mixed_df.Rd | 8 +- man/wide2long.Rd | 16 +- tests/testthat/test-check_design.R | 37 ++- tests/testthat/test-check_sim_stats.R | 56 +++-- tests/testthat/test-long2wide.R | 51 +++++ tests/testthat/test-rnorm_multi.R | 4 +- tests/testthat/test-select_num_grp.R | 2 +- tests/testthat/test-sim_df.R | 32 ++- vignettes/sim_design.Rmd | 4 +- 51 files changed, 1450 insertions(+), 445 deletions(-) create mode 100644 docs/reference/get_design_long.html create mode 100644 man/get_design_long.Rd create mode 100644 tests/testthat/test-long2wide.R diff --git a/DESCRIPTION b/DESCRIPTION index c78eb7c4..86fa2b15 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,7 +19,7 @@ Imports: ggplot2 License: MIT + file LICENSE Suggests: - testthat, + testthat (>= 2.1.0), knitr, rmarkdown VignetteBuilder: knitr diff --git a/NAMESPACE b/NAMESPACE index f7dce87b..2bada45d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,7 @@ export(check_design) export(check_sim_stats) export(cormat) export(cormat_from_triangle) +export(get_design_long) export(is_pos_def) export(long2wide) export(make_id) diff --git a/NEWS.md b/NEWS.md index fafedd47..940dca9c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,4 +5,9 @@ # faux 0.0.0.9005 -* Bug fixes for `sim_design()` (failed when within or between factor number was 0) \ No newline at end of file +* Bug fixes for `sim_design()` (failed when within or between factor number was 0) + +# faux 0.0.0.9006 + +* Changes to argument order and names (more consistent, but may break old scripts) +* Updated vignettes \ No newline at end of file diff --git a/R/check_design.R b/R/check_design.R index 95f8c478..33db726b 100644 --- a/R/check_design.R +++ b/R/check_design.R @@ -15,7 +15,7 @@ #' #' within <- list(time = c("day", "night")) #' between <- list(pet = c("dog", "cat")) -#' design <- check_design(within, between) +#' check_design(within, between) #' #' @export #' @@ -116,12 +116,12 @@ check_design <- function(within = list(), between = list(), between_factors = between_factors, within_labels = within_labels, between_labels = between_labels, + cells_w = cells_w, + cells_b = cells_b, cell_n = cell_n, cell_mu = cell_mu, cell_sd = cell_sd, cell_r = cell_r, - cells_w = cells_w, - cells_b = cells_b, sub_id = sub_id ) } @@ -209,3 +209,115 @@ convert_param <- function (param, cells_w, cells_b, type = "this parameter") { dd } + + +#' Get design from long data +#' +#' Makes a best guess at the design of a long-format data frame. +#' Finds all columns that contain a single value per unit of analysis (between factors), +#' all columns that contain the same values per unit of analysis (within factors), and +#' all columns that differ over units of analysis (dv, continuous factors) +#' +#' @param .data the data frame (in long format) +#' @param id the column name(s) that identify a unit of analysis +#' @param dv the column name that identifies the DV +#' +#' @return the data frame in long format +#' +#' @export +#' +get_design_long <- function(.data, id = "sub_id", dv = "val") { + between_factors <- .data %>% + dplyr::group_by_at(dplyr::vars(tidyselect::one_of(id))) %>% + dplyr::summarise_all(dplyr::n_distinct) %>% + dplyr::ungroup() %>% + dplyr::select(-tidyselect::one_of(id)) %>% + dplyr::summarise_all(max) %>% + dplyr::select_if(~ . == 1) %>% + names() + + within_factors <- .data %>% + dplyr::select(-tidyselect::one_of(between_factors)) %>% + dplyr::group_by_at(dplyr::vars(tidyselect::one_of(id))) %>% + dplyr::summarise_all(paste0, collapse = ",") %>% + dplyr::ungroup() %>% + dplyr::select(-tidyselect::one_of(id)) %>% + dplyr::summarise_all(dplyr::n_distinct) %>% + dplyr::select_if(~ . == 1) %>% + names() + + within <- .data %>% + dplyr::select(tidyselect::one_of(within_factors)) %>% + dplyr::mutate_all(as.factor) %>% + dplyr::summarise_all(~levels(.) %>% paste0(collapse = ".|.")) %>% + as.list() %>% + sapply(strsplit, split=".|.", fixed = TRUE) + + between <- .data %>% + dplyr::select(tidyselect::one_of(between_factors)) %>% + dplyr::mutate_all(as.factor) %>% + dplyr::summarise_all(~levels(.) %>% paste0(collapse = ".|.")) %>% + as.list() %>% + sapply(strsplit, split=".|.", fixed = TRUE) + + between_labels <- purrr::map(between, fix_name_labels) + within_labels <- purrr::map(within, fix_name_labels) + + cells_b <- do.call(expand.grid, between) %>% + tidyr::unite("b", 1:ncol(.)) %>% dplyr::pull("b") + + cells_w <- do.call(expand.grid, within) %>% + tidyr::unite("b", 1:ncol(.)) %>% dplyr::pull("b") + + # get n, mu, sd, r per cell + chk <- check_sim_stats(.data, between_factors, within_factors, dv, id) + + n <- chk %>% + tidyr::unite(".within", tidyselect::one_of(between_factors)) %>% + dplyr::select(.within, var, n) %>% + tidyr::spread(var, n) %>% + tibble::column_to_rownames(".within") + + mu <- chk %>% + tidyr::unite(".within", tidyselect::one_of(between_factors)) %>% + dplyr::select(.within, var, mean) %>% + tidyr::spread(var, mean) %>% + tibble::column_to_rownames(".within") + + sd <- chk %>% + tidyr::unite(".within", tidyselect::one_of(between_factors)) %>% + dplyr::select(.within, var, sd) %>% + tidyr::spread(var, sd) %>% + tibble::column_to_rownames(".within") + + cors <- chk %>% + tidyr::unite(".between", tidyselect::one_of(between_factors)) %>% + dplyr::select(tidyselect::one_of(c(".between", "var", cells_w))) %>% + dplyr::mutate(var = forcats::fct_relevel(var, cells_w)) %>% + dplyr::arrange(var) %>% + dplyr::group_by(.between) %>% + tidyr::nest(.key = "r") %>% + as.list() + + r <- purrr::map(cors$r, ~tibble::column_to_rownames(., "var")) + names(r) <- cors$.between + + design <- list( + within = within, + between = between, + within_factors = within_factors, + between_factors = between_factors, + within_labels = within_labels, + between_labels = between_labels, + cells_w = cells_w, + cells_b = cells_b, + cell_n = n, + cell_mu = mu, + cell_sd = sd, + cell_r = r, + sub_id = id + ) + + design +} + diff --git a/R/check_sim_stats.R b/R/check_sim_stats.R index cad641da..7f82ad3b 100644 --- a/R/check_sim_stats.R +++ b/R/check_sim_stats.R @@ -2,7 +2,7 @@ #' #' \code{check_sim_stats} Generates a table of the correlations and means of numeric columns in a data frame #' -#' @param dat the existing dataframe +#' @param .data the existing tbl #' @param between a vector of column names for between-subject factors #' @param within a vector of column names for within-subject factors (if data is long) #' @param dv the column name of the dv (if data is long) @@ -10,22 +10,22 @@ #' @param digits how many digits to round to (default = 2) #' @param usekable logical. If TRUE, output with knitr::kable #' -#' @return tibble or kable +#' @return a tbl or kable #' @examples #' check_sim_stats(iris, "Species") #' @export #' -check_sim_stats <- function(dat, between = c(), within = c(), dv = c(), id = c(), +check_sim_stats <- function(.data, between = c(), within = c(), dv = c(), id = c(), digits = 2, usekable = FALSE) { if (length(within) && length(dv) && length(id)) { # convert long to wide - dat <- long2wide(dat, within, between, dv, id) %>% + .data <- long2wide(.data, within, between, dv, id) %>% dplyr::select(-tidyselect::one_of(id)) } - grpdat <- select_num_grp(dat, between) + grpdat <- select_num_grp(.data, between) grpvars <- dplyr::group_vars(grpdat) numvars <- names(grpdat)[!names(grpdat) %in% grpvars] diff --git a/R/long2wide.R b/R/long2wide.R index 0d075fc7..d2c4e7b1 100644 --- a/R/long2wide.R +++ b/R/long2wide.R @@ -2,18 +2,22 @@ #' #' Converts data from long format to wide #' -#' @param dat the long data frame to convert +#' @param .data the tbl in long format #' @param within the names of the within column(s) #' @param between the names of between column(s) (optional) #' @param dv the name of the DV (value) column #' @param id the names of the column(s) for grouping observations #' -#' @return the data frame in wide format +#' @return a tbl in wide format +#' +#' @examples +#' df_long <- sim_design(2, 2, long = TRUE) +#' long2wide(df_long, "A", "B", "val", "sub_id") #' #' @export #' -long2wide <- function(dat, within = c(), between = c(), dv = c(), id = c()) { - dat %>% +long2wide <- function(.data, within = c(), between = c(), dv = "val", id = "sub_id") { + .data %>% dplyr::select(tidyselect::one_of(c(id, between, within, dv))) %>% tidyr::unite(".tmpwithin.", tidyselect::one_of(within)) %>% dplyr::group_by_at(dplyr::vars(tidyselect::one_of(between))) %>% @@ -25,17 +29,25 @@ long2wide <- function(dat, within = c(), between = c(), dv = c(), id = c()) { #' #' Converts data from wide format to long #' -#' @param dat the wide data frame to convert -#' @param within the names of the within factors -#' @param dv the names of the DV (value) columns -#' @param sep Separator between columns (see tidyr::separate) +#' @param .data the tbl in wide format +#' @param within_factors the names of the within factors +#' @param within_cols the names (or indices) of the within-subject (value) columns +#' @param sep Separator for within-columns (see tidyr::separate) +#' +#' @return a tbl in long format #' -#' @return the data frame in long format +#' @examples +#' wide2long(iris, c("Feature", "Measure"), 1:4) #' #' @export #' -wide2long <- function(dat, within_factors = c(), within_cols = c(), sep = "[^[:alnum:]]+") { - dat %>% +wide2long <- function(.data, within_factors = c(), within_cols = c(), sep = "[^[:alnum:]]+") { + if (is.numeric(within_cols)) { + within_cols <- names(.data)[within_cols] + } + + .data %>% tidyr::gather(".tmpwithin.", "val", tidyselect::one_of(within_cols)) %>% tidyr::separate(".tmpwithin.", within_factors, sep = sep) -} \ No newline at end of file +} + diff --git a/R/make_id.R b/R/make_id.R index 2720590a..2748032f 100644 --- a/R/make_id.R +++ b/R/make_id.R @@ -1,8 +1,9 @@ #' Make ID #' #' Make IDs with fixed length and a letter prefix for random effects (e.g., S001, S002, ..., S100). -#' @param n the number of IDs to generate +#' @param n the number of IDs to generate (or a vector of numbers) #' @param prefix the letter prefix to the number +#' @param digits the number of digits to use for the numeric part. Only used if this is larger than the number of digits in n. #' #' @return a vector of IDs #' @export @@ -10,8 +11,17 @@ #' @examples #' #' make_id(20, "SUBJECT_") +#' make_id(10:30, digits = 3) #' -make_id <- function(n = 100, prefix = "S") { - max_digits <- floor(log10(n))+1 - paste0(prefix, formatC(1:n, width = max_digits, flag = "0")) -} \ No newline at end of file +make_id <- function(n = 100, prefix = "S", digits = 0) { + # set max digits to the larger of digits in `n`` or `digits` + if (length(n) == 1) { + max_n <- n + n <- 1:max_n + } else { + max_n <- max(n) + } + + max_digits <- max(floor(log10(max_n))+1, digits) + paste0(prefix, formatC(n, width = max_digits, flag = "0")) +} diff --git a/R/rnorm_multi.R b/R/rnorm_multi.R index 03c65033..6e44c8ce 100644 --- a/R/rnorm_multi.R +++ b/R/rnorm_multi.R @@ -1,6 +1,6 @@ #' Multiple Normally Distributed Vectors #' -#' \code{rnorm_multi} makes multiple normally distributed vectors with specified relationships +#' \code{rnorm_multi()} makes multiple normally distributed vectors with specified relationships. #' #' @param n the number of samples required #' @param vars the number of variables to return @@ -12,10 +12,12 @@ #' @param as.matrix logical. If true, returns a matrix #' @param cors (deprecated; use r) #' -#' @return dataframe of vars vectors +#' @return a tbl of vars vectors +#' #' @examples -#' rnorm_multi(100, 3, c(0.2, 0.4, 0.5), varnames=c("A", "B", "C")) -#' rnorm_multi(100, 3, c(1, 0.2, -0.5, 0.2, 1, 0.5, -0.5, 0.5, 1), varnames=c("A", "B", "C")) +#' rnorm_multi(100, 3, 0, 1, c(0.2, 0.4, 0.5), varnames=c("A", "B", "C")) +#' rnorm_multi(100, 3, 0, 1, c(1, 0.2, -0.5, 0.2, 1, 0.5, -0.5, 0.5, 1), varnames=c("A", "B", "C")) +#' #' @export rnorm_multi <- function(n, vars = 3, mu = 0, sd = 1, r = 0, diff --git a/R/select_num_grp.R b/R/select_num_grp.R index 5e9d1342..ac6c0a50 100644 --- a/R/select_num_grp.R +++ b/R/select_num_grp.R @@ -2,39 +2,39 @@ #' #' \code{select_num_grp} Select grouping and (optionally specified) numeric columns and group #' -#' @param dat the existing dataframe +#' @param .data the existing tbl #' @param between an optional list of column names to group by #' @param cols an optional list of column names to return (default of NULL returns all numeric columns) #' -#' @return tibble +#' @return a tbl #' @examples #' select_num_grp(iris, "Species") #' @export -select_num_grp <- function(dat, between = c(), cols = NULL) { +select_num_grp <- function(.data, between = c(), cols = NULL) { # error checking ----------------- - if (is.matrix(dat)) { - dat = as.data.frame(dat) - } else if (!is.data.frame(dat)) { - stop("dat must be a data frame or matrix") + if (is.matrix(.data)) { + .data = as.data.frame(.data) + } else if (!is.data.frame(.data)) { + stop(".data must be a data frame or matrix") } # select only grouping and numeric columns ----------------- if (is.null(between)) { # no grouping, so select all numeric columns - numdat <- dplyr::select_if(dat, is.numeric) + numdat <- dplyr::select_if(.data, is.numeric) grpdat <- numdat } else if (is.numeric(between) || is.character(between)) { # get grouping column names if specified by index - if (is.numeric(between)) between <- names(dat)[between] + if (is.numeric(between)) between <- names(.data)[between] # numeric columns, excluding grouping columns - numdat <- dat %>% + numdat <- .data %>% dplyr::select(-tidyselect::one_of(between)) %>% dplyr::select_if(is.numeric) # get grouping columns, add remaining numeric columns, and group - grpdat <- dat %>% + grpdat <- .data %>% dplyr::select(tidyselect::one_of(between)) %>% dplyr::bind_cols(numdat) %>% dplyr::group_by_at(dplyr::vars(tidyselect::one_of(between))) @@ -44,7 +44,7 @@ select_num_grp <- function(dat, between = c(), cols = NULL) { if (!is.null(cols)) { # return only grouping and cols - if (is.numeric(cols)) cols <- names(dat)[cols] + if (is.numeric(cols)) cols <- names(.data)[cols] grpdat <- grpdat %>% dplyr::select(tidyselect::one_of(c(between, cols))) diff --git a/R/sim_design.R b/R/sim_design.R index a83c22de..103d530a 100644 --- a/R/sim_design.R +++ b/R/sim_design.R @@ -1,6 +1,6 @@ #' Simulate Data from Design #' -#' \code{sim_design} generates a dataframe with a specified within and between design +#' \code{sim_design()} generates a data table with a specified within and between design. #' #' @param within a list of the within-subject factors #' @param between a list of the between-subject factors @@ -9,21 +9,21 @@ #' @param sd the standard deviations of the variables (numeric vector of length 1 or vars) #' @param r the correlations among the variables (can be a single number, vars\*vars matrix, vars\*vars vector, or a vars\*(vars-1)/2 vector) #' @param empirical logical. If true, mu, sd and r specify the empirical not population mean, sd and covariance -#' @param frame_long Whether the returned dataframe is in wide (default = FALSE) or long (TRUE) format +#' @param long Whether the returned tbl is in wide (default = FALSE) or long (TRUE) format #' -#' @return dataframe +#' @return a tbl #' #' @export #' sim_design <- function(within = list(), between = list(), n = 100, mu = 0, sd = 1, r = 0, - empirical = FALSE, frame_long = FALSE) { + empirical = FALSE, long = FALSE) { # check the design is specified correctly design <- check_design(within = within, between = between, n = n, mu = mu, sd = sd, r = r) # simulate the data - sim_design_(design, empirical = empirical, frame_long = frame_long) + sim_design_(design, empirical = empirical, long = long) } #' Fix name labels @@ -45,16 +45,16 @@ fix_name_labels <- function(x) { #' Simulate Data from Design #' -#' \code{sim_design_} generates a dataframe with a specified design +#' \code{sim_design_} generates a data table with a specified design #' #' @param design A list of design parameters created by check_design() #' @param empirical logical. If true, mu, sd and r specify the empirical not population mean, sd and covariance -#' @param frame_long Whether the returned dataframe is in wide (default = FALSE) or long (TRUE) format +#' @param long Whether the returned tbl is in wide (default = FALSE) or long (TRUE) format #' -#' @return dataframe +#' @return a tbl #' @keywords internal #' -sim_design_ <- function(design, empirical = FALSE, frame_long = FALSE) { +sim_design_ <- function(design, empirical = FALSE, long = FALSE) { list2env(design, envir = environment()) # simulate data for each between-cell @@ -100,7 +100,7 @@ sim_design_ <- function(design, empirical = FALSE, frame_long = FALSE) { # df_wide[[f]] <- factor(df_wide[[f]], levels = between[[f]]) #} - if (frame_long == TRUE && length(within)) { + if (long == TRUE && length(within)) { # not necessary for fully between designs col_order <- c("sub_id", between_factors, within_factors, "val") %>% setdiff(".tmpvar.") diff --git a/R/sim_df.R b/R/sim_df.R index d873233c..a7d222c5 100644 --- a/R/sim_df.R +++ b/R/sim_df.R @@ -1,20 +1,20 @@ #' Simulate an existing dataframe #' -#' \code{sim_df} Produces a dataframe with the same distributions and correlations as an existing dataframe. Only returns numeric columns and simulates all numeric variables from a continuous normal distribution (for now). +#' \code{sim_df} Produces a data table with the same distributions and correlations as an existing data table Only returns numeric columns and simulates all numeric variables from a continuous normal distribution (for now). #' -#' @param dat the existing dataframe (must be in wide format) +#' @param .data the existing tbl (must be in wide format) #' @param n the number of samples to return per group #' @param between a list of the between-subject columns #' @param empirical logical. Passed on to rnorm_multi #' @param grp_by (deprecated; use between) #' -#' @return tibble +#' @return a tbl #' @examples #' iris100 <- sim_df(iris, 100) #' iris_species <- sim_df(iris, 100, between = "Species") #' @export -sim_df <- function (dat, n = 100, between = c(), empirical = FALSE, grp_by = NULL) { +sim_df <- function (.data, n = 100, between = c(), empirical = FALSE, grp_by = NULL) { # error checking if ( !is.numeric(n) || n %% 1 > 0 || n < 3 ) { stop("n must be an integer > 2") @@ -25,7 +25,7 @@ sim_df <- function (dat, n = 100, between = c(), empirical = FALSE, grp_by = NUL if (between == c()) between = grp_by # set between to grp_by if between is not set } - grpdat <- select_num_grp(dat, between) + grpdat <- select_num_grp(.data, between) simdat <- grpdat %>% tidyr::nest() %>% diff --git a/R/sim_mixed_df.R b/R/sim_mixed_df.R index d6508d0f..646b59b1 100644 --- a/R/sim_mixed_df.R +++ b/R/sim_mixed_df.R @@ -1,36 +1,36 @@ #' Generate a sample with random intercepts for subjects and items #' -#' \code{sim_mixed_df} Produces a dataframe with the same distributions of by-subject and by-item random intercepts as an existing dataframe +#' \code{sim_mixed_df()} produces a data table with the same distributions of by-subject and by-item random intercepts as an existing data table. #' -#' @param dat the existing dataframe +#' @param .data the existing tbl #' @param sub_n the number of subjects to simulate #' @param item_n the number of items to simulate #' @param dv the column name or index containing the DV #' @param sub_id the column name or index for the subject IDs #' @param item_id the column name or index for the item IDs #' -#' @return tibble +#' @return a tbl #' @examples #' \donttest{sim_mixed_df(faceratings, 10, 10, "rating", "rater_id", "face_id")} #' @export -sim_mixed_df <- function(dat, sub_n = 100, item_n = 25, +sim_mixed_df <- function(.data, sub_n = 100, item_n = 25, dv = 1, sub_id = 2, item_id = 3) { # error checking ------------------------------------------------------------- - if (is.matrix(dat)) { - dat = as.data.frame(dat) - } else if (!is.data.frame(dat)) { - stop("dat must be a data frame or matrix") + if (is.matrix(.data)) { + .data = as.data.frame(.data) + } else if (!is.data.frame(.data)) { + stop(".data must be a data frame or matrix") } # get column names if specified by index - if (is.numeric(dv)) dv <- names(dat)[dv] - if (is.numeric(sub_id)) sub_id <- names(dat)[sub_id] - if (is.numeric(item_id)) item_id <- names(dat)[item_id] + if (is.numeric(dv)) dv <- names(.data)[dv] + if (is.numeric(sub_id)) sub_id <- names(.data)[sub_id] + if (is.numeric(item_id)) item_id <- names(.data)[item_id] lmer_formula <- paste0(dv, " ~ 1 + (1 | ", sub_id, ") + (1 | ", item_id, ")") %>% stats::as.formula() - mod <- lme4::lmer(lmer_formula, data = dat) + mod <- lme4::lmer(lmer_formula, data = .data) grand_i <- lme4::fixef(mod) sds <- lme4::VarCorr(mod) %>% as.data.frame() diff --git a/README.Rmd b/README.Rmd index 7a7c7ed1..c2c1f805 100644 --- a/README.Rmd +++ b/README.Rmd @@ -120,6 +120,29 @@ It is useful for IDs for random effects (e.g., subjects or stimuli) to be charac make_id(n = 10, prefix = "ITEM_") ``` +You can also manually set the number of digits and set `n` to a range of integers. + +```{r} +make_id(n = 10:20, digits = 3) +``` + + +### long2wide + +```{r} +between <- list("pet" = c("cat", "dog")) +within <- list("time" = c("day", "night")) +df_long <- sim_design(within, between, long = TRUE) + +df_wide <- long2wide(df_long, + within = "time", + between = "pet", + dv = "val", + id = "sub_id") +``` + + + ### pos_def_limits diff --git a/README.md b/README.md index fd017880..f068d489 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ df <- sim_design(within, between, rnorm\_multi ------------ -This function makes multiple normally distributed vectors with specified parameters and relationships.[see vignette](articles/rnorm_multi.html) +This function makes multiple normally distributed vectors with specified parameters and relationships. [see vignette](articles/rnorm_multi.html) For example, the following creates a sample that has 100 observations of 3 variables, drawn from a population where A has a mean of 0 and SD of 1, while B and C have means of 20 and SDs of 5. A correlates with B and C with r = 0.5, and B and C correlate with r = 0.25. @@ -122,6 +122,28 @@ make_id(n = 10, prefix = "ITEM_") #> [8] "ITEM_08" "ITEM_09" "ITEM_10" ``` +You can also manually set the number of digits and set `n` to a range of integers. + +``` r +make_id(n = 10:20, digits = 3) +#> [1] "S010" "S011" "S012" "S013" "S014" "S015" "S016" "S017" "S018" "S019" +#> [11] "S020" +``` + +### long2wide + +``` r +between <- list("pet" = c("cat", "dog")) +within <- list("time" = c("day", "night")) +df_long <- sim_design(within, between, long = TRUE) + +df_wide <- long2wide(df_long, + within = "time", + between = "pet", + dv = "val", + id = "sub_id") +``` + ### pos\_def\_limits Not all correlation matrices are possible. For example, if variables A and B are correlated with r = 1.0, then the correlation between A and C can only be exactly equal to the correlation between B and C. diff --git a/docs/articles/rnorm_multi.html b/docs/articles/rnorm_multi.html index 122f09b9..ee3f4a82 100644 --- a/docs/articles/rnorm_multi.html +++ b/docs/articles/rnorm_multi.html @@ -82,7 +82,7 @@

Simulate Correlated Variables

Lisa DeBruine

-

2019-05-02

+

2019-05-03

diff --git a/docs/articles/sim_design.html b/docs/articles/sim_design.html index 5e40bb1a..fe2d0404 100644 --- a/docs/articles/sim_design.html +++ b/docs/articles/sim_design.html @@ -82,7 +82,7 @@

Simulate by Design

Lisa DeBruine

-

2019-05-02

+

2019-05-03

@@ -440,10 +440,10 @@

expert_day = triangle, expert_night = triangle ) -

You can set frame_long = TRUE to return the data frame in long format, which is usually easier for plotting.

+

You can set long = TRUE to return the data frame in long format, which is usually easier for plotting.

df <- sim_design(within, between, n = 100, 
                  mu = mu, sd = 2, r = r, 
-                 frame_long = TRUE)
+ long = TRUE)

diff --git a/docs/articles/sim_df.html b/docs/articles/sim_df.html index b69b7f57..b970f643 100644 --- a/docs/articles/sim_df.html +++ b/docs/articles/sim_df.html @@ -82,7 +82,7 @@

Simulate from Existing Data

Lisa DeBruine

-

2019-05-02

+

2019-05-03

diff --git a/docs/index.html b/docs/index.html index 0e40054e..6c9528ff 100644 --- a/docs/index.html +++ b/docs/index.html @@ -395,6 +395,23 @@

make_id(n = 10, prefix = "ITEM_")
 #>  [1] "ITEM_01" "ITEM_02" "ITEM_03" "ITEM_04" "ITEM_05" "ITEM_06" "ITEM_07"
 #>  [8] "ITEM_08" "ITEM_09" "ITEM_10"
+

You can also manually set the number of digits and set n to a range of integers.

+
make_id(n = 10:20, digits = 3)
+#>  [1] "S010" "S011" "S012" "S013" "S014" "S015" "S016" "S017" "S018" "S019"
+#> [11] "S020"
+ +
+

+long2wide

+
between <- list("pet" = c("cat", "dog"))
+within <- list("time" = c("day", "night"))
+df_long <- sim_design(within, between, long = TRUE)
+
+df_wide <- long2wide(df_long, 
+                     within = "time", 
+                     between = "pet", 
+                     dv = "val", 
+                     id = "sub_id")

diff --git a/docs/news/index.html b/docs/news/index.html index ff5eeb2d..b8338901 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -130,6 +130,14 @@

  • Bug fixes for sim_design() (failed when within or between factor number was 0)
+

+
+

+faux 0.0.0.9006

+
    +
  • Changes to argument order and names (more consistent, but may break old scripts)
  • +
  • Updated vignettes
  • +
@@ -139,6 +147,7 @@

Contents

diff --git a/docs/reference/check_design.html b/docs/reference/check_design.html index 801e75e0..b6769873 100644 --- a/docs/reference/check_design.html +++ b/docs/reference/check_design.html @@ -167,7 +167,90 @@

Examp
within <- list(time = c("day", "night")) between <- list(pet = c("dog", "cat")) -design <- check_design(within, between)
+check_design(within, between)
#> $within +#> $within$time +#> [1] "day" "night" +#> +#> +#> $between +#> $between$pet +#> [1] "dog" "cat" +#> +#> +#> $within_factors +#> [1] "time" +#> +#> $between_factors +#> [1] "pet" +#> +#> $within_labels +#> $within_labels$time +#> day night +#> "day" "night" +#> +#> +#> $between_labels +#> $between_labels$pet +#> dog cat +#> "dog" "cat" +#> +#> +#> $cell_n +#> dog cat +#> day 100 100 +#> night 100 100 +#> +#> $cell_mu +#> dog cat +#> day 0 0 +#> night 0 0 +#> +#> $cell_sd +#> dog cat +#> day 1 1 +#> night 1 1 +#> +#> $cell_r +#> $cell_r$dog +#> [,1] [,2] +#> [1,] 1 0 +#> [2,] 0 1 +#> +#> $cell_r$cat +#> [,1] [,2] +#> [1,] 1 0 +#> [2,] 0 1 +#> +#> +#> $cells_w +#> [1] "day" "night" +#> +#> $cells_b +#> [1] "dog" "cat" +#> +#> $sub_id +#> [1] "S001" "S002" "S003" "S004" "S005" "S006" "S007" "S008" "S009" "S010" +#> [11] "S011" "S012" "S013" "S014" "S015" "S016" "S017" "S018" "S019" "S020" +#> [21] "S021" "S022" "S023" "S024" "S025" "S026" "S027" "S028" "S029" "S030" +#> [31] "S031" "S032" "S033" "S034" "S035" "S036" "S037" "S038" "S039" "S040" +#> [41] "S041" "S042" "S043" "S044" "S045" "S046" "S047" "S048" "S049" "S050" +#> [51] "S051" "S052" "S053" "S054" "S055" "S056" "S057" "S058" "S059" "S060" +#> [61] "S061" "S062" "S063" "S064" "S065" "S066" "S067" "S068" "S069" "S070" +#> [71] "S071" "S072" "S073" "S074" "S075" "S076" "S077" "S078" "S079" "S080" +#> [81] "S081" "S082" "S083" "S084" "S085" "S086" "S087" "S088" "S089" "S090" +#> [91] "S091" "S092" "S093" "S094" "S095" "S096" "S097" "S098" "S099" "S100" +#> [101] "S101" "S102" "S103" "S104" "S105" "S106" "S107" "S108" "S109" "S110" +#> [111] "S111" "S112" "S113" "S114" "S115" "S116" "S117" "S118" "S119" "S120" +#> [121] "S121" "S122" "S123" "S124" "S125" "S126" "S127" "S128" "S129" "S130" +#> [131] "S131" "S132" "S133" "S134" "S135" "S136" "S137" "S138" "S139" "S140" +#> [141] "S141" "S142" "S143" "S144" "S145" "S146" "S147" "S148" "S149" "S150" +#> [151] "S151" "S152" "S153" "S154" "S155" "S156" "S157" "S158" "S159" "S160" +#> [161] "S161" "S162" "S163" "S164" "S165" "S166" "S167" "S168" "S169" "S170" +#> [171] "S171" "S172" "S173" "S174" "S175" "S176" "S177" "S178" "S179" "S180" +#> [181] "S181" "S182" "S183" "S184" "S185" "S186" "S187" "S188" "S189" "S190" +#> [191] "S191" "S192" "S193" "S194" "S195" "S196" "S197" "S198" "S199" "S200" +#>
+
-
check_sim_stats(dat, between = c(), within = c(), dv = c(),
+    
check_sim_stats(.data, between = c(), within = c(), dv = c(),
   id = c(), digits = 2, usekable = FALSE)

Arguments

- - + + @@ -164,26 +164,26 @@

Arg

Value

-

tibble or kable

+

a tbl or kable

Examples

-
check_sim_stats(iris, "Species")
#> # A tibble: 12 x 9 +
check_sim_stats(iris, "Species")
#> # A tibble: 12 x 9 #> Species n var Sepal.Length Sepal.Width Petal.Length Petal.Width mean -#> <fct> <dbl> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 setosa 50 Sepa… 1 0.74 0.27 0.28 5.01 -#> 2 setosa 50 Sepa… 0.74 1 0.18 0.23 3.43 -#> 3 setosa 50 Peta… 0.27 0.18 1 0.33 1.46 -#> 4 setosa 50 Peta… 0.28 0.23 0.33 1 0.25 -#> 5 versic… 50 Sepa… 1 0.53 0.75 0.55 5.94 -#> 6 versic… 50 Sepa… 0.53 1 0.56 0.66 2.77 -#> 7 versic… 50 Peta… 0.75 0.56 1 0.79 4.26 -#> 8 versic… 50 Peta… 0.55 0.66 0.79 1 1.33 -#> 9 virgin… 50 Sepa… 1 0.46 0.86 0.28 6.59 -#> 10 virgin… 50 Sepa… 0.46 1 0.4 0.54 2.97 -#> 11 virgin… 50 Peta… 0.86 0.4 1 0.32 5.55 -#> 12 virgin… 50 Peta… 0.28 0.54 0.32 1 2.03 -#> # … with 1 more variable: sd <dbl>
+#>
<fct> <dbl> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> +#> 1 setosa 50 Sepa… 1 0.74 0.27 0.28 5.01 +#> 2 setosa 50 Sepa… 0.74 1 0.18 0.23 3.43 +#> 3 setosa 50 Peta… 0.27 0.18 1 0.33 1.46 +#> 4 setosa 50 Peta… 0.28 0.23 0.33 1 0.25 +#> 5 versic… 50 Sepa… 1 0.53 0.75 0.55 5.94 +#> 6 versic… 50 Sepa… 0.53 1 0.56 0.66 2.77 +#> 7 versic… 50 Peta… 0.75 0.56 1 0.79 4.26 +#> 8 versic… 50 Peta… 0.55 0.66 0.79 1 1.33 +#> 9 virgin… 50 Sepa… 1 0.46 0.86 0.28 6.59 +#> 10 virgin… 50 Sepa… 0.46 1 0.4 0.54 2.97 +#> 11 virgin… 50 Peta… 0.86 0.4 1 0.32 5.55 +#> 12 virgin… 50 Peta… 0.28 0.54 0.32 1 2.03 +#> # … with 1 more variable: sd <dbl>
dat

the existing dataframe

.data

the existing tbl

between
+ + + + + + + + + + + + + +
.data

the data frame (in long format)

id

the column name(s) that identify a unit of analysis

dv

the column name that identifies the DV

+ +

Value

+ +

the data frame in long format

+ + + + + + +
+ + +
+

Site built with pkgdown 1.3.0.

+
+
+ + + + + + + diff --git a/docs/reference/index.html b/docs/reference/index.html index 85381922..bedc5427 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -162,6 +162,12 @@

get_design_long()

+ +

Get design from long data

+ +

is_pos_def()

diff --git a/docs/reference/long2wide.html b/docs/reference/long2wide.html index b5ec7c90..654b00f5 100644 --- a/docs/reference/long2wide.html +++ b/docs/reference/long2wide.html @@ -126,14 +126,15 @@

Long to wide format

-
long2wide(dat, within = c(), between = c(), dv = c(), id = c())
+
long2wide(.data, within = c(), between = c(), dv = "val",
+  id = "sub_id")

Arguments

- - + + @@ -155,9 +156,26 @@

Arg

Value

-

the data frame in wide format

+

a tbl in wide format

+

Examples

+
df_long <- sim_design(2, 2, long = TRUE) +long2wide(df_long, "A", "B", "val", "sub_id")
#> # A tibble: 200 x 4 +#> sub_id B A1 A2 +#> <chr> <fct> <dbl> <dbl> +#> 1 S001 B1 0.387 -1.40 +#> 2 S002 B1 0.785 0.255 +#> 3 S003 B1 1.06 -2.44 +#> 4 S004 B1 0.796 -0.00557 +#> 5 S005 B1 1.76 0.622 +#> 6 S006 B1 0.691 1.15 +#> 7 S007 B1 0.559 -1.82 +#> 8 S008 B1 0.537 -0.247 +#> 9 S009 B1 -0.227 -0.244 +#> 10 S010 B1 -0.978 -0.283 +#> # … with 190 more rows
+
diff --git a/docs/reference/make_id.html b/docs/reference/make_id.html index f1bf100d..999c632b 100644 --- a/docs/reference/make_id.html +++ b/docs/reference/make_id.html @@ -126,19 +126,23 @@

Make ID

-
make_id(n = 100, prefix = "S")
+
make_id(n = 100, prefix = "S", digits = 0)

Arguments

dat

the long data frame to convert

.data

the tbl in long format

within
- + + + + +
n

the number of IDs to generate

the number of IDs to generate (or a vector of numbers)

prefix

the letter prefix to the number

digits

the number of digits to use for the numeric part. Only used if this is larger than the number of digits in n.

Value

@@ -151,7 +155,9 @@

Examp make_id(20, "SUBJECT_")
#> [1] "SUBJECT_01" "SUBJECT_02" "SUBJECT_03" "SUBJECT_04" "SUBJECT_05" #> [6] "SUBJECT_06" "SUBJECT_07" "SUBJECT_08" "SUBJECT_09" "SUBJECT_10" #> [11] "SUBJECT_11" "SUBJECT_12" "SUBJECT_13" "SUBJECT_14" "SUBJECT_15" -#> [16] "SUBJECT_16" "SUBJECT_17" "SUBJECT_18" "SUBJECT_19" "SUBJECT_20"
+#> [16] "SUBJECT_16" "SUBJECT_17" "SUBJECT_18" "SUBJECT_19" "SUBJECT_20"
make_id(10:30, digits = 3)
#> [1] "S010" "S011" "S012" "S013" "S014" "S015" "S016" "S017" "S018" "S019" +#> [11] "S020" "S021" "S022" "S023" "S024" "S025" "S026" "S027" "S028" "S029" +#> [21] "S030"

-
select_num_grp(dat, between = c(), cols = NULL)
+
select_num_grp(.data, between = c(), cols = NULL)

Arguments

- - + + @@ -147,25 +147,25 @@

Arg

Value

-

tibble

+

a tbl

Examples

-
select_num_grp(iris, "Species")
#> # A tibble: 150 x 5 -#> # Groups: Species [3] +
select_num_grp(iris, "Species")
#> # A tibble: 150 x 5 +#> # Groups: Species [3] #> Species Sepal.Length Sepal.Width Petal.Length Petal.Width -#> <fct> <dbl> <dbl> <dbl> <dbl> -#> 1 setosa 5.1 3.5 1.4 0.2 -#> 2 setosa 4.9 3 1.4 0.2 -#> 3 setosa 4.7 3.2 1.3 0.2 -#> 4 setosa 4.6 3.1 1.5 0.2 -#> 5 setosa 5 3.6 1.4 0.2 -#> 6 setosa 5.4 3.9 1.7 0.4 -#> 7 setosa 4.6 3.4 1.4 0.3 -#> 8 setosa 5 3.4 1.5 0.2 -#> 9 setosa 4.4 2.9 1.4 0.2 -#> 10 setosa 4.9 3.1 1.5 0.1 -#> # … with 140 more rows
+#>
<fct> <dbl> <dbl> <dbl> <dbl> +#> 1 setosa 5.1 3.5 1.4 0.2 +#> 2 setosa 4.9 3 1.4 0.2 +#> 3 setosa 4.7 3.2 1.3 0.2 +#> 4 setosa 4.6 3.1 1.5 0.2 +#> 5 setosa 5 3.6 1.4 0.2 +#> 6 setosa 5.4 3.9 1.7 0.4 +#> 7 setosa 4.6 3.4 1.4 0.3 +#> 8 setosa 5 3.4 1.5 0.2 +#> 9 setosa 4.4 2.9 1.4 0.2 +#> 10 setosa 4.9 3.1 1.5 0.1 +#> # … with 140 more rows
dat

the existing dataframe

.data

the existing tbl

between
@@ -161,14 +161,14 @@

Arg

- - + +

logical. If true, mu, sd and r specify the empirical not population mean, sd and covariance

frame_long

Whether the returned dataframe is in wide (default = FALSE) or long (TRUE) format

long

Whether the returned tbl is in wide (default = FALSE) or long (TRUE) format

Value

-

dataframe

+

a tbl

diff --git a/docs/reference/sim_design_.html b/docs/reference/sim_design_.html index f22f4165..997e7e70 100644 --- a/docs/reference/sim_design_.html +++ b/docs/reference/sim_design_.html @@ -32,7 +32,7 @@ - + @@ -122,11 +122,11 @@

Simulate Data from Design

-

sim_design_ generates a dataframe with a specified design

+

sim_design_ generates a data table with a specified design

-
sim_design_(design, empirical = FALSE, frame_long = FALSE)
+
sim_design_(design, empirical = FALSE, long = FALSE)

Arguments

@@ -140,14 +140,14 @@

Arg

- - + +

logical. If true, mu, sd and r specify the empirical not population mean, sd and covariance

frame_long

Whether the returned dataframe is in wide (default = FALSE) or long (TRUE) format

long

Whether the returned tbl is in wide (default = FALSE) or long (TRUE) format

Value

-

dataframe

+

a tbl

diff --git a/docs/reference/sim_df.html b/docs/reference/sim_df.html index 79deab5e..e3ea6eb6 100644 --- a/docs/reference/sim_df.html +++ b/docs/reference/sim_df.html @@ -32,7 +32,7 @@ - + @@ -122,19 +122,19 @@

Simulate an existing dataframe

-

sim_df Produces a dataframe with the same distributions and correlations as an existing dataframe. Only returns numeric columns and simulates all numeric variables from a continuous normal distribution (for now).

+

sim_df Produces a data table with the same distributions and correlations as an existing data table Only returns numeric columns and simulates all numeric variables from a continuous normal distribution (for now).

-
sim_df(dat, n = 100, between = c(), empirical = FALSE,
+    
sim_df(.data, n = 100, between = c(), empirical = FALSE,
   grp_by = NULL)

Arguments

- - + + @@ -156,7 +156,7 @@

Arg

Value

-

tibble

+

a tbl

Examples

diff --git a/docs/reference/sim_mixed_df.html b/docs/reference/sim_mixed_df.html index 480535c1..36852235 100644 --- a/docs/reference/sim_mixed_df.html +++ b/docs/reference/sim_mixed_df.html @@ -32,7 +32,7 @@ - + @@ -122,19 +122,19 @@

Generate a sample with random intercepts for subjects and items

-

sim_mixed_df Produces a dataframe with the same distributions of by-subject and by-item random intercepts as an existing dataframe

+

sim_mixed_df() produces a data table with the same distributions of by-subject and by-item random intercepts as an existing data table.

-
sim_mixed_df(dat, sub_n = 100, item_n = 25, dv = 1, sub_id = 2,
+    
sim_mixed_df(.data, sub_n = 100, item_n = 25, dv = 1, sub_id = 2,
   item_id = 3)

Arguments

dat

the existing dataframe (must be in wide format)

.data

the existing tbl (must be in wide format)

n
- - + + @@ -160,111 +160,111 @@

Arg

Value

-

tibble

+

a tbl

Examples

-
sim_mixed_df(faceratings, 10, 10, "rating", "rater_id", "face_id")
#> sub_id item_id sub_i item_i dv -#> 1 1 1 -1.31204794 -0.91527468 -0.5821852 -#> 2 2 1 0.58686412 -0.91527468 3.6621355 -#> 3 3 1 0.03209700 -0.91527468 1.1597510 -#> 4 4 1 0.19719216 -0.91527468 2.9041436 -#> 5 5 1 0.85825196 -0.91527468 1.6956532 -#> 6 6 1 1.23958914 -0.91527468 3.3635152 -#> 7 7 1 -0.04067057 -0.91527468 2.4206597 -#> 8 8 1 -0.49972036 -0.91527468 1.2830612 -#> 9 9 1 -0.39832107 -0.91527468 2.4032570 -#> 10 10 1 -0.27425086 -0.91527468 2.8374416 -#> 11 1 2 -1.31204794 -0.75442016 2.8801949 -#> 12 2 2 0.58686412 -0.75442016 4.6594123 -#> 13 3 2 0.03209700 -0.75442016 2.3269642 -#> 14 4 2 0.19719216 -0.75442016 4.2190505 -#> 15 5 2 0.85825196 -0.75442016 1.6568714 -#> 16 6 2 1.23958914 -0.75442016 3.7147063 -#> 17 7 2 -0.04067057 -0.75442016 2.6823381 -#> 18 8 2 -0.49972036 -0.75442016 1.2207087 -#> 19 9 2 -0.39832107 -0.75442016 0.1317110 -#> 20 10 2 -0.27425086 -0.75442016 3.5317627 -#> 21 1 3 -1.31204794 -0.52699466 2.3226909 -#> 22 2 3 0.58686412 -0.52699466 2.4430166 -#> 23 3 3 0.03209700 -0.52699466 1.9510354 -#> 24 4 3 0.19719216 -0.52699466 2.5561268 -#> 25 5 3 0.85825196 -0.52699466 2.7123415 -#> 26 6 3 1.23958914 -0.52699466 3.4618648 -#> 27 7 3 -0.04067057 -0.52699466 3.3228664 -#> 28 8 3 -0.49972036 -0.52699466 4.7390622 -#> 29 9 3 -0.39832107 -0.52699466 2.3873381 -#> 30 10 3 -0.27425086 -0.52699466 1.2534605 -#> 31 1 4 -1.31204794 -0.02510984 0.8446420 -#> 32 2 4 0.58686412 -0.02510984 4.0745936 -#> 33 3 4 0.03209700 -0.02510984 2.2571747 -#> 34 4 4 0.19719216 -0.02510984 2.1582137 -#> 35 5 4 0.85825196 -0.02510984 2.6919926 -#> 36 6 4 1.23958914 -0.02510984 3.2690829 -#> 37 7 4 -0.04067057 -0.02510984 3.6804353 -#> 38 8 4 -0.49972036 -0.02510984 0.2449312 -#> 39 9 4 -0.39832107 -0.02510984 4.4384063 -#> 40 10 4 -0.27425086 -0.02510984 2.5131083 -#> 41 1 5 -1.31204794 1.14363329 3.3097340 -#> 42 2 5 0.58686412 1.14363329 4.0280504 -#> 43 3 5 0.03209700 1.14363329 3.4736644 -#> 44 4 5 0.19719216 1.14363329 4.4829729 -#> 45 5 5 0.85825196 1.14363329 6.0465548 -#> 46 6 5 1.23958914 1.14363329 4.0794730 -#> 47 7 5 -0.04067057 1.14363329 4.0704548 -#> 48 8 5 -0.49972036 1.14363329 3.4539076 -#> 49 9 5 -0.39832107 1.14363329 4.4518836 -#> 50 10 5 -0.27425086 1.14363329 3.7230423 -#> 51 1 6 -1.31204794 0.02181121 1.7452042 -#> 52 2 6 0.58686412 0.02181121 4.5943491 -#> 53 3 6 0.03209700 0.02181121 3.0840564 -#> 54 4 6 0.19719216 0.02181121 3.6131343 -#> 55 5 6 0.85825196 0.02181121 2.9055922 -#> 56 6 6 1.23958914 0.02181121 3.2747244 -#> 57 7 6 -0.04067057 0.02181121 2.5952921 -#> 58 8 6 -0.49972036 0.02181121 2.2170451 -#> 59 9 6 -0.39832107 0.02181121 4.3551644 -#> 60 10 6 -0.27425086 0.02181121 0.6118565 -#> 61 1 7 -1.31204794 -0.53113887 0.9948724 -#> 62 2 7 0.58686412 -0.53113887 3.2054074 -#> 63 3 7 0.03209700 -0.53113887 1.8000139 -#> 64 4 7 0.19719216 -0.53113887 2.1077354 -#> 65 5 7 0.85825196 -0.53113887 3.0181285 -#> 66 6 7 1.23958914 -0.53113887 3.0721583 -#> 67 7 7 -0.04067057 -0.53113887 2.1009421 -#> 68 8 7 -0.49972036 -0.53113887 2.3233091 -#> 69 9 7 -0.39832107 -0.53113887 2.9582357 -#> 70 10 7 -0.27425086 -0.53113887 4.1178312 -#> 71 1 8 -1.31204794 -0.69069006 1.3048000 -#> 72 2 8 0.58686412 -0.69069006 3.2600878 -#> 73 3 8 0.03209700 -0.69069006 2.1985137 -#> 74 4 8 0.19719216 -0.69069006 2.8759249 -#> 75 5 8 0.85825196 -0.69069006 2.8337853 -#> 76 6 8 1.23958914 -0.69069006 2.7156484 -#> 77 7 8 -0.04067057 -0.69069006 2.2678694 -#> 78 8 8 -0.49972036 -0.69069006 1.6444369 -#> 79 9 8 -0.39832107 -0.69069006 1.7506832 -#> 80 10 8 -0.27425086 -0.69069006 2.8302596 -#> 81 1 9 -1.31204794 -0.41158246 1.5533167 -#> 82 2 9 0.58686412 -0.41158246 0.6675154 -#> 83 3 9 0.03209700 -0.41158246 2.7254063 -#> 84 4 9 0.19719216 -0.41158246 2.3380499 -#> 85 5 9 0.85825196 -0.41158246 3.0601278 -#> 86 6 9 1.23958914 -0.41158246 3.7980488 -#> 87 7 9 -0.04067057 -0.41158246 4.0910659 -#> 88 8 9 -0.49972036 -0.41158246 1.7803072 -#> 89 9 9 -0.39832107 -0.41158246 1.1584322 -#> 90 10 9 -0.27425086 -0.41158246 4.1641162 -#> 91 1 10 -1.31204794 0.45071102 1.3128191 -#> 92 2 10 0.58686412 0.45071102 4.3255009 -#> 93 3 10 0.03209700 0.45071102 2.4496289 -#> 94 4 10 0.19719216 0.45071102 2.5378068 -#> 95 5 10 0.85825196 0.45071102 3.1817382 -#> 96 6 10 1.23958914 0.45071102 4.4856500 -#> 97 7 10 -0.04067057 0.45071102 4.8521086 -#> 98 8 10 -0.49972036 0.45071102 3.5287348 -#> 99 9 10 -0.39832107 0.45071102 1.5642742 -#> 100 10 10 -0.27425086 0.45071102 2.1061951
+
sim_mixed_df(faceratings, 10, 10, "rating", "rater_id", "face_id")
#> sub_id item_id sub_i item_i dv +#> 1 1 1 0.15336871 0.1152507 3.4263347 +#> 2 2 1 -0.07546968 0.1152507 2.6552210 +#> 3 3 1 -0.09464565 0.1152507 2.5473771 +#> 4 4 1 0.13680669 0.1152507 4.5736075 +#> 5 5 1 0.46710613 0.1152507 4.6470300 +#> 6 6 1 0.71713231 0.1152507 5.0470723 +#> 7 7 1 -0.16377959 0.1152507 3.0286129 +#> 8 8 1 -0.03648029 0.1152507 3.0203508 +#> 9 9 1 -0.44490238 0.1152507 2.4007496 +#> 10 10 1 -0.50294582 0.1152507 1.4482325 +#> 11 1 2 0.15336871 0.9694343 4.2646276 +#> 12 2 2 -0.07546968 0.9694343 3.5117228 +#> 13 3 2 -0.09464565 0.9694343 1.9205807 +#> 14 4 2 0.13680669 0.9694343 3.3332175 +#> 15 5 2 0.46710613 0.9694343 4.1037056 +#> 16 6 2 0.71713231 0.9694343 4.8340290 +#> 17 7 2 -0.16377959 0.9694343 4.3931885 +#> 18 8 2 -0.03648029 0.9694343 3.5224828 +#> 19 9 2 -0.44490238 0.9694343 2.7403387 +#> 20 10 2 -0.50294582 0.9694343 4.9209943 +#> 21 1 3 0.15336871 -0.1809222 2.3955324 +#> 22 2 3 -0.07546968 -0.1809222 5.0649247 +#> 23 3 3 -0.09464565 -0.1809222 3.0032075 +#> 24 4 3 0.13680669 -0.1809222 2.4135067 +#> 25 5 3 0.46710613 -0.1809222 4.5656069 +#> 26 6 3 0.71713231 -0.1809222 2.8650467 +#> 27 7 3 -0.16377959 -0.1809222 3.6126806 +#> 28 8 3 -0.03648029 -0.1809222 0.9722492 +#> 29 9 3 -0.44490238 -0.1809222 0.6125408 +#> 30 10 3 -0.50294582 -0.1809222 3.8909402 +#> 31 1 4 0.15336871 1.0979794 5.9448229 +#> 32 2 4 -0.07546968 1.0979794 3.9574235 +#> 33 3 4 -0.09464565 1.0979794 4.8079004 +#> 34 4 4 0.13680669 1.0979794 5.0826263 +#> 35 5 4 0.46710613 1.0979794 3.3817108 +#> 36 6 4 0.71713231 1.0979794 3.2445244 +#> 37 7 4 -0.16377959 1.0979794 4.2746244 +#> 38 8 4 -0.03648029 1.0979794 4.7967650 +#> 39 9 4 -0.44490238 1.0979794 4.3737837 +#> 40 10 4 -0.50294582 1.0979794 4.2923638 +#> 41 1 5 0.15336871 0.2255086 5.9170173 +#> 42 2 5 -0.07546968 0.2255086 2.7538325 +#> 43 3 5 -0.09464565 0.2255086 3.1842397 +#> 44 4 5 0.13680669 0.2255086 4.2260520 +#> 45 5 5 0.46710613 0.2255086 1.5543152 +#> 46 6 5 0.71713231 0.2255086 3.9556215 +#> 47 7 5 -0.16377959 0.2255086 3.8447343 +#> 48 8 5 -0.03648029 0.2255086 4.5385200 +#> 49 9 5 -0.44490238 0.2255086 2.6456965 +#> 50 10 5 -0.50294582 0.2255086 2.2025837 +#> 51 1 6 0.15336871 -0.5688417 3.5177725 +#> 52 2 6 -0.07546968 -0.5688417 2.9838297 +#> 53 3 6 -0.09464565 -0.5688417 3.5923231 +#> 54 4 6 0.13680669 -0.5688417 3.1022826 +#> 55 5 6 0.46710613 -0.5688417 2.7535176 +#> 56 6 6 0.71713231 -0.5688417 5.4940446 +#> 57 7 6 -0.16377959 -0.5688417 2.5234260 +#> 58 8 6 -0.03648029 -0.5688417 0.3511046 +#> 59 9 6 -0.44490238 -0.5688417 1.8498874 +#> 60 10 6 -0.50294582 -0.5688417 3.5379786 +#> 61 1 7 0.15336871 -0.1003512 4.2409599 +#> 62 2 7 -0.07546968 -0.1003512 3.5556705 +#> 63 3 7 -0.09464565 -0.1003512 2.6899611 +#> 64 4 7 0.13680669 -0.1003512 2.0439883 +#> 65 5 7 0.46710613 -0.1003512 5.0354057 +#> 66 6 7 0.71713231 -0.1003512 3.5521496 +#> 67 7 7 -0.16377959 -0.1003512 2.3525066 +#> 68 8 7 -0.03648029 -0.1003512 3.5415480 +#> 69 9 7 -0.44490238 -0.1003512 4.1344729 +#> 70 10 7 -0.50294582 -0.1003512 2.3269392 +#> 71 1 8 0.15336871 1.6989795 6.4250556 +#> 72 2 8 -0.07546968 1.6989795 5.7450023 +#> 73 3 8 -0.09464565 1.6989795 3.8872425 +#> 74 4 8 0.13680669 1.6989795 4.5973502 +#> 75 5 8 0.46710613 1.6989795 5.7349937 +#> 76 6 8 0.71713231 1.6989795 2.6852695 +#> 77 7 8 -0.16377959 1.6989795 3.7919020 +#> 78 8 8 -0.03648029 1.6989795 4.7810577 +#> 79 9 8 -0.44490238 1.6989795 5.1999969 +#> 80 10 8 -0.50294582 1.6989795 5.4375538 +#> 81 1 9 0.15336871 1.2452224 5.3180720 +#> 82 2 9 -0.07546968 1.2452224 2.7003936 +#> 83 3 9 -0.09464565 1.2452224 4.3759073 +#> 84 4 9 0.13680669 1.2452224 6.5338902 +#> 85 5 9 0.46710613 1.2452224 3.8544295 +#> 86 6 9 0.71713231 1.2452224 5.2503336 +#> 87 7 9 -0.16377959 1.2452224 4.6527757 +#> 88 8 9 -0.03648029 1.2452224 3.6883031 +#> 89 9 9 -0.44490238 1.2452224 2.8378979 +#> 90 10 9 -0.50294582 1.2452224 4.8626384 +#> 91 1 10 0.15336871 -0.2064970 4.7460439 +#> 92 2 10 -0.07546968 -0.2064970 1.8389187 +#> 93 3 10 -0.09464565 -0.2064970 1.3021962 +#> 94 4 10 0.13680669 -0.2064970 2.4226626 +#> 95 5 10 0.46710613 -0.2064970 3.0711292 +#> 96 6 10 0.71713231 -0.2064970 2.2198113 +#> 97 7 10 -0.16377959 -0.2064970 0.9575364 +#> 98 8 10 -0.03648029 -0.2064970 2.6135275 +#> 99 9 10 -0.44490238 -0.2064970 1.2924662 +#> 100 10 10 -0.50294582 -0.2064970 0.8947152
-
wide2long(dat, within_factors = c(), within_cols = c(),
+    
wide2long(.data, within_factors = c(), within_cols = c(),
   sep = "[^[:alnum:]]+")

Arguments

dat

the existing dataframe

.data

the existing tbl

sub_n
- - + + - - + + - - + + - - + +
dat

the wide data frame to convert

.data

the tbl in wide format

sep

Separator between columns (see tidyr::separate)

within_factors

the names of the within factors

within

the names of the within factors

within_cols

the names (or indices) of the within-subject (value) columns

dv

the names of the DV (value) columns

sep

Separator for within-columns (see tidyr::separate)

Value

-

the data frame in long format

+

a tbl in long format

+

Examples

+
wide2long(iris, c("Feature", "Measure"), 1:4)
#> Species Feature Measure val +#> 1 setosa Sepal Length 5.1 +#> 2 setosa Sepal Length 4.9 +#> 3 setosa Sepal Length 4.7 +#> 4 setosa Sepal Length 4.6 +#> 5 setosa Sepal Length 5.0 +#> 6 setosa Sepal Length 5.4 +#> 7 setosa Sepal Length 4.6 +#> 8 setosa Sepal Length 5.0 +#> 9 setosa Sepal Length 4.4 +#> 10 setosa Sepal Length 4.9 +#> 11 setosa Sepal Length 5.4 +#> 12 setosa Sepal Length 4.8 +#> 13 setosa Sepal Length 4.8 +#> 14 setosa Sepal Length 4.3 +#> 15 setosa Sepal Length 5.8 +#> 16 setosa Sepal Length 5.7 +#> 17 setosa Sepal Length 5.4 +#> 18 setosa Sepal Length 5.1 +#> 19 setosa Sepal Length 5.7 +#> 20 setosa Sepal Length 5.1 +#> 21 setosa Sepal Length 5.4 +#> 22 setosa Sepal Length 5.1 +#> 23 setosa Sepal Length 4.6 +#> 24 setosa Sepal Length 5.1 +#> 25 setosa Sepal Length 4.8 +#> 26 setosa Sepal Length 5.0 +#> 27 setosa Sepal Length 5.0 +#> 28 setosa Sepal Length 5.2 +#> 29 setosa Sepal Length 5.2 +#> 30 setosa Sepal Length 4.7 +#> 31 setosa Sepal Length 4.8 +#> 32 setosa Sepal Length 5.4 +#> 33 setosa Sepal Length 5.2 +#> 34 setosa Sepal Length 5.5 +#> 35 setosa Sepal Length 4.9 +#> 36 setosa Sepal Length 5.0 +#> 37 setosa Sepal Length 5.5 +#> 38 setosa Sepal Length 4.9 +#> 39 setosa Sepal Length 4.4 +#> 40 setosa Sepal Length 5.1 +#> 41 setosa Sepal Length 5.0 +#> 42 setosa Sepal Length 4.5 +#> 43 setosa Sepal Length 4.4 +#> 44 setosa Sepal Length 5.0 +#> 45 setosa Sepal Length 5.1 +#> 46 setosa Sepal Length 4.8 +#> 47 setosa Sepal Length 5.1 +#> 48 setosa Sepal Length 4.6 +#> 49 setosa Sepal Length 5.3 +#> 50 setosa Sepal Length 5.0 +#> 51 versicolor Sepal Length 7.0 +#> 52 versicolor Sepal Length 6.4 +#> 53 versicolor Sepal Length 6.9 +#> 54 versicolor Sepal Length 5.5 +#> 55 versicolor Sepal Length 6.5 +#> 56 versicolor Sepal Length 5.7 +#> 57 versicolor Sepal Length 6.3 +#> 58 versicolor Sepal Length 4.9 +#> 59 versicolor Sepal Length 6.6 +#> 60 versicolor Sepal Length 5.2 +#> 61 versicolor Sepal Length 5.0 +#> 62 versicolor Sepal Length 5.9 +#> 63 versicolor Sepal Length 6.0 +#> 64 versicolor Sepal Length 6.1 +#> 65 versicolor Sepal Length 5.6 +#> 66 versicolor Sepal Length 6.7 +#> 67 versicolor Sepal Length 5.6 +#> 68 versicolor Sepal Length 5.8 +#> 69 versicolor Sepal Length 6.2 +#> 70 versicolor Sepal Length 5.6 +#> 71 versicolor Sepal Length 5.9 +#> 72 versicolor Sepal Length 6.1 +#> 73 versicolor Sepal Length 6.3 +#> 74 versicolor Sepal Length 6.1 +#> 75 versicolor Sepal Length 6.4 +#> 76 versicolor Sepal Length 6.6 +#> 77 versicolor Sepal Length 6.8 +#> 78 versicolor Sepal Length 6.7 +#> 79 versicolor Sepal Length 6.0 +#> 80 versicolor Sepal Length 5.7 +#> 81 versicolor Sepal Length 5.5 +#> 82 versicolor Sepal Length 5.5 +#> 83 versicolor Sepal Length 5.8 +#> 84 versicolor Sepal Length 6.0 +#> 85 versicolor Sepal Length 5.4 +#> 86 versicolor Sepal Length 6.0 +#> 87 versicolor Sepal Length 6.7 +#> 88 versicolor Sepal Length 6.3 +#> 89 versicolor Sepal Length 5.6 +#> 90 versicolor Sepal Length 5.5 +#> 91 versicolor Sepal Length 5.5 +#> 92 versicolor Sepal Length 6.1 +#> 93 versicolor Sepal Length 5.8 +#> 94 versicolor Sepal Length 5.0 +#> 95 versicolor Sepal Length 5.6 +#> 96 versicolor Sepal Length 5.7 +#> 97 versicolor Sepal Length 5.7 +#> 98 versicolor Sepal Length 6.2 +#> 99 versicolor Sepal Length 5.1 +#> 100 versicolor Sepal Length 5.7 +#> 101 virginica Sepal Length 6.3 +#> 102 virginica Sepal Length 5.8 +#> 103 virginica Sepal Length 7.1 +#> 104 virginica Sepal Length 6.3 +#> 105 virginica Sepal Length 6.5 +#> 106 virginica Sepal Length 7.6 +#> 107 virginica Sepal Length 4.9 +#> 108 virginica Sepal Length 7.3 +#> 109 virginica Sepal Length 6.7 +#> 110 virginica Sepal Length 7.2 +#> 111 virginica Sepal Length 6.5 +#> 112 virginica Sepal Length 6.4 +#> 113 virginica Sepal Length 6.8 +#> 114 virginica Sepal Length 5.7 +#> 115 virginica Sepal Length 5.8 +#> 116 virginica Sepal Length 6.4 +#> 117 virginica Sepal Length 6.5 +#> 118 virginica Sepal Length 7.7 +#> 119 virginica Sepal Length 7.7 +#> 120 virginica Sepal Length 6.0 +#> 121 virginica Sepal Length 6.9 +#> 122 virginica Sepal Length 5.6 +#> 123 virginica Sepal Length 7.7 +#> 124 virginica Sepal Length 6.3 +#> 125 virginica Sepal Length 6.7 +#> 126 virginica Sepal Length 7.2 +#> 127 virginica Sepal Length 6.2 +#> 128 virginica Sepal Length 6.1 +#> 129 virginica Sepal Length 6.4 +#> 130 virginica Sepal Length 7.2 +#> 131 virginica Sepal Length 7.4 +#> 132 virginica Sepal Length 7.9 +#> 133 virginica Sepal Length 6.4 +#> 134 virginica Sepal Length 6.3 +#> 135 virginica Sepal Length 6.1 +#> 136 virginica Sepal Length 7.7 +#> 137 virginica Sepal Length 6.3 +#> 138 virginica Sepal Length 6.4 +#> 139 virginica Sepal Length 6.0 +#> 140 virginica Sepal Length 6.9 +#> 141 virginica Sepal Length 6.7 +#> 142 virginica Sepal Length 6.9 +#> 143 virginica Sepal Length 5.8 +#> 144 virginica Sepal Length 6.8 +#> 145 virginica Sepal Length 6.7 +#> 146 virginica Sepal Length 6.7 +#> 147 virginica Sepal Length 6.3 +#> 148 virginica Sepal Length 6.5 +#> 149 virginica Sepal Length 6.2 +#> 150 virginica Sepal Length 5.9 +#> 151 setosa Sepal Width 3.5 +#> 152 setosa Sepal Width 3.0 +#> 153 setosa Sepal Width 3.2 +#> 154 setosa Sepal Width 3.1 +#> 155 setosa Sepal Width 3.6 +#> 156 setosa Sepal Width 3.9 +#> 157 setosa Sepal Width 3.4 +#> 158 setosa Sepal Width 3.4 +#> 159 setosa Sepal Width 2.9 +#> 160 setosa Sepal Width 3.1 +#> 161 setosa Sepal Width 3.7 +#> 162 setosa Sepal Width 3.4 +#> 163 setosa Sepal Width 3.0 +#> 164 setosa Sepal Width 3.0 +#> 165 setosa Sepal Width 4.0 +#> 166 setosa Sepal Width 4.4 +#> 167 setosa Sepal Width 3.9 +#> 168 setosa Sepal Width 3.5 +#> 169 setosa Sepal Width 3.8 +#> 170 setosa Sepal Width 3.8 +#> 171 setosa Sepal Width 3.4 +#> 172 setosa Sepal Width 3.7 +#> 173 setosa Sepal Width 3.6 +#> 174 setosa Sepal Width 3.3 +#> 175 setosa Sepal Width 3.4 +#> 176 setosa Sepal Width 3.0 +#> 177 setosa Sepal Width 3.4 +#> 178 setosa Sepal Width 3.5 +#> 179 setosa Sepal Width 3.4 +#> 180 setosa Sepal Width 3.2 +#> 181 setosa Sepal Width 3.1 +#> 182 setosa Sepal Width 3.4 +#> 183 setosa Sepal Width 4.1 +#> 184 setosa Sepal Width 4.2 +#> 185 setosa Sepal Width 3.1 +#> 186 setosa Sepal Width 3.2 +#> 187 setosa Sepal Width 3.5 +#> 188 setosa Sepal Width 3.6 +#> 189 setosa Sepal Width 3.0 +#> 190 setosa Sepal Width 3.4 +#> 191 setosa Sepal Width 3.5 +#> 192 setosa Sepal Width 2.3 +#> 193 setosa Sepal Width 3.2 +#> 194 setosa Sepal Width 3.5 +#> 195 setosa Sepal Width 3.8 +#> 196 setosa Sepal Width 3.0 +#> 197 setosa Sepal Width 3.8 +#> 198 setosa Sepal Width 3.2 +#> 199 setosa Sepal Width 3.7 +#> 200 setosa Sepal Width 3.3 +#> 201 versicolor Sepal Width 3.2 +#> 202 versicolor Sepal Width 3.2 +#> 203 versicolor Sepal Width 3.1 +#> 204 versicolor Sepal Width 2.3 +#> 205 versicolor Sepal Width 2.8 +#> 206 versicolor Sepal Width 2.8 +#> 207 versicolor Sepal Width 3.3 +#> 208 versicolor Sepal Width 2.4 +#> 209 versicolor Sepal Width 2.9 +#> 210 versicolor Sepal Width 2.7 +#> 211 versicolor Sepal Width 2.0 +#> 212 versicolor Sepal Width 3.0 +#> 213 versicolor Sepal Width 2.2 +#> 214 versicolor Sepal Width 2.9 +#> 215 versicolor Sepal Width 2.9 +#> 216 versicolor Sepal Width 3.1 +#> 217 versicolor Sepal Width 3.0 +#> 218 versicolor Sepal Width 2.7 +#> 219 versicolor Sepal Width 2.2 +#> 220 versicolor Sepal Width 2.5 +#> 221 versicolor Sepal Width 3.2 +#> 222 versicolor Sepal Width 2.8 +#> 223 versicolor Sepal Width 2.5 +#> 224 versicolor Sepal Width 2.8 +#> 225 versicolor Sepal Width 2.9 +#> 226 versicolor Sepal Width 3.0 +#> 227 versicolor Sepal Width 2.8 +#> 228 versicolor Sepal Width 3.0 +#> 229 versicolor Sepal Width 2.9 +#> 230 versicolor Sepal Width 2.6 +#> 231 versicolor Sepal Width 2.4 +#> 232 versicolor Sepal Width 2.4 +#> 233 versicolor Sepal Width 2.7 +#> 234 versicolor Sepal Width 2.7 +#> 235 versicolor Sepal Width 3.0 +#> 236 versicolor Sepal Width 3.4 +#> 237 versicolor Sepal Width 3.1 +#> 238 versicolor Sepal Width 2.3 +#> 239 versicolor Sepal Width 3.0 +#> 240 versicolor Sepal Width 2.5 +#> 241 versicolor Sepal Width 2.6 +#> 242 versicolor Sepal Width 3.0 +#> 243 versicolor Sepal Width 2.6 +#> 244 versicolor Sepal Width 2.3 +#> 245 versicolor Sepal Width 2.7 +#> 246 versicolor Sepal Width 3.0 +#> 247 versicolor Sepal Width 2.9 +#> 248 versicolor Sepal Width 2.9 +#> 249 versicolor Sepal Width 2.5 +#> 250 versicolor Sepal Width 2.8 +#> [ reached 'max' / getOption("max.print") -- omitted 350 rows ]
+
diff --git a/man/check_design.Rd b/man/check_design.Rd index f8bd5fad..140a0c8e 100644 --- a/man/check_design.Rd +++ b/man/check_design.Rd @@ -30,6 +30,6 @@ list within <- list(time = c("day", "night")) between <- list(pet = c("dog", "cat")) -design <- check_design(within, between) +check_design(within, between) } diff --git a/man/check_sim_stats.Rd b/man/check_sim_stats.Rd index 5c5e2e2a..88c46544 100644 --- a/man/check_sim_stats.Rd +++ b/man/check_sim_stats.Rd @@ -4,11 +4,11 @@ \alias{check_sim_stats} \title{Check table stats} \usage{ -check_sim_stats(dat, between = c(), within = c(), dv = c(), +check_sim_stats(.data, between = c(), within = c(), dv = c(), id = c(), digits = 2, usekable = FALSE) } \arguments{ -\item{dat}{the existing dataframe} +\item{.data}{the existing tbl} \item{between}{a vector of column names for between-subject factors} @@ -23,7 +23,7 @@ check_sim_stats(dat, between = c(), within = c(), dv = c(), \item{usekable}{logical. If TRUE, output with knitr::kable} } \value{ -tibble or kable +a tbl or kable } \description{ \code{check_sim_stats} Generates a table of the correlations and means of numeric columns in a data frame diff --git a/man/get_design_long.Rd b/man/get_design_long.Rd new file mode 100644 index 00000000..9560b4ae --- /dev/null +++ b/man/get_design_long.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/check_design.R +\name{get_design_long} +\alias{get_design_long} +\title{Get design from long data} +\usage{ +get_design_long(.data, id = "sub_id", dv = "val") +} +\arguments{ +\item{.data}{the data frame (in long format)} + +\item{id}{the column name(s) that identify a unit of analysis} + +\item{dv}{the column name that identifies the DV} +} +\value{ +the data frame in long format +} +\description{ +Makes a best guess at the design of a long-format data frame. +Finds all columns that contain a single value per unit of analysis (between factors), +all columns that contain the same values per unit of analysis (within factors), and +all columns that differ over units of analysis (dv, continuous factors) +} diff --git a/man/long2wide.Rd b/man/long2wide.Rd index a567b147..717b59a3 100644 --- a/man/long2wide.Rd +++ b/man/long2wide.Rd @@ -4,10 +4,11 @@ \alias{long2wide} \title{Long to wide format} \usage{ -long2wide(dat, within = c(), between = c(), dv = c(), id = c()) +long2wide(.data, within = c(), between = c(), dv = "val", + id = "sub_id") } \arguments{ -\item{dat}{the long data frame to convert} +\item{.data}{the tbl in long format} \item{within}{the names of the within column(s)} @@ -18,8 +19,13 @@ long2wide(dat, within = c(), between = c(), dv = c(), id = c()) \item{id}{the names of the column(s) for grouping observations} } \value{ -the data frame in wide format +a tbl in wide format } \description{ Converts data from long format to wide } +\examples{ +df_long <- sim_design(2, 2, long = TRUE) +long2wide(df_long, "A", "B", "val", "sub_id") + +} diff --git a/man/make_id.Rd b/man/make_id.Rd index 8678d9d6..55894a0e 100644 --- a/man/make_id.Rd +++ b/man/make_id.Rd @@ -4,12 +4,14 @@ \alias{make_id} \title{Make ID} \usage{ -make_id(n = 100, prefix = "S") +make_id(n = 100, prefix = "S", digits = 0) } \arguments{ -\item{n}{the number of IDs to generate} +\item{n}{the number of IDs to generate (or a vector of numbers)} \item{prefix}{the letter prefix to the number} + +\item{digits}{the number of digits to use for the numeric part. Only used if this is larger than the number of digits in n.} } \value{ a vector of IDs @@ -20,5 +22,6 @@ Make IDs with fixed length and a letter prefix for random effects (e.g., S001, S \examples{ make_id(20, "SUBJECT_") +make_id(10:30, digits = 3) } diff --git a/man/rnorm_multi.Rd b/man/rnorm_multi.Rd index 63000d3e..b1a8ef80 100644 --- a/man/rnorm_multi.Rd +++ b/man/rnorm_multi.Rd @@ -27,12 +27,13 @@ rnorm_multi(n, vars = 3, mu = 0, sd = 1, r = 0, varnames = NULL, \item{cors}{(deprecated; use r)} } \value{ -dataframe of vars vectors +a tbl of vars vectors } \description{ -\code{rnorm_multi} makes multiple normally distributed vectors with specified relationships +\code{rnorm_multi()} makes multiple normally distributed vectors with specified relationships. } \examples{ -rnorm_multi(100, 3, c(0.2, 0.4, 0.5), varnames=c("A", "B", "C")) -rnorm_multi(100, 3, c(1, 0.2, -0.5, 0.2, 1, 0.5, -0.5, 0.5, 1), varnames=c("A", "B", "C")) +rnorm_multi(100, 3, 0, 1, c(0.2, 0.4, 0.5), varnames=c("A", "B", "C")) +rnorm_multi(100, 3, 0, 1, c(1, 0.2, -0.5, 0.2, 1, 0.5, -0.5, 0.5, 1), varnames=c("A", "B", "C")) + } diff --git a/man/select_num_grp.Rd b/man/select_num_grp.Rd index ee801214..3831209a 100644 --- a/man/select_num_grp.Rd +++ b/man/select_num_grp.Rd @@ -4,17 +4,17 @@ \alias{select_num_grp} \title{Select grouping and numeric columns and group} \usage{ -select_num_grp(dat, between = c(), cols = NULL) +select_num_grp(.data, between = c(), cols = NULL) } \arguments{ -\item{dat}{the existing dataframe} +\item{.data}{the existing tbl} \item{between}{an optional list of column names to group by} \item{cols}{an optional list of column names to return (default of NULL returns all numeric columns)} } \value{ -tibble +a tbl } \description{ \code{select_num_grp} Select grouping and (optionally specified) numeric columns and group diff --git a/man/sim_design.Rd b/man/sim_design.Rd index 1127b4a9..4d88a826 100644 --- a/man/sim_design.Rd +++ b/man/sim_design.Rd @@ -5,7 +5,7 @@ \title{Simulate Data from Design} \usage{ sim_design(within = list(), between = list(), n = 100, mu = 0, - sd = 1, r = 0, empirical = FALSE, frame_long = FALSE) + sd = 1, r = 0, empirical = FALSE, long = FALSE) } \arguments{ \item{within}{a list of the within-subject factors} @@ -22,11 +22,11 @@ sim_design(within = list(), between = list(), n = 100, mu = 0, \item{empirical}{logical. If true, mu, sd and r specify the empirical not population mean, sd and covariance} -\item{frame_long}{Whether the returned dataframe is in wide (default = FALSE) or long (TRUE) format} +\item{long}{Whether the returned tbl is in wide (default = FALSE) or long (TRUE) format} } \value{ -dataframe +a tbl } \description{ -\code{sim_design} generates a dataframe with a specified within and between design +\code{sim_design()} generates a data table with a specified within and between design. } diff --git a/man/sim_design_.Rd b/man/sim_design_.Rd index 92b7ff67..b27f96ac 100644 --- a/man/sim_design_.Rd +++ b/man/sim_design_.Rd @@ -4,19 +4,19 @@ \alias{sim_design_} \title{Simulate Data from Design} \usage{ -sim_design_(design, empirical = FALSE, frame_long = FALSE) +sim_design_(design, empirical = FALSE, long = FALSE) } \arguments{ \item{design}{A list of design parameters created by check_design()} \item{empirical}{logical. If true, mu, sd and r specify the empirical not population mean, sd and covariance} -\item{frame_long}{Whether the returned dataframe is in wide (default = FALSE) or long (TRUE) format} +\item{long}{Whether the returned tbl is in wide (default = FALSE) or long (TRUE) format} } \value{ -dataframe +a tbl } \description{ -\code{sim_design_} generates a dataframe with a specified design +\code{sim_design_} generates a data table with a specified design } \keyword{internal} diff --git a/man/sim_df.Rd b/man/sim_df.Rd index 6a2de59b..ef95ffc0 100644 --- a/man/sim_df.Rd +++ b/man/sim_df.Rd @@ -4,11 +4,11 @@ \alias{sim_df} \title{Simulate an existing dataframe} \usage{ -sim_df(dat, n = 100, between = c(), empirical = FALSE, +sim_df(.data, n = 100, between = c(), empirical = FALSE, grp_by = NULL) } \arguments{ -\item{dat}{the existing dataframe (must be in wide format)} +\item{.data}{the existing tbl (must be in wide format)} \item{n}{the number of samples to return per group} @@ -19,10 +19,10 @@ sim_df(dat, n = 100, between = c(), empirical = FALSE, \item{grp_by}{(deprecated; use between)} } \value{ -tibble +a tbl } \description{ -\code{sim_df} Produces a dataframe with the same distributions and correlations as an existing dataframe. Only returns numeric columns and simulates all numeric variables from a continuous normal distribution (for now). +\code{sim_df} Produces a data table with the same distributions and correlations as an existing data table Only returns numeric columns and simulates all numeric variables from a continuous normal distribution (for now). } \examples{ iris100 <- sim_df(iris, 100) diff --git a/man/sim_mixed_df.Rd b/man/sim_mixed_df.Rd index d63ba25b..6b4d73de 100644 --- a/man/sim_mixed_df.Rd +++ b/man/sim_mixed_df.Rd @@ -4,11 +4,11 @@ \alias{sim_mixed_df} \title{Generate a sample with random intercepts for subjects and items} \usage{ -sim_mixed_df(dat, sub_n = 100, item_n = 25, dv = 1, sub_id = 2, +sim_mixed_df(.data, sub_n = 100, item_n = 25, dv = 1, sub_id = 2, item_id = 3) } \arguments{ -\item{dat}{the existing dataframe} +\item{.data}{the existing tbl} \item{sub_n}{the number of subjects to simulate} @@ -21,10 +21,10 @@ sim_mixed_df(dat, sub_n = 100, item_n = 25, dv = 1, sub_id = 2, \item{item_id}{the column name or index for the item IDs} } \value{ -tibble +a tbl } \description{ -\code{sim_mixed_df} Produces a dataframe with the same distributions of by-subject and by-item random intercepts as an existing dataframe +\code{sim_mixed_df()} produces a data table with the same distributions of by-subject and by-item random intercepts as an existing data table. } \examples{ \donttest{sim_mixed_df(faceratings, 10, 10, "rating", "rater_id", "face_id")} diff --git a/man/wide2long.Rd b/man/wide2long.Rd index e461d709..0574bb41 100644 --- a/man/wide2long.Rd +++ b/man/wide2long.Rd @@ -4,21 +4,25 @@ \alias{wide2long} \title{Wide to long format} \usage{ -wide2long(dat, within_factors = c(), within_cols = c(), +wide2long(.data, within_factors = c(), within_cols = c(), sep = "[^[:alnum:]]+") } \arguments{ -\item{dat}{the wide data frame to convert} +\item{.data}{the tbl in wide format} -\item{sep}{Separator between columns (see tidyr::separate)} +\item{within_factors}{the names of the within factors} -\item{within}{the names of the within factors} +\item{within_cols}{the names (or indices) of the within-subject (value) columns} -\item{dv}{the names of the DV (value) columns} +\item{sep}{Separator for within-columns (see tidyr::separate)} } \value{ -the data frame in long format +a tbl in long format } \description{ Converts data from wide format to long } +\examples{ +wide2long(iris, c("Feature", "Measure"), 1:4) + +} diff --git a/tests/testthat/test-check_design.R b/tests/testthat/test-check_design.R index 19389732..d0e7906c 100644 --- a/tests/testthat/test-check_design.R +++ b/tests/testthat/test-check_design.R @@ -1,5 +1,6 @@ context("test-check_design") +# basic ---- test_that("basic", { within <- list(time = c("day", "night")) between <- list(pet = c("dog", "cat")) @@ -13,20 +14,21 @@ test_that("basic", { magrittr::set_rownames(c("day", "night")) - testthat::expect_equal(design$within, within) - testthat::expect_equal(design$between, between) - testthat::expect_equal(design$within_labels, list(time = c(day = "day", night = "night"))) - testthat::expect_equal(design$between_labels, list(pet = c(dog = "dog", cat = "cat"))) + expect_equal(design$within, within) + expect_equal(design$between, between) + expect_equal(design$within_labels, list(time = c(day = "day", night = "night"))) + expect_equal(design$between_labels, list(pet = c(dog = "dog", cat = "cat"))) - testthat::expect_equal(design$cell_n, cell_n) - testthat::expect_equal(design$cell_mu, cell_mu) - testthat::expect_equal(design$cell_sd, cell_sd) + expect_equal(design$cell_n, cell_n) + expect_equal(design$cell_mu, cell_mu) + expect_equal(design$cell_sd, cell_sd) - testthat::expect_equal(design$cells_w, c("day", "night")) - testthat::expect_equal(design$cells_b, c("dog", "cat")) - testthat::expect_equal(design$sub_id, c(paste0("S0", 1:9), paste0("S", 10:20))) + expect_equal(design$cells_w, c("day", "night")) + expect_equal(design$cells_b, c("dog", "cat")) + expect_equal(design$sub_id, c(paste0("S0", 1:9), paste0("S", 10:20))) }) +# design spec ---- test_that("design spec", { between <- list( "B" = c("B1", "B2") @@ -54,12 +56,13 @@ test_that("design spec", { design <- check_design(within, between, n, mu, sd, r) design_elements <- c("within", "between", "within_factors", "between_factors", - "within_labels", "between_labels", "cell_n", "cell_mu", "cell_sd", - "cell_r", "cells_w", "cells_b", "sub_id") + "within_labels", "between_labels", "cells_w", "cells_b", + "cell_n", "cell_mu", "cell_sd", "cell_r", "sub_id") expect_equal(names(design), design_elements) }) +# anon factors ---- test_that("anon factors", { design <- check_design(c(2, 4), c(2, 2)) @@ -77,6 +80,7 @@ test_that("anon factors", { expect_equal(design$between, b) }) +# make_id ---- test_that("make_id", { expect_equal(make_id(10), c("S01", "S02", "S03", "S04", "S05", "S06", "S07", "S08", "S09", "S10")) @@ -87,4 +91,13 @@ test_that("make_id", { expect_equal(make_id(100)[[1]], "S001") expect_equal(make_id(1000)[[1]], "S0001") expect_equal(make_id(1000, "pokemon_")[[1]], "pokemon_0001") + expect_equal(make_id(100, digits = 4)[[1]], "S0001") + + # named arguments + expect_equal(make_id(n = 100, prefix = "A", digits = 4)[[1]], "A0001") + expect_equal(make_id(digits = 4, prefix = "A", n = 100)[[1]], "A0001") + + # vector + expect_equal(make_id(2:4), c("S2", "S3", "S4")) + expect_equal(make_id(100:200)[[1]], "S100") }) diff --git a/tests/testthat/test-check_sim_stats.R b/tests/testthat/test-check_sim_stats.R index d511c721..bd48d53b 100644 --- a/tests/testthat/test-check_sim_stats.R +++ b/tests/testthat/test-check_sim_stats.R @@ -1,11 +1,13 @@ context("check_sim_stats") +# error messages ---- test_that("error messages", { - expect_error(check_sim_stats("A"), "dat must be a data frame or matrix") + expect_error(check_sim_stats("A"), ".data must be a data frame or matrix") expect_error(check_sim_stats(iris, FALSE), "between must be a numeric or character vector") }) -test_that("correct defaults", { +# defaults ---- +test_that("defaults", { checkiris <- check_sim_stats(iris) irisnames <- c("n", "var", "Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width", "mean", "sd") @@ -14,7 +16,8 @@ test_that("correct defaults", { expect_equal(names(checkiris), irisnames) }) -test_that("correct defaults with group", { +# defaults with between ---- +test_that("defaults with between", { checkiris <- check_sim_stats(iris, "Species") irisnames <- c("Species", "n", "var", "Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width", "mean", "sd") @@ -23,6 +26,7 @@ test_that("correct defaults with group", { expect_equal(names(checkiris), irisnames) }) +# is_pos_def ---- test_that("is_pos_def", { expect_equal(is_pos_def(matrix(c(1, .5, .5, 1), 2)), TRUE) @@ -33,29 +37,33 @@ test_that("is_pos_def", { }) -test_that("long", { - df_long <- sim_design(2, 2, frame_long = TRUE) - df_wide <- long2wide(df_long, "A", "B", "val", "sub_id") +# get_design_long ---- +test_that("get_design_long", { + df_long <- sim_design(2, 2, n = 10, mu = 5, sd = 2, r = 0.5, long = TRUE, empirical = TRUE) + d <- get_design_long(df_long) - expect_equal(names(df_wide), c("sub_id", "B", "A1", "A2")) - expect_equal(nrow(df_wide), 200) + n <- data.frame(A1 = c(10, 10), A2 = c(10, 10), row.names = c("B1", "B2")) + mu <- data.frame(A1 = c(5, 5), A2 = c(5, 5), row.names = c("B1", "B2")) + sd <- data.frame(A1 = c(2, 2), A2 = c(2, 2), row.names = c("B1", "B2")) + r <- data.frame(A1 = c(1, .5), A2 = c(.5, 1), row.names = c("A1", "A2")) - iris_long <- iris %>% - dplyr::mutate(id = make_id(nrow(.), "I")) %>% - tidyr::gather(var, val, Sepal.Length:Petal.Width) %>% - tidyr::separate(var, c("Feature", "Measure")) - - iris_wide <- long2wide(iris_long, within = c("Feature", "Measure"), - between = "Species", dv = "val", id = "id") - inames <- c("id", "Species", "Petal_Length", "Petal_Width", "Sepal_Length", "Sepal_Width") - testthat::expect_equal(names(iris_wide), inames) - testthat::expect_equal(nrow(iris_wide), 150) - - long <- check_sim_stats(iris_long, within = c("Feature", "Measure"), - between = "Species", dv = "val", id = "id") - - wide <- check_sim_stats(iris, between = "Species") + expect_equal(d$within, list(A = c("A1", "A2"))) + expect_equal(d$between, list(B = c("B1", "B2"))) + expect_equal(d$within_factors, "A") + expect_equal(d$between_factors, "B") + expect_equal(d$cell_n, n) + expect_equal(d$cell_mu, mu) + expect_equal(d$cell_sd, sd) + expect_equal(d$cell_r$B1, r) + expect_equal(d$cell_r$B2, r) + df_long <- sim_design(c(2, 2, 2), c(2, 2, 2), long = TRUE, empirical = TRUE) + d <- get_design_long(df_long) - testthat::expect_equal(nrow(long), nrow(wide)) + expect_equal(d$within_factors, c("A", "B", "C")) + expect_equal(d$between_factors, c("D", "E", "F")) + expect_equal(d$cell_n %>% sum(), 6400) + expect_equal(d$cell_mu %>% sum(), 0) + expect_equal(d$cell_sd %>% sum(), 64) + expect_equal(d$cell_r[[1]] %>% sum(), 8) }) diff --git a/tests/testthat/test-long2wide.R b/tests/testthat/test-long2wide.R new file mode 100644 index 00000000..9932d1f5 --- /dev/null +++ b/tests/testthat/test-long2wide.R @@ -0,0 +1,51 @@ +context("long2wide") + +# 2w*2b ---- +test_that("2w*2b", { + df_long <- sim_design(2, 2, long = TRUE) + df_wide <- long2wide(df_long, "A", "B", "val", "sub_id") + + expect_equal(names(df_wide), c("sub_id", "B", "A1", "A2")) + expect_equal(nrow(df_wide), 200) +}) + +# named arguments ---- +test_that("named arguments", { + df_long <- sim_design(2, 2, long = TRUE) + df_wide <- long2wide(dv = "val", id = "sub_id", .data = df_long, between = "B", within = "A") + + expect_equal(names(df_wide), c("sub_id", "B", "A1", "A2")) + expect_equal(nrow(df_wide), 200) +}) + +# 2w*2w*2b*2b ---- +test_that("2w*2w*2b*2b", { + df_long <- sim_design(c(2, 2), c(2, 2), long = TRUE) + df_wide <- long2wide(df_long, c("A", "B"), c("C","D"), "val", "sub_id") + + expect_equal(names(df_wide), c("sub_id", "C", "D", "A1_B1", "A1_B2", "A2_B1", "A2_B2")) + expect_equal(nrow(df_wide), 400) +}) + + +# iris ---- +test_that("iris", { + iris_long <- iris %>% + dplyr::mutate(id = make_id(nrow(.), "I")) %>% + tidyr::gather(var, val, Sepal.Length:Petal.Width) %>% + tidyr::separate(var, c("Feature", "Measure")) + + iris_wide <- long2wide(iris_long, within = c("Feature", "Measure"), + between = "Species", dv = "val", id = "id") + inames <- c("id", "Species", "Petal_Length", "Petal_Width", "Sepal_Length", "Sepal_Width") + expect_equal(names(iris_wide), inames) + expect_equal(nrow(iris_wide), 150) + + long <- check_sim_stats(iris_long, within = c("Feature", "Measure"), + between = "Species", dv = "val", id = "id") + + wide <- check_sim_stats(iris, between = "Species") + + + expect_equal(nrow(long), nrow(wide)) +}) diff --git a/tests/testthat/test-rnorm_multi.R b/tests/testthat/test-rnorm_multi.R index 774dee07..d56d4122 100644 --- a/tests/testthat/test-rnorm_multi.R +++ b/tests/testthat/test-rnorm_multi.R @@ -56,7 +56,7 @@ test_that("correct default parameters", { dat <- rnorm_multi(n) r <- cor(dat) means <- dplyr::summarise_all(dat, mean) - sds <- dplyr::summarise_all(dat, sd) + sds <- dplyr::summarise_all(dat, stats::sd) expect_equal(nrow(dat), n) expect_equal(ncol(dat), 3) @@ -69,7 +69,7 @@ test_that("correct default parameters with empirical = TRUE", { dat <- rnorm_multi(n, empirical = TRUE) r <- cor(dat) means <- dplyr::summarise_all(dat, mean) - sds <- dplyr::summarise_all(dat, sd) + sds <- dplyr::summarise_all(dat, stats::sd) expect_equal(nrow(dat), n) expect_equal(ncol(dat), 3) diff --git a/tests/testthat/test-select_num_grp.R b/tests/testthat/test-select_num_grp.R index 53fe24a8..a8c1a7af 100644 --- a/tests/testthat/test-select_num_grp.R +++ b/tests/testthat/test-select_num_grp.R @@ -1,7 +1,7 @@ context("select_num_grp") test_that("error messages", { - expect_error(select_num_grp("A"), "dat must be a data frame or matrix") + expect_error(select_num_grp("A"), ".data must be a data frame or matrix") expect_error(select_num_grp(iris, FALSE), "between must be a numeric or character vector") }) diff --git a/tests/testthat/test-sim_df.R b/tests/testthat/test-sim_df.R index 51559cbe..6bf668e8 100644 --- a/tests/testthat/test-sim_df.R +++ b/tests/testthat/test-sim_df.R @@ -1,13 +1,15 @@ context("sim_df") +# error messages ---- test_that("error messages", { - expect_error( sim_df("A"), "dat must be a data frame or matrix" ) + expect_error( sim_df("A"), ".data must be a data frame or matrix" ) expect_error( sim_df(iris, "A"), "n must be an integer > 2" ) expect_error( sim_df(iris, 2), "n must be an integer > 2" ) expect_error( sim_df(iris, 10, FALSE), "between must be a numeric or character vector" ) }) -test_that("correct default parameters", { +# default parameters ---- +test_that("default parameters", { newdf <- sim_df(iris) expect_equal(nrow(newdf), 100) @@ -15,7 +17,8 @@ test_that("correct default parameters", { expect_equal(names(newdf), names(iris)[1:4]) }) -test_that("correct specified parameters", { +# specified parameters ---- +test_that("specified parameters", { n <- 100 dat <- tibble::as_tibble(iris) %>% dplyr::select_if(is.numeric) @@ -25,6 +28,7 @@ test_that("correct specified parameters", { sds <- dplyr::summarise_all(dat, sd) %>% as.data.frame() + # unnamed arguments in order newdf <- sim_df(iris, n, c(), TRUE) newdat <- dplyr::select_if(newdf, is.numeric) newcors <- cor(newdat) @@ -40,9 +44,28 @@ test_that("correct specified parameters", { expect_equal(cors, newcors) expect_equal(means, newmeans) expect_equal(sds, newsds) + + # named arguments out of order + newdf <- sim_df(between = c(), empirical = TRUE, .data = iris, n = n) + newdat <- dplyr::select_if(newdf, is.numeric) + newcors <- cor(newdat) + newmeans <- dplyr::summarise_all(newdat, mean) %>% + as.data.frame() + newsds <- dplyr::summarise_all(newdat, sd) %>% + as.data.frame() + + expect_equal(nrow(newdf), n) + expect_equal(ncol(newdf), 4) + expect_equal(names(newdf), names(iris)[1:4]) + + expect_equal(cors, newcors) + expect_equal(means, newmeans) + expect_equal(sds, newsds) + }) -test_that("grouping by col name", { +# grouping by name ---- +test_that("grouping by name", { newdf <- sim_df(iris, 20, "Species") expect_equal(nrow(newdf), 60) @@ -50,6 +73,7 @@ test_that("grouping by col name", { expect_equal(names(newdf) %>% sort(), names(iris) %>% sort()) }) +# grouping by col number ---- test_that("grouping by col number", { newdf <- sim_df(iris, 20, 5) diff --git a/vignettes/sim_design.Rmd b/vignettes/sim_design.Rmd index 6b0c02ab..77261c76 100644 --- a/vignettes/sim_design.Rmd +++ b/vignettes/sim_design.Rmd @@ -208,12 +208,12 @@ r <- list( ) ``` -You can set `frame_long = TRUE` to return the data frame in long format, which is usually easier for plotting. +You can set `long = TRUE` to return the data frame in long format, which is usually easier for plotting. ```{r} df <- sim_design(within, between, n = 100, mu = mu, sd = 2, r = r, - frame_long = TRUE) + long = TRUE) ```