rBernoulli {ANOPA}R Documentation

Generating random proportions with GRP

Description

The function 'GRP()' generates random proportions based on a design, i.e., a list giving the factors and the categories with each factor. The data are returned in the 'wide' format.

Usage

GRP( props, n, BSDesign=NULL, WSDesign=NULL, sname = "s" )

rBernoulli(n, p)

Arguments

n

How many simulated participants are in each between-subject group (can be a vector, one per group);

p

a proportion of success;

BSDesign

A list with the between-subject factor(s) and the categories within each;

WSDesign

A list with the within-subject factor(s) and the categories within each;

props

(optional) the proportion of succes in each cell of the design. Default 0.50;

sname

(optional) the column name that will contain the success/failure;

Details

The name of the function GRP() 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). GRP() is actually a proxy for GRD().

Value

GRP() returns a data frame containing success (coded as 1) or failure (coded as 0) for n participants per cells of the design. Note that correlated scores cannot be generated by GRP(); see (Lunn and Davies 1998). rBernoulli() returns a sequence of n success (1) or failures (0)

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.

Lunn AD, Davies SJ (1998). “A note on generating correlated binary variables.” Biometrika, 85(2), 487–490. doi:10.1093/biomet/85.2.487.

Examples


# The first example generate scorse for 20 particants in one factor having
# two categories (low and high):
design <- list( A=c("low","high"))
GRP( design, props = c(0.1,  0.9), n = 20 )

# This example has two factors, with factor A having levels a, b, c
# and factor B having 2 levels, for a total of 6 conditions;
# with 40 participants per group, it represents 240 observations:
design <- list( A=letters[1:3], B = c("low","high"))
GRP( design, props = c(0.1, 0.15, 0.20, 0.80, 0.85, 0.90), n = 40 )

# groups can be unequal:
design <- list( A=c("low","high"))
GRP( design, props = c(0.1,  0.9), n = c(5, 35) )

# Finally, repeated-measures can be generated
# but note that correlated scores cannot be generated with `GRP()`
wsDesign = list( Moment = c("pre", "post") )
GRP( WSDesign=wsDesign, props = c(0.1,  0.9), n = 10 )

# 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"))
GRP( design, n = 30, props = rep(0.5,12) )

# To specify unequal probabilities, use
design  <- list( A=letters[1:3], B = c("low","high"))
expProp <- c(.05, .05, .35, .35, .10, .10 )
GRP( design, n = 30, props=expProp )

# The name of the column containing the proportions can be changed
GRP( design, n=30, props=expProp, sname="patate")

# Examples of use of rBernoulli
t <- rBernoulli(50, 0.1)
mean(t)





[Package ANOPA version 0.1.3 Index]