fn_sample: Return a javascript function that samples from an array

Description Usage Arguments Details Value

View source: R/randomisation.R

Description

Return a javascript function that samples from an array

Usage

1

Arguments

x

A vector specifying the possible values

size

The number of values to sample

replace

Sample with replacement? (default = FALSE)

weights

Probability of sampling each item (ignored if replace = FALSE)

Details

The fn_sample() is used to return a function that, when called from within a jsPsych experiment, will mirror the behaviour of the sample() function from the base package using th jsPsych randomisation functions to at runtime. The input argument x specifies the set of values from which samples should be drawn, and the size argument specifies the number of samples to be drawn. When replace = TRUE items are sampled with replacement, and when replace = FALSE items are sampled without replacement. When sampling with replacement, the weights argument can be used to specify unequal sampling probabilities.

The current implementation is limited. It does not work when x is a character vector, for example. Note also that the value returned within the jsPsych experiment is always an array (not a scalar), even when size = 1.

Value

Returns a javascript function that samples from an array of values


djnavarro/jaysire documentation built on April 12, 2021, 4:25 a.m.