Uses faux::sim_design() to generate a data table with a specified within and between design.

add_sim_data(
  study,
  data_id,
  within = list(),
  between = list(),
  n = 100,
  mu = 0,
  sd = 1,
  r = 0,
  empirical = FALSE,
  long = FALSE,
  dv = list(y = "value"),
  id = list(id = "id"),
  plot = FALSE,
  rep = 1
)

Arguments

study

A study list object with class scivrs_study

data_id

The id for this dataset (index or character) if a dataset with this id already exists, it will overwrite it

within

a list of the within-subject factors

between

a list of the between-subject factors

n

the number of samples required

mu

the means of the variables

sd

the standard deviations of the variables

r

the correlations among the variables (can be a single number, full correlation matrix as a matrix or vector, or a vector of the upper right triangle of the correlation matrix

empirical

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

long

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

dv

the name of the dv for long plots (defaults to y)

id

the name of the id column (defaults to id)

plot

whether to show a plot of the design

rep

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

Value

A study object with class scivrs_study

Examples


s <- study() %>%
  add_sim_data("dat", within = list(time = c("day", "night")),
               between = list(pet = c("cat", "dog")),
               n = 10, mu = 100, sd = 10, r = 0.5)
#> id set to dataType string
#> pet set to dataType string
#> day set to dataType float
#> night set to dataType float
s$data[[1]]$data
#>     id pet       day     night
#> 1  S01 cat  90.64376  85.10677
#> 2  S02 cat  99.06620 105.35602
#> 3  S03 cat  68.56755  89.21780
#> 4  S04 cat 108.10670  91.79680
#> 5  S05 cat 102.82067 107.94494
#> 6  S06 cat 119.26059 100.63048
#> 7  S07 cat  86.83266  81.61253
#> 8  S08 cat  98.12111  97.59509
#> 9  S09 cat  95.17019 100.60015
#> 10 S10 cat 102.12207  92.98132
#> 11 S11 dog  99.37752 108.73115
#> 12 S12 dog 102.26081 104.02569
#> 13 S13 dog  87.48389  89.92075
#> 14 S14 dog  98.27159 114.50707
#> 15 S15 dog 115.79474 116.91512
#> 16 S16 dog  99.82609  98.48612
#> 17 S17 dog 101.44576  82.34489
#> 18 S18 dog 101.25805  98.46568
#> 19 S19 dog  94.40703  91.27257
#> 20 S20 dog  81.56570  92.23877