diff --git a/DESCRIPTION b/DESCRIPTION index d470acdc..ba76ad21 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: faux Title: Simulation for Factorial Designs -Version: 0.0.1.4 -Date: 2020-08-12 +Version: 0.0.1.5 +Date: 2020-09-11 Authors@R: c( person( given = "Lisa", @@ -45,7 +45,8 @@ Suggests: ggExtra, purrr, broom, - broom.mixed + broom.mixed, + psych VignetteBuilder: knitr RoxygenNote: 7.1.1 Encoding: UTF-8 diff --git a/NAMESPACE b/NAMESPACE index f4d96c75..a3942abd 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,6 +6,7 @@ S3method(print,design) S3method(print,nested_list) S3method(print,psychds_codebook) export("%>%") +export(average_r2tau_0) export(check_design) export(check_mixed_design) export(check_sim_stats) @@ -40,6 +41,7 @@ export(sim_design) export(sim_df) export(sim_mixed_cc) export(sim_mixed_df) +export(std_alpha2average_r) export(trunc2norm) export(unif2norm) export(unique_pairs) diff --git a/NEWS.md b/NEWS.md index 3bf254b5..6446a271 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# faux 0.0.1.5 (2020-09-11) + +* Removed a test using markdown that failed on Solaris (causing faux to be pulled from CRAN) Back on CRAN! +* `seed` arguments reinstated as deprecated and produce a warning + # faux 0.0.1.4 (2020-08-12) * Even more fixes for CRAN (on CRAN from 2009-08-19!) diff --git a/R/distribution_convertors.R b/R/distribution_convertors.R index b6384cb8..94adaf38 100644 --- a/R/distribution_convertors.R +++ b/R/distribution_convertors.R @@ -240,3 +240,31 @@ norm2likert <- function(x, prob, mu = mean(x), sd = stats::sd(x)) { sapply(p, function(a) n + 1 - sum(a < cprob)) } + +#' Standardized Alpha to Average R +#' +#' @param std_alpha The standarized alpha +#' @param n The number of items +#' +#' @return The average inter-item correlation +#' @export +#' +#' @examples +#' std_alpha2average_r(.8, 10) +std_alpha2average_r <- function(std_alpha, n) { + sumR <- -n / ((std_alpha / (n/(n - 1))) - 1) + (sumR - n)/(n * (n - 1)) +} + +#' Average r to Random Intercept SD +#' +#' @param average_r The average inter-item correlation +#' @param sigma Total error variance +#' +#' @return The standard deviation of the random intercept +#' @export +#' +#' @examples +average_r2tau_0 <- function(average_r, sigma) { + sqrt((average_r * sigma^2) / (1 - average_r)) +} diff --git a/R/rnorm_multi.R b/R/rnorm_multi.R index 0176b19e..6f0bf7f4 100644 --- a/R/rnorm_multi.R +++ b/R/rnorm_multi.R @@ -10,6 +10,7 @@ #' @param varnames optional names for the variables (string vector of length vars) defaults if r is a matrix with column names #' @param empirical logical. If true, mu, sd and r specify the empirical not population mean, sd and covariance #' @param as.matrix logical. If true, returns a matrix +#' @param seed DEPRECATED use set.seed() instead #' #' @return a tbl of vars vectors #' @@ -21,11 +22,12 @@ rnorm_multi <- function(n, vars = NULL, mu = 0, sd = 1, r = 0, varnames = NULL, empirical = FALSE, - as.matrix = FALSE) { - # if (!is.null(seed)) { + as.matrix = FALSE, seed = NULL) { + if (!is.null(seed)) { + warning("The seed argument is deprecated. Please set seed using set.seed() instead") # # reinstate system seed after simulation # gs <- global_seed(); on.exit(global_seed(gs)) - # } + } # error handling ---- if ( !is.numeric(n) || n %% 1 > 0 || n < 1 ) { diff --git a/R/sim_design.R b/R/sim_design.R index 1bdeffa0..1f8a9c8d 100644 --- a/R/sim_design.R +++ b/R/sim_design.R @@ -16,6 +16,7 @@ #' @param interactive whether to run the function interactively #' @param design a design list including within, between, n, mu, sd, r, dv, id #' @param rep the number of data frames to return (default 1); if greater than 1, the returned data frame is nested by rep +#' @param seed DEPRECATED use set.seed() instead #' #' @return a tbl #' @@ -28,7 +29,7 @@ sim_design <- function(within = list(), between = list(), id = list(id = "id"), plot = faux_options("plot"), interactive = FALSE, - design = NULL, rep = 1) { + design = NULL, rep = 1, seed = NULL) { # check the design is specified correctly if (interactive) { design <- interactive_design(plot = plot) @@ -45,6 +46,10 @@ sim_design <- function(within = list(), between = list(), dv = dv, id = id, plot = plot) } + if (!is.null(seed)) { + warning("The seed argument is deprecated. Please set seed using set.seed() instead") + } + # simulate the data data <- sim_data(design, empirical = empirical, long = long, rep = rep) @@ -60,12 +65,13 @@ sim_design <- function(within = list(), between = list(), #' @param long Whether the returned tbl is in wide (default = FALSE) or long (TRUE) format #' @param rep the number of data frames to return (default 1); if greater than 1, the returned data frame is nested by rep #' @param sep separator for within-columns, defaults to _ +#' @param seed DEPRECATED use set.seed() instead #' #' @return a tbl #' @export #' sim_data <- function(design, empirical = FALSE, long = FALSE, - rep = 1, sep = faux_options("sep")) { + rep = 1, sep = faux_options("sep"), seed = NULL) { if (!is.numeric(rep)) { stop("rep must be a number") } else if (rep < 1) { @@ -74,11 +80,12 @@ sim_data <- function(design, empirical = FALSE, long = FALSE, warning("rep should be an integer") } - # if (!is.null(seed)) { + if (!is.null(seed)) { + warning("The seed argument is deprecated. Please set seed using set.seed() instead") # # reinstate system seed after simulation # gs <- global_seed(); on.exit(global_seed(gs)) # set.seed(seed, kind = "Mersenne-Twister", normal.kind = "Inversion") - # } + } # defaults within <- list() diff --git a/R/sim_df.R b/R/sim_df.R index b0b65c4a..a48e3b86 100644 --- a/R/sim_df.R +++ b/R/sim_df.R @@ -13,6 +13,7 @@ #' @param id the names of the column(s) for grouping observations #' @param empirical Should the returned data have these exact parameters? (versus be sampled from a population with these parameters) #' @param long whether to return the data table in long format +#' @param seed DEPRECATED use set.seed() instead #' #' @return a tbl #' @examples @@ -22,12 +23,13 @@ sim_df <- function (data, n = 100, within = c(), between = c(), id = "id", dv = "value", - empirical = FALSE, long = FALSE) { - # if (!is.null(seed)) { + empirical = FALSE, long = FALSE, seed = NULL) { + if (!is.null(seed)) { + warning("The seed argument is deprecated. Please set seed using set.seed() instead") # # reinstate system seed after simulation # gs <- global_seed(); on.exit(global_seed(gs)) # set.seed(seed, kind = "Mersenne-Twister", normal.kind = "Inversion") - # } + } # error checking ------ if ( !is.numeric(n) || n %% 1 > 0 || n < 3 ) { diff --git a/R/sim_mixed_cc.R b/R/sim_mixed_cc.R index 2c54865f..789fa40f 100644 --- a/R/sim_mixed_cc.R +++ b/R/sim_mixed_cc.R @@ -9,6 +9,7 @@ #' @param item_sd the SD of item random intercepts (or an item_n-length named vector of random intercepts for each item) #' @param error_sd the SD of the error term #' @param empirical Should the returned data have these exact parameters? (versus be sampled from a population with these parameters) +#' @param seed DEPRECATED use set.seed() instead #' #' @return a tbl #' @export @@ -18,12 +19,13 @@ #' sim_mixed_cc(10, 10) sim_mixed_cc <- function(sub_n = 100, item_n = 20, grand_i = 0, sub_sd = 1, item_sd = 1, error_sd = 1, - empirical = FALSE) { - # if (!is.null(seed)) { + empirical = FALSE, seed = NULL) { + if (!is.null(seed)) { + warning("The seed argument is deprecated. Please set seed using set.seed() instead") # # reinstate system seed after simulation # gs <- global_seed(); on.exit(global_seed(gs)) # set.seed(seed, kind = "Mersenne-Twister", normal.kind = "Inversion") - # } + } # sample subject random intercepts---- if (length(sub_sd) == sub_n) { diff --git a/docs/404.html b/docs/404.html index b10b9909..00d6ce6a 100644 --- a/docs/404.html +++ b/docs/404.html @@ -79,7 +79,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -102,26 +102,26 @@
  • diff --git a/docs/CODE_OF_CONDUCT.html b/docs/CODE_OF_CONDUCT.html index 1209c3cb..35751351 100644 --- a/docs/CODE_OF_CONDUCT.html +++ b/docs/CODE_OF_CONDUCT.html @@ -79,7 +79,7 @@ faux - 0.0.1.4 + 0.0.1.5 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index ce31eeec..f2729603 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -79,7 +79,7 @@ faux - 0.0.1.4 + 0.0.1.5 diff --git a/docs/LICENSE.html b/docs/LICENSE.html index a8bf8b42..79230800 100644 --- a/docs/LICENSE.html +++ b/docs/LICENSE.html @@ -79,7 +79,7 @@ faux - 0.0.1.4 + 0.0.1.5 diff --git a/docs/articles/codebook.html b/docs/articles/codebook.html index 8d1f2437..972481da 100644 --- a/docs/articles/codebook.html +++ b/docs/articles/codebook.html @@ -38,7 +38,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -61,26 +61,26 @@
  • diff --git a/docs/articles/continuous.html b/docs/articles/continuous.html index 1e49c958..7035372a 100644 --- a/docs/articles/continuous.html +++ b/docs/articles/continuous.html @@ -38,7 +38,7 @@ faux - 0.0.1.4 + 0.0.1.5 diff --git a/docs/articles/index.html b/docs/articles/index.html index a3b530f2..bc302098 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -79,7 +79,7 @@ faux - 0.0.1.4 + 0.0.1.5 diff --git a/docs/articles/plots.html b/docs/articles/plots.html index 2e6449ad..e8a47b03 100644 --- a/docs/articles/plots.html +++ b/docs/articles/plots.html @@ -38,7 +38,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -61,26 +61,26 @@
  • diff --git a/docs/articles/rnorm_multi.html b/docs/articles/rnorm_multi.html index 1bf48638..2ec6c6c8 100644 --- a/docs/articles/rnorm_multi.html +++ b/docs/articles/rnorm_multi.html @@ -38,7 +38,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -61,26 +61,26 @@
  • @@ -110,7 +110,7 @@

    Simulate Correlated Variables

    Lisa DeBruine

    -

    2020-08-12

    +

    2020-09-28

    Source: vignettes/rnorm_multi.Rmd diff --git a/docs/articles/sim_design.html b/docs/articles/sim_design.html index ca6a75fd..d09c81bd 100644 --- a/docs/articles/sim_design.html +++ b/docs/articles/sim_design.html @@ -38,7 +38,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -61,26 +61,26 @@
  • @@ -110,7 +110,7 @@

    Simulate by Design

    Lisa DeBruine

    -

    2020-08-12

    +

    2020-09-28

    Source: vignettes/sim_design.Rmd diff --git a/docs/articles/sim_df.html b/docs/articles/sim_df.html index e87f362c..f09689de 100644 --- a/docs/articles/sim_df.html +++ b/docs/articles/sim_df.html @@ -38,7 +38,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -61,26 +61,26 @@
  • @@ -110,7 +110,7 @@

    Simulate from Existing Data

    Lisa DeBruine

    -

    2020-08-12

    +

    2020-09-28

    Source: vignettes/sim_df.Rmd diff --git a/docs/articles/sim_mixed.html b/docs/articles/sim_mixed.html index 6816e91b..68cc783d 100644 --- a/docs/articles/sim_mixed.html +++ b/docs/articles/sim_mixed.html @@ -38,7 +38,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -61,26 +61,26 @@
  • diff --git a/docs/authors.html b/docs/authors.html index 3e3e8406..92df768b 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -79,7 +79,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -152,15 +152,15 @@

    Citation

    Source: inst/CITATION -

    Lisa DeBruine (2020). faux: Simulation for Factorial Designs. R package version 0.0.1.4. Zenodo. http://doi.org/10.5281/zenodo.2669586

    +

    Lisa DeBruine (2020). faux: Simulation for Factorial Designs. R package version 0.0.1.5. Zenodo. http://doi.org/10.5281/zenodo.2669586

    @Manual{,
       title = {faux: Simulation for Factorial Designs},
       author = {Lisa DeBruine},
       doi = {10.5281/zenodo.2669586},
       publisher = {Zenodo},
       year = {2020},
    -  month = {August},
    -  note = {R package version 0.0.1.4},
    +  month = {September},
    +  note = {R package version 0.0.1.5},
       url = {https://debruine.github.io/faux/},
     }
    diff --git a/docs/index.html b/docs/index.html index a39ceb04..ccd3daff 100644 --- a/docs/index.html +++ b/docs/index.html @@ -38,7 +38,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -108,10 +108,6 @@

    -
    -

    -output: github_document

    -
    @@ -152,6 +152,16 @@

    Changelog

    Source: NEWS.md
    +
    +

    +faux 0.0.1.5 (2020-09-11) 2020-09-22 +

    +
      +
    • Removed a test using markdown that failed on Solaris (causing faux to be pulled from CRAN) Back on CRAN!
    • +
    • +seed arguments reinstated as deprecated and produce a warning
    • +
    +

    faux 0.0.1.4 (2020-08-12) 2020-08-19 diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index ee07abe7..98055738 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -9,5 +9,5 @@ articles: sim_design: sim_design.html sim_df: sim_df.html sim_mixed: sim_mixed.html -last_built: 2020-08-12T09:07Z +last_built: 2020-09-28T14:49Z diff --git a/docs/reference/average_r2tau_0.html b/docs/reference/average_r2tau_0.html new file mode 100644 index 00000000..dceb5597 --- /dev/null +++ b/docs/reference/average_r2tau_0.html @@ -0,0 +1,207 @@ + + + + + + + + +Average r to Random Intercept SD — average_r2tau_0 • faux + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Average r to Random Intercept SD

    +
    + +
    average_r2tau_0(average_r, sigma)
    + +

    Arguments

    + + + + + + + + + + +
    average_r

    The average inter-item correlation

    sigma

    Total error variance

    + +

    Value

    + +

    The standard deviation of the random intercept

    + +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.5.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/cell_combos.html b/docs/reference/cell_combos.html index 35cca3d3..1ebf43fd 100644 --- a/docs/reference/cell_combos.html +++ b/docs/reference/cell_combos.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5

    @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/check_design.html b/docs/reference/check_design.html index 1b3058c4..7f1a8fc9 100644 --- a/docs/reference/check_design.html +++ b/docs/reference/check_design.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/check_mixed_design.html b/docs/reference/check_mixed_design.html index af5d0a99..d16c7e25 100644 --- a/docs/reference/check_mixed_design.html +++ b/docs/reference/check_mixed_design.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/codebook.html b/docs/reference/codebook.html index e32d4e8a..8e5ebcb7 100644 --- a/docs/reference/codebook.html +++ b/docs/reference/codebook.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/codebook_interactive.html b/docs/reference/codebook_interactive.html index b3f4f40d..906a468c 100644 --- a/docs/reference/codebook_interactive.html +++ b/docs/reference/codebook_interactive.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/convert_param.html b/docs/reference/convert_param.html index ab84c9ff..24838517 100644 --- a/docs/reference/convert_param.html +++ b/docs/reference/convert_param.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/cormat.html b/docs/reference/cormat.html index 7ab64839..d7b266a8 100644 --- a/docs/reference/cormat.html +++ b/docs/reference/cormat.html @@ -81,7 +81,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -104,26 +104,26 @@
  • diff --git a/docs/reference/cormat_from_triangle.html b/docs/reference/cormat_from_triangle.html index 634531aa..2bfaeff4 100644 --- a/docs/reference/cormat_from_triangle.html +++ b/docs/reference/cormat_from_triangle.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/faceratings.html b/docs/reference/faceratings.html index 9430f889..9268206f 100644 --- a/docs/reference/faceratings.html +++ b/docs/reference/faceratings.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/faux.html b/docs/reference/faux.html index 5f807720..cc0ab59c 100644 --- a/docs/reference/faux.html +++ b/docs/reference/faux.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/faux_options.html b/docs/reference/faux_options.html index 6380e325..b7bc1e26 100644 --- a/docs/reference/faux_options.html +++ b/docs/reference/faux_options.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/figures/get-design-long-1.png b/docs/reference/figures/get-design-long-1.png index 9d5c4431..29912e2f 100644 Binary files a/docs/reference/figures/get-design-long-1.png and b/docs/reference/figures/get-design-long-1.png differ diff --git a/docs/reference/figures/plot-design-1.png b/docs/reference/figures/plot-design-1.png index 1f7bf58c..e91706fc 100644 Binary files a/docs/reference/figures/plot-design-1.png and b/docs/reference/figures/plot-design-1.png differ diff --git a/docs/reference/figures/plot-iris-sim-1.png b/docs/reference/figures/plot-iris-sim-1.png index aec71c1b..c4313b38 100644 Binary files a/docs/reference/figures/plot-iris-sim-1.png and b/docs/reference/figures/plot-iris-sim-1.png differ diff --git a/docs/reference/figures/plot-rnorm-pre-1.png b/docs/reference/figures/plot-rnorm-pre-1.png index d9bd3d8f..3bcdc9f0 100644 Binary files a/docs/reference/figures/plot-rnorm-pre-1.png and b/docs/reference/figures/plot-rnorm-pre-1.png differ diff --git a/docs/reference/fix_name_labels.html b/docs/reference/fix_name_labels.html index 1299eb83..99a6e396 100644 --- a/docs/reference/fix_name_labels.html +++ b/docs/reference/fix_name_labels.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/fr4.html b/docs/reference/fr4.html index 2ed12334..8f87ef20 100644 --- a/docs/reference/fr4.html +++ b/docs/reference/fr4.html @@ -81,7 +81,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -104,26 +104,26 @@
  • diff --git a/docs/reference/get_design_long.html b/docs/reference/get_design_long.html index 022196a7..e18eecc0 100644 --- a/docs/reference/get_design_long.html +++ b/docs/reference/get_design_long.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/get_params.html b/docs/reference/get_params.html index 6316d2c4..e890b892 100644 --- a/docs/reference/get_params.html +++ b/docs/reference/get_params.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/index.html b/docs/reference/index.html index aa583132..bcbb9585 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -79,7 +79,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -102,26 +102,26 @@
  • @@ -411,6 +411,12 @@

    std_alpha2average_r()

    + +

    Standardized Alpha to Average R

    + +

    norm2likert()

    diff --git a/docs/reference/interactive_design.html b/docs/reference/interactive_design.html index 6bb7865c..546837fc 100644 --- a/docs/reference/interactive_design.html +++ b/docs/reference/interactive_design.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@

  • diff --git a/docs/reference/is_pos_def.html b/docs/reference/is_pos_def.html index e3c1ea11..a51fd8e7 100644 --- a/docs/reference/is_pos_def.html +++ b/docs/reference/is_pos_def.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/json_design.html b/docs/reference/json_design.html index ea4e7b68..7d8f2185 100644 --- a/docs/reference/json_design.html +++ b/docs/reference/json_design.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/long2wide.html b/docs/reference/long2wide.html index 0427c59b..84db75d5 100644 --- a/docs/reference/long2wide.html +++ b/docs/reference/long2wide.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/make_id.html b/docs/reference/make_id.html index 55bfeaa6..d54cdc76 100644 --- a/docs/reference/make_id.html +++ b/docs/reference/make_id.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/message.html b/docs/reference/message.html index f7578e17..b75dcc42 100644 --- a/docs/reference/message.html +++ b/docs/reference/message.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/messy.html b/docs/reference/messy.html index 536f8421..13707300 100644 --- a/docs/reference/messy.html +++ b/docs/reference/messy.html @@ -81,7 +81,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -104,26 +104,26 @@
  • diff --git a/docs/reference/nested_list.html b/docs/reference/nested_list.html index 702b74f3..cbf1df6b 100644 --- a/docs/reference/nested_list.html +++ b/docs/reference/nested_list.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/norm2beta.html b/docs/reference/norm2beta.html index bce588d6..428e6f44 100644 --- a/docs/reference/norm2beta.html +++ b/docs/reference/norm2beta.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/norm2binom.html b/docs/reference/norm2binom.html index 9bdd6436..03e85ac7 100644 --- a/docs/reference/norm2binom.html +++ b/docs/reference/norm2binom.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/norm2likert.html b/docs/reference/norm2likert.html index c9e2b811..2c758129 100644 --- a/docs/reference/norm2likert.html +++ b/docs/reference/norm2likert.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/norm2pois.html b/docs/reference/norm2pois.html index ad1b6d3d..356acffa 100644 --- a/docs/reference/norm2pois.html +++ b/docs/reference/norm2pois.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/norm2trunc.html b/docs/reference/norm2trunc.html index 6acc1ba9..e1a9e36d 100644 --- a/docs/reference/norm2trunc.html +++ b/docs/reference/norm2trunc.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/norm2unif.html b/docs/reference/norm2unif.html index 529368f9..df17a815 100644 --- a/docs/reference/norm2unif.html +++ b/docs/reference/norm2unif.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/pipe.html b/docs/reference/pipe.html index 3d8f6b41..4c991ecf 100644 --- a/docs/reference/pipe.html +++ b/docs/reference/pipe.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/plot_design.html b/docs/reference/plot_design.html index 22bf7a1b..993dcffd 100644 --- a/docs/reference/plot_design.html +++ b/docs/reference/plot_design.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/pos_def_limits.html b/docs/reference/pos_def_limits.html index ecd48e7e..6f95fc8c 100644 --- a/docs/reference/pos_def_limits.html +++ b/docs/reference/pos_def_limits.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/print.design.html b/docs/reference/print.design.html index ecf11e28..c0dcda18 100644 --- a/docs/reference/print.design.html +++ b/docs/reference/print.design.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/print.nested_list.html b/docs/reference/print.nested_list.html index a08f6c29..39983491 100644 --- a/docs/reference/print.nested_list.html +++ b/docs/reference/print.nested_list.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/print.psychds_codebook.html b/docs/reference/print.psychds_codebook.html index acb8bae4..db36c5c0 100644 --- a/docs/reference/print.psychds_codebook.html +++ b/docs/reference/print.psychds_codebook.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/readline_check.html b/docs/reference/readline_check.html index a3b6f4b0..20699c91 100644 --- a/docs/reference/readline_check.html +++ b/docs/reference/readline_check.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/rnorm_multi.html b/docs/reference/rnorm_multi.html index aeb6f1e2..bfaeaf03 100644 --- a/docs/reference/rnorm_multi.html +++ b/docs/reference/rnorm_multi.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • @@ -166,7 +166,8 @@

    Multiple correlated normal distributions

    r = 0, varnames = NULL, empirical = FALSE, - as.matrix = FALSE + as.matrix = FALSE, + seed = NULL )

    Arguments

    @@ -204,6 +205,10 @@

    Arg as.matrix

    logical. If true, returns a matrix

    + + seed +

    DEPRECATED use set.seed() instead

    +

    Value

    diff --git a/docs/reference/rnorm_pre.html b/docs/reference/rnorm_pre.html index 34f706a6..a6bedbdb 100644 --- a/docs/reference/rnorm_pre.html +++ b/docs/reference/rnorm_pre.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/sample_from_pop.html b/docs/reference/sample_from_pop.html index 4902a7af..4d0c6a4d 100644 --- a/docs/reference/sample_from_pop.html +++ b/docs/reference/sample_from_pop.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/sim_data.html b/docs/reference/sim_data.html index 9403d6fc..e8247172 100644 --- a/docs/reference/sim_data.html +++ b/docs/reference/sim_data.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • @@ -163,7 +163,8 @@

    Simulate data from design (internal)

    empirical = FALSE, long = FALSE, rep = 1, - sep = faux_options("sep") + sep = faux_options("sep"), + seed = NULL )

    Arguments

    @@ -189,6 +190,10 @@

    Arg sep

    separator for within-columns, defaults to _

    + + seed +

    DEPRECATED use set.seed() instead

    +

    Value

    diff --git a/docs/reference/sim_design.html b/docs/reference/sim_design.html index bdc72af2..e0e5b8fd 100644 --- a/docs/reference/sim_design.html +++ b/docs/reference/sim_design.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • @@ -172,7 +172,8 @@

    Simulate data from design

    plot = faux_options("plot"), interactive = FALSE, design = NULL, - rep = 1 + rep = 1, + seed = NULL )

    Arguments

    @@ -234,6 +235,10 @@

    Arg rep

    the number of data frames to return (default 1); if greater than 1, the returned data frame is nested by rep

    + + seed +

    DEPRECATED use set.seed() instead

    +

    Value

    diff --git a/docs/reference/sim_df.html b/docs/reference/sim_df.html index 22f93218..f0844cf8 100644 --- a/docs/reference/sim_df.html +++ b/docs/reference/sim_df.html @@ -81,7 +81,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -104,26 +104,26 @@
  • @@ -168,7 +168,8 @@

    Simulate an existing dataframe

    id = "id", dv = "value", empirical = FALSE, - long = FALSE + long = FALSE, + seed = NULL )

    Arguments

    @@ -206,6 +207,10 @@

    Arg long

    whether to return the data table in long format

    + + seed +

    DEPRECATED use set.seed() instead

    +

    Value

    diff --git a/docs/reference/sim_mixed_cc.html b/docs/reference/sim_mixed_cc.html index 9a0572e9..276fcad7 100644 --- a/docs/reference/sim_mixed_cc.html +++ b/docs/reference/sim_mixed_cc.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • @@ -165,7 +165,8 @@

    Generate a cross-classified sample

    sub_sd = 1, item_sd = 1, error_sd = 1, - empirical = FALSE + empirical = FALSE, + seed = NULL )

    Arguments

    @@ -199,6 +200,10 @@

    Arg empirical

    Should the returned data have these exact parameters? (versus be sampled from a population with these parameters)

    + + seed +

    DEPRECATED use set.seed() instead

    +

    Value

    diff --git a/docs/reference/sim_mixed_df.html b/docs/reference/sim_mixed_df.html index 905f4d66..8cf29180 100644 --- a/docs/reference/sim_mixed_df.html +++ b/docs/reference/sim_mixed_df.html @@ -81,7 +81,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -104,26 +104,26 @@
  • diff --git a/docs/reference/std_alpha2average_r.html b/docs/reference/std_alpha2average_r.html new file mode 100644 index 00000000..18905414 --- /dev/null +++ b/docs/reference/std_alpha2average_r.html @@ -0,0 +1,209 @@ + + + + + + + + +Standardized Alpha to Average R — std_alpha2average_r • faux + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Standardized Alpha to Average R

    +
    + +
    std_alpha2average_r(std_alpha, n)
    + +

    Arguments

    + + + + + + + + + + +
    std_alpha

    The standarized alpha

    n

    The number of items

    + +

    Value

    + +

    The average inter-item correlation

    + +

    Examples

    +
    std_alpha2average_r(.8, 10)
    #> [1] 0.2857143
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.5.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/trunc2norm.html b/docs/reference/trunc2norm.html index f9568eb2..a5c9e70f 100644 --- a/docs/reference/trunc2norm.html +++ b/docs/reference/trunc2norm.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/unif2norm.html b/docs/reference/unif2norm.html index edd57f56..ba7d5129 100644 --- a/docs/reference/unif2norm.html +++ b/docs/reference/unif2norm.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/unique_pairs.html b/docs/reference/unique_pairs.html index 8e718fe3..c108c95f 100644 --- a/docs/reference/unique_pairs.html +++ b/docs/reference/unique_pairs.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/docs/reference/wide2long.html b/docs/reference/wide2long.html index 67621d10..365ab26b 100644 --- a/docs/reference/wide2long.html +++ b/docs/reference/wide2long.html @@ -80,7 +80,7 @@ faux - 0.0.1.4 + 0.0.1.5 @@ -103,26 +103,26 @@
  • diff --git a/inst/CITATION b/inst/CITATION index 5bd7a6e9..9e216976 100644 --- a/inst/CITATION +++ b/inst/CITATION @@ -7,8 +7,8 @@ citEntry( doi = "10.5281/zenodo.2669586", publisher = "Zenodo", year = "2020", - month = "August", - note = "R package version 0.0.1.4", + month = "September", + note = "R package version 0.0.1.5", url = "https://debruine.github.io/faux/", - textVersion = paste("Lisa DeBruine (2020). faux: Simulation for Factorial Designs. R package version 0.0.1.4. Zenodo. http://doi.org/10.5281/zenodo.2669586") + textVersion = paste("Lisa DeBruine (2020). faux: Simulation for Factorial Designs. R package version 0.0.1.5. Zenodo. http://doi.org/10.5281/zenodo.2669586") ) diff --git a/inst/_pkgdown.yml b/inst/_pkgdown.yml index 72671ce4..c9c7661d 100644 --- a/inst/_pkgdown.yml +++ b/inst/_pkgdown.yml @@ -57,6 +57,7 @@ reference: - title: Distribution functions desc: ~ contents: + - '`std_alpha2average_r`' - '`norm2likert`' - '`norm2beta`' - '`norm2binom`' diff --git a/man/average_r2tau_0.Rd b/man/average_r2tau_0.Rd new file mode 100644 index 00000000..50a04470 --- /dev/null +++ b/man/average_r2tau_0.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/distribution_convertors.R +\name{average_r2tau_0} +\alias{average_r2tau_0} +\title{Average r to Random Intercept SD} +\usage{ +average_r2tau_0(average_r, sigma) +} +\arguments{ +\item{average_r}{The average inter-item correlation} + +\item{sigma}{Total error variance} +} +\value{ +The standard deviation of the random intercept +} +\description{ +Average r to Random Intercept SD +} diff --git a/man/rnorm_multi.Rd b/man/rnorm_multi.Rd index a4450657..06adac6d 100644 --- a/man/rnorm_multi.Rd +++ b/man/rnorm_multi.Rd @@ -12,7 +12,8 @@ rnorm_multi( r = 0, varnames = NULL, empirical = FALSE, - as.matrix = FALSE + as.matrix = FALSE, + seed = NULL ) } \arguments{ @@ -31,6 +32,8 @@ rnorm_multi( \item{empirical}{logical. If true, mu, sd and r specify the empirical not population mean, sd and covariance} \item{as.matrix}{logical. If true, returns a matrix} + +\item{seed}{DEPRECATED use set.seed() instead} } \value{ a tbl of vars vectors diff --git a/man/sim_data.Rd b/man/sim_data.Rd index b45ae8a3..53e3afd6 100644 --- a/man/sim_data.Rd +++ b/man/sim_data.Rd @@ -9,7 +9,8 @@ sim_data( empirical = FALSE, long = FALSE, rep = 1, - sep = faux_options("sep") + sep = faux_options("sep"), + seed = NULL ) } \arguments{ @@ -22,6 +23,8 @@ sim_data( \item{rep}{the number of data frames to return (default 1); if greater than 1, the returned data frame is nested by rep} \item{sep}{separator for within-columns, defaults to _} + +\item{seed}{DEPRECATED use set.seed() instead} } \value{ a tbl diff --git a/man/sim_design.Rd b/man/sim_design.Rd index 5193578f..f154e3e8 100644 --- a/man/sim_design.Rd +++ b/man/sim_design.Rd @@ -18,7 +18,8 @@ sim_design( plot = faux_options("plot"), interactive = FALSE, design = NULL, - rep = 1 + rep = 1, + seed = NULL ) } \arguments{ @@ -49,6 +50,8 @@ sim_design( \item{design}{a design list including within, between, n, mu, sd, r, dv, id} \item{rep}{the number of data frames to return (default 1); if greater than 1, the returned data frame is nested by rep} + +\item{seed}{DEPRECATED use set.seed() instead} } \value{ a tbl diff --git a/man/sim_df.Rd b/man/sim_df.Rd index 15c3c787..193d2aa2 100644 --- a/man/sim_df.Rd +++ b/man/sim_df.Rd @@ -12,7 +12,8 @@ sim_df( id = "id", dv = "value", empirical = FALSE, - long = FALSE + long = FALSE, + seed = NULL ) } \arguments{ @@ -31,6 +32,8 @@ sim_df( \item{empirical}{Should the returned data have these exact parameters? (versus be sampled from a population with these parameters)} \item{long}{whether to return the data table in long format} + +\item{seed}{DEPRECATED use set.seed() instead} } \value{ a tbl diff --git a/man/sim_mixed_cc.Rd b/man/sim_mixed_cc.Rd index 65e49e0a..320b33d5 100644 --- a/man/sim_mixed_cc.Rd +++ b/man/sim_mixed_cc.Rd @@ -11,7 +11,8 @@ sim_mixed_cc( sub_sd = 1, item_sd = 1, error_sd = 1, - empirical = FALSE + empirical = FALSE, + seed = NULL ) } \arguments{ @@ -28,6 +29,8 @@ sim_mixed_cc( \item{error_sd}{the SD of the error term} \item{empirical}{Should the returned data have these exact parameters? (versus be sampled from a population with these parameters)} + +\item{seed}{DEPRECATED use set.seed() instead} } \value{ a tbl diff --git a/man/std_alpha2average_r.Rd b/man/std_alpha2average_r.Rd new file mode 100644 index 00000000..813b96d9 --- /dev/null +++ b/man/std_alpha2average_r.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/distribution_convertors.R +\name{std_alpha2average_r} +\alias{std_alpha2average_r} +\title{Standardized Alpha to Average R} +\usage{ +std_alpha2average_r(std_alpha, n) +} +\arguments{ +\item{std_alpha}{The standarized alpha} + +\item{n}{The number of items} +} +\value{ +The average inter-item correlation +} +\description{ +Standardized Alpha to Average R +} +\examples{ +std_alpha2average_r(.8, 10) +} diff --git a/mess/r_to_tau.Rmd b/mess/r_to_tau.Rmd new file mode 100644 index 00000000..c43402ab --- /dev/null +++ b/mess/r_to_tau.Rmd @@ -0,0 +1,157 @@ +--- +title: "R to Tau" +author: "Lisa DeBruine" +date: "31/08/2020" +output: html_document +--- + +```{r} +knitr::opts_chunk$set(echo = TRUE, out.width = "100%", plot.width = 8, plot.height = 6) +library(lme4) +library(faux) +library(tidyverse) +``` + +## Function + +Simulates data for DV `y` with `n_subj` subjects doing `n_trials` repeated trials across 2 conditions (`B`) with effect size `beta`. The subject random intercept SD is `tau_0` and the error SD is `sigma`. + +Runs a mixed model with formula `y ~ B + (1 | id)` and a Cronbach's alpha. + +```{r} +x <- function(n_subj = 10, + n_trials = 10, + beta = 0, + tau_0 = 0, + sigma = 1) { + subj <- data.frame( + id = 1:n_subj, + T_0s = rnorm(n_subj, 0, tau_0), + B = rep(c(-0.5, 0.5), n_subj/2) + ) + + dat <- crossing(subj, trial = 1:n_trials) %>% + mutate(err = rnorm(nrow(.), 0, sigma), + y = B*beta + T_0s + err) + + mod <- lmer(y ~ B + (1 | id), dat) + + # so much output to trash! + trash <- suppressWarnings( + suppressMessages( + capture.output( + alpha <- dat %>% + select(id, trial, y) %>% + spread(trial, y) %>% + select(-id) %>% + psych::alpha(warnings = FALSE, check.keys = FALSE) %>% summary() + ))) + + list( + # params + n_trials = n_trials, + n_subj = n_subj, + beta = beta, + tau_0 = tau_0, + sigma = sigma, + # psych::alpha output + std.alpha = alpha$std.alpha, + raw.alpha = alpha$raw_alpha, + average_r = alpha$average_r, + # lmer output + B = fixef(mod)[[2]], + T0 = sqrt(unlist(VarCorr(mod))), + S = sigma(mod) + ) +} +``` + + +```{r eval = FALSE} +params <- expand.grid( + rep = 1:10, + beta = seq(0, 1, .25), + n_trials = c(10, 20), + n_subj = c(10, 20), + tau_0 = seq(0, 1.5, .25), + sigma = seq(0.5, 1.5, .25) +) %>% + select(-rep) +y <- purrr::pmap_df(params, x) + +save(y, file = "y") +``` + + +```{r} +load("y") +``` + + +```{r} +dat <- y %>% + mutate( + calc_avg_r = std_alpha2average_r(std.alpha, n_trials), + prop_var = tau_0^2 / (tau_0^2 + sigma^2), + calc_tau_0 = average_r2tau_0(calc_avg_r, sigma)) %>% + group_by(n_subj, n_trials, beta, tau_0, sigma) %>% + summarise(calc_tau_0 = mean(calc_tau_0, na.rm = T), + std.alpha = mean(std.alpha, na.rm = T), + avg_r = mean(average_r, na.rm = T), + prop_var = mean(prop_var, na.rm = T), + calc_avg_r = mean(calc_avg_r, na.rm = T), + T0 = mean(T0, na.rm = T), + S = mean(S, na.rm = T), + B = mean(B, na.rm = T), + .groups = "drop") +``` + +## Parameter tau_0 versus estimate T0 +```{r} +ggplot(dat, aes(tau_0, T0, color = as.factor(n_trials))) + + geom_abline(slope = 1) + + geom_point(alpha = 0.5) + + facet_grid(beta~sigma, labeller = label_both) +``` + +## Parameter tau_0 versus estimate from std_alpha +```{r} +ggplot(dat, aes(tau_0, calc_tau_0, color = sigma)) + + geom_abline(slope = 1) + + geom_point(alpha = .2) + + stat_summary(fun = "mean", geom = "point", size = 3) + + facet_grid(~beta, labeller = label_both) +``` + +## Parameter sigma versus estimate S +```{r} +ggplot(dat, aes(sigma, S, color = tau_0)) + + geom_point() + + geom_abline(slope = 1) + + facet_grid(n_trials~n_subj) +``` + +## Parameter beta versus estimate B +```{r} +ggplot(dat, aes(beta, B, color = tau_0)) + + geom_abline(slope = 1) + + geom_point(alpha = .5) + + stat_summary(fun = "mean", geom = "point", size = 3) + + facet_grid(sigma~tau_0, labeller = label_both) +``` + +## Estimate average_r versus calculated average_r +```{r} +ggplot(dat, aes(avg_r, calc_avg_r, color = sigma)) + + geom_point() + + geom_abline(slope = 1) + + facet_grid(beta~sigma, labeller = label_both) +``` + +## Parameter proportion variance versus calculated average_r +```{r} +ggplot(dat, aes(prop_var, calc_avg_r, color = beta)) + + geom_point() + + geom_abline(slope = 1) + + facet_grid(beta~sigma, labeller = label_both) +``` diff --git a/mess/r_to_tau.html b/mess/r_to_tau.html new file mode 100644 index 00000000..b0c6030b --- /dev/null +++ b/mess/r_to_tau.html @@ -0,0 +1,573 @@ + + + + + + + + + + + + + + +R to Tau + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + +
    knitr::opts_chunk$set(echo = TRUE, out.width = "100%", plot.width = 8, plot.height = 6)
    +library(lme4)
    +
    ## Loading required package: Matrix
    +
    library(faux)
    +
    ## 
    +## ************
    +## Welcome to faux. For support and examples visit:
    +## http://debruine.github.io/faux/
    +## - Get and set global package options with: faux_options()
    +## ************
    +
    library(tidyverse)
    +
    ## ── Attaching packages ────────────────────────────── tidyverse 1.3.0 ──
    +
    ## ✓ ggplot2 3.3.2     ✓ purrr   0.3.4
    +## ✓ tibble  3.0.3     ✓ dplyr   1.0.2
    +## ✓ tidyr   1.1.1     ✓ stringr 1.4.0
    +## ✓ readr   1.3.1     ✓ forcats 0.5.0
    +
    ## ── Conflicts ───────────────────────────────── tidyverse_conflicts() ──
    +## x tidyr::expand() masks Matrix::expand()
    +## x dplyr::filter() masks stats::filter()
    +## x dplyr::lag()    masks stats::lag()
    +## x tidyr::pack()   masks Matrix::pack()
    +## x tidyr::unpack() masks Matrix::unpack()
    +
    +

    Function

    +

    Simulates data for DV y with n_subj subjects doing n_trials repeated trials across 2 conditions (B) with effect size beta. The subject random intercept SD is tau_0 and the error SD is sigma.

    +

    Runs a mixed model with formula y ~ B + (1 | id) and a Cronbach’s alpha.

    +
    x <- function(n_subj = 10, 
    +              n_trials = 10, 
    +              beta = 0, 
    +              tau_0 = 0, 
    +              sigma = 1) {
    +  subj <- data.frame(
    +    id = 1:n_subj,
    +    T_0s = rnorm(n_subj, 0, tau_0),
    +    B = rep(c(-0.5, 0.5), n_subj/2)
    +  )
    +  
    +  dat <- crossing(subj, trial = 1:n_trials) %>%
    +    mutate(err = rnorm(nrow(.), 0, sigma),
    +           y = B*beta + T_0s + err)
    +  
    +  mod <- lmer(y ~ B + (1 | id), dat)
    +  
    +  # so much output to trash!
    +  trash <- suppressWarnings(
    +    suppressMessages(
    +      capture.output(
    +        alpha <- dat %>%
    +          select(id, trial, y) %>%
    +          spread(trial, y) %>%
    +          select(-id) %>%
    +          psych::alpha(warnings = FALSE, check.keys = FALSE) %>% summary()
    +  )))
    +  
    +  list(
    +    # params
    +    n_trials = n_trials,
    +    n_subj = n_subj,
    +    beta = beta,
    +    tau_0 = tau_0,
    +    sigma = sigma, 
    +    # psych::alpha output
    +    std.alpha = alpha$std.alpha,
    +    raw.alpha = alpha$raw_alpha,
    +    average_r = alpha$average_r,
    +    # lmer output
    +    B = fixef(mod)[[2]],
    +    T0 = sqrt(unlist(VarCorr(mod))),
    +    S =  sigma(mod)
    +  )
    +}
    +
    params <- expand.grid(
    +  rep = 1:10,
    +  beta = seq(0, 1, .25),
    +  n_trials = c(10, 20),
    +  n_subj = c(10, 20),
    +  tau_0 = seq(0, 1.5, .25),
    +  sigma = seq(0.5, 1.5, .25)
    +) %>%
    +  select(-rep)
    +y <- purrr::pmap_df(params, x)
    +
    +save(y, file = "y")
    +
    load("y")
    +
    dat <- y %>%
    +  mutate(
    +    calc_avg_r = std_alpha2average_r(std.alpha, n_trials),
    +    prop_var = tau_0^2 / (tau_0^2 + sigma^2),
    +    calc_tau_0 = average_r2tau_0(calc_avg_r, sigma)) %>%
    +  group_by(n_subj, n_trials, beta, tau_0, sigma) %>%
    +  summarise(calc_tau_0 = mean(calc_tau_0, na.rm = T),
    +            std.alpha = mean(std.alpha, na.rm = T), 
    +            avg_r = mean(average_r, na.rm = T),
    +            prop_var = mean(prop_var, na.rm = T),
    +            calc_avg_r = mean(calc_avg_r, na.rm = T),
    +            T0 = mean(T0, na.rm = T),
    +            S = mean(S, na.rm = T),
    +            B = mean(B, na.rm = T),
    +            .groups = "drop")
    +
    ## Warning: Problem with `mutate()` input `calc_tau_0`.
    +## ℹ NaNs produced
    +## ℹ Input `calc_tau_0` is `average_r2tau_0(calc_avg_r, sigma)`.
    +
    ## Warning in sqrt((average_r * sigma^2)/(1 - average_r)): NaNs produced
    +
    +
    +

    Parameter tau_0 versus estimate T0

    +
    ggplot(dat, aes(tau_0, T0, color = as.factor(n_trials))) +
    +  geom_abline(slope = 1) + 
    +  geom_point(alpha = 0.5) + 
    +  facet_grid(beta~sigma, labeller = label_both)
    +

    +
    +
    +

    Parameter tau_0 versus estimate from std_alpha

    +
    ggplot(dat, aes(tau_0, calc_tau_0, color = sigma)) +
    +  geom_abline(slope = 1) + 
    +  geom_point(alpha = .2) + 
    +  stat_summary(fun = "mean", geom = "point", size = 3) +
    +  facet_grid(~beta, labeller = label_both)
    +

    +
    +
    +

    Parameter sigma versus estimate S

    +
    ggplot(dat, aes(sigma, S, color = tau_0)) +
    +  geom_point() + 
    +  geom_abline(slope = 1) + 
    +  facet_grid(n_trials~n_subj)
    +

    +
    +
    +

    Parameter beta versus estimate B

    +
    ggplot(dat, aes(beta, B, color = tau_0)) +
    +  geom_abline(slope = 1) + 
    +  geom_point(alpha = .5) + 
    +  stat_summary(fun = "mean", geom = "point", size = 3) +
    +  facet_grid(sigma~tau_0, labeller = label_both)
    +

    +
    +
    +

    Estimate average_r versus calculated average_r

    +
    ggplot(dat, aes(avg_r, calc_avg_r, color = sigma)) +
    +  geom_point() + 
    +  geom_abline(slope = 1) + 
    +  facet_grid(beta~sigma, labeller = label_both)
    +

    +
    +
    +

    Parameter proportion variance versus calculated average_r

    +
    ggplot(dat, aes(prop_var, calc_avg_r, color = beta)) +
    +  geom_point() + 
    +  geom_abline(slope = 1) + 
    +  facet_grid(beta~sigma, labeller = label_both)
    +

    +
    + + + + +
    + + + + + + + + + + + + + + + diff --git a/mess/todo.md b/mess/todo.md new file mode 100644 index 00000000..63b40090 --- /dev/null +++ b/mess/todo.md @@ -0,0 +1,16 @@ +# To Do + +## Coding + +* handle underscores in variable names better +* non-normal DVs +* mixed designs +* generic power (from scienceverse) +* shiny app + +## Other + +* workshop test (advertise on Twitter?) +* integrate with other R packages +* more vignettes + diff --git a/mess/y b/mess/y new file mode 100644 index 00000000..b4ee7de5 Binary files /dev/null and b/mess/y differ diff --git a/tests/testthat/Rplots.pdf b/tests/testthat/Rplots.pdf index b465cb57..7b2561ff 100644 Binary files a/tests/testthat/Rplots.pdf and b/tests/testthat/Rplots.pdf differ diff --git a/tests/testthat/test-distributions.R b/tests/testthat/test-distributions.R index 3f3f49b8..3799b449 100644 --- a/tests/testthat/test-distributions.R +++ b/tests/testthat/test-distributions.R @@ -157,25 +157,25 @@ test_that("trunc2norm", { x <- truncnorm::rtruncnorm(1000) expect_message(suppressWarnings(trunc2norm(x)), - "mu was set to 0.00639653548187051", fixed = TRUE) + "mu was set to 0\\.006\\d+") expect_message(suppressWarnings(trunc2norm(x)), - "sd was set to 0.9980754175952", fixed = TRUE) + "sd was set to 0\\.998\\d+") expect_message(suppressWarnings(trunc2norm(x)), - "-2.98782971730373 (min(x) = -3.05632823356306)", fixed = TRUE) + "-2\\.987\\d+ \\(min\\(x\\) = -3\\.056\\d+\\)") expect_message(suppressWarnings(trunc2norm(x)), - "max was set to 3.00062278826747 (max(x) = 3.51929906496364)", fixed = TRUE) + "max was set to 3\\.000\\d+ \\(max\\(x\\) = 3\\.519\\d+\\)") expect_warning(suppressMessages(trunc2norm(x)), - "min was > min(x), so min was set to -3.06630898773901", fixed = TRUE) + "min was > min\\(x\\), so min was set to -3\\.066\\d+") expect_warning(suppressMessages(trunc2norm(x)), - "max was < max(x), so max was set to 3.52927981913959", fixed = TRUE) + "max was < max\\(x\\), so max was set to 3\\.529\\d+") set.seed(8675309) x <- truncnorm::rtruncnorm(100, mean = 10, sd = 5) - expect_message(trunc2norm(x), "mu was set to 10.2615138815768", fixed = TRUE) - expect_message(trunc2norm(x), "sd was set to 4.64571854015768", fixed = TRUE) - expect_message(trunc2norm(x), "min was set to -3.67564173889628 (min(x) = -2.98432899791241)", fixed = TRUE) - expect_message(trunc2norm(x), "max was set to 24.1986695020498 (max(x) = 20.1469578725237)", fixed = TRUE) + expect_message(trunc2norm(x), "mu was set to 10\\.261\\d+") + expect_message(trunc2norm(x), "sd was set to 4\\.645\\d+") + expect_message(trunc2norm(x), "min was set to -3\\.675\\d+ \\(min\\(x\\) = -2\\.984\\d+\\)") + expect_message(trunc2norm(x), "max was set to 24\\.198\\d+ \\(max\\(x\\) = 20\\.146\\d+\\)") # defaults for (i in 1:reps) { @@ -238,3 +238,21 @@ test_that("norm2likert", { expect_equal(mean(y == 3), .2, tolerance = tol) expect_equal(mean(y == 4), .1, tolerance = tol) }) + +# std_alpha2average_r ---- +test_that("std_alpha2average_r", { + set.seed(10) + + replicate(10, { + n <- sample(10:100, 1) + vars <- sample(5:20, 1) + r <- runif(1) + dat <- rnorm_multi(n, vars, r = r) + suppressWarnings(capture.output( + a <- psych::alpha(dat, check.keys = FALSE) %>% summary() + )) + calc_r <- std_alpha2average_r(a$std.alpha, vars) + expect_equal(a$average_r, calc_r, tolerance = .001) + }) +}) + diff --git a/tests/testthat/test-messages.R b/tests/testthat/test-messages.R index 60c6f586..2556acc1 100644 --- a/tests/testthat/test-messages.R +++ b/tests/testthat/test-messages.R @@ -5,20 +5,20 @@ test_that("check", { expect_message(message("pipes?", "no!"), "\033[32mpipes?no!\033[39m", fixed = 1) }) -test_that("not knit", { - # renders without green text marker when knitting - - txt <- "---\ntitle: 'Test'\n---\n\n```{r}\nfaux:::message('hi')\n```" - find <- '
    ## hi
    ' - - write(txt, "tmp.Rmd") - rmarkdown::render("tmp.Rmd", quiet = TRUE) - html <- readLines("tmp.html") - found <- grep(find, html, fixed = TRUE) - expect_true(length(found) == 1) - - # cleanup - file.remove("tmp.Rmd") - file.remove("tmp.html") - -}) +# test_that("not knit", { +# # renders without green text marker when knitting +# +# txt <- "---\ntitle: 'Test'\n---\n\n```{r}\nfaux:::message('hi')\n```" +# find <- '
    ## hi
    ' +# +# write(txt, "tmp.Rmd") +# rmarkdown::render("tmp.Rmd", quiet = TRUE) +# html <- readLines("tmp.html") +# found <- grep(find, html, fixed = TRUE) +# expect_true(length(found) == 1) +# +# # cleanup +# file.remove("tmp.Rmd") +# file.remove("tmp.html") +# +# })