debruine / faux

R functions for simulating factorial datasets

Home Page:https://debruine.github.io/faux/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

transposed mu data.frame

debruine opened this issue · comments

Bug found by @doomlab

library(faux)

between <- list(where_bought = c(online = "online", store = "Store"),
                who_bought = c(different = "Different", same = "Same"))
within <- list(rm_var = c("money", "time"))
how_many <- 100

# doesn't work
mu <- data.frame(
  online = c(25, 2),
  store = c(35, 10),
  different = c(25, 1.5),
  same = c(35, 12),
  row.names = within$rm_var
)

# does work!?
mu2 <- t(mu)
               
lab4_update <- sim_design(within, between, n = how_many, mu = mu2,
                          sd = 3, r = .10,
                          empirical = FALSE, plot = TRUE)

Ok, so yeah, I think I was misunderstanding what you were doing. That code only worked because it had the right number of numbers. Here's what I should have done:

##simulated data
between <- list(where_bought = c(online = "Online",
                                 store = "Store"),
                who_bought = c(different = "Different", 
                               same = "Same"))
within <- list(rm_var = c("money", "time"))

##pattern is money, then time, so keep the numbers larger in the first one
mu <- data.frame(
  online_different = c(25, 10),
  online_same = c(25, 10),
  store_different = c(35, 15),
  store_same = c(35, 20), 
  row.names = within$rm_var)
  
lab4_update <- sim_design(within, between, 
                          n = how_many, mu = mu, 
                          sd = 3, r = .10,
                          interactive = FALSE,
                          empirical = FALSE, 
                          plot = TRUE, 
                          seed = this_year_seed)

So maybe the bug is the user ;).