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 @@
##
+## ************
+## Welcome to faux. For support and examples visit:
+## http://debruine.github.io/faux/
+## - Get and set global package options with: faux_options()
+## ************
## ── 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.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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 <- '