The function GRF() generates random frequencies based on a design, i.e., a list giving the factors and the categories with each factor. The data are given in the compiled format.

GRF( design, n, prob = NULL, f = "Freq" )

Arguments

design

A list with the factors and the categories within each.

n

How many simulated participants are to be classified.

prob

(optional) the probability of falling in each cell of the design.

f

(optional) the column names that will contain the frequencies.

Value

a data frame containing frequencies per cells of the design.

Details

The name of the function GRF() is derived from grd(), a general-purpose tool to generate random data (Calderini and Harding 2019) now bundled in the superb package (Cousineau et al. 2021) .

References

Calderini M, Harding B (2019). “GRD for R: An intuitive tool for generating random data in R.” The Quantitative Methods for Psychology, 15(1), 1--11. doi:10.20982/tqmp.15.1.p001 .

Cousineau D, Goulet M, Harding B (2021). “Summary plots with adjusted error bars: The superb framework with an implementation in R.” Advances in Methods and Practices in Psychological Science, 4, 1--18. doi:10.1177/25152459211035109 .

Examples


# The first example disperse 20 particants in one factor having
# two categories (low and high):
design <- list( A=c("low","high"))
GRF( design, 20 )
#>      A Freq
#> 1  low    7
#> 2 high   13

# This example has two factors, with factor A having levels a, b, c:
design <- list( A=letters[1:3], B = c("low","high"))
GRF( design, 40 )
#>   A    B Freq
#> 1 a  low    9
#> 2 b  low    7
#> 3 c  low    4
#> 4 a high    2
#> 5 b high    9
#> 6 c high    9

# This last one has three factors, for a total of 3 x 2 x 2 = 12 cells
design <- list( A=letters[1:3], B = c("low","high"), C = c("cat","dog"))
GRF( design, 100 )
#>    A    B   C Freq
#> 1  a  low cat    8
#> 2  b  low cat    7
#> 3  c  low cat   10
#> 4  a high cat   10
#> 5  b high cat   11
#> 6  c high cat    5
#> 7  a  low dog    4
#> 8  b  low dog    8
#> 9  c  low dog    9
#> 10 a high dog    7
#> 11 b high dog   10
#> 12 c high dog   11

# To specify unequal probabilities, use
design <- list( A=letters[1:3], B = c("low","high"))
GRF( design, 100, c(.05, .05, .35, .35, .10, .10 ) )
#>   A    B Freq
#> 1 a  low    2
#> 2 b  low    4
#> 3 c  low   32
#> 4 a high   37
#> 5 b high    8
#> 6 c high   17

# The name of the column containing the frequencies can be changes
GRF( design, 100, f="patate")
#>   A    B patate
#> 1 a  low     17
#> 2 b  low     18
#> 3 c  low     18
#> 4 a high     10
#> 5 b high     16
#> 6 c high     21