Last data update: 2014.03.03
|
R: Generate data
Generate data
Description
Generate data from a single row in the design input (see runSimulation ).
Usage
Generate(condition, fixed_objects = NULL)
Arguments
condition |
a single row from the design input (as a data.frame ), indicating the
simulation conditions
|
fixed_objects |
object passed down from runSimulation
|
Value
returns a single object containing the data to be analyzed (usually a
vector , matrix , or data.frame ),
or list )
See Also
add_missing , Attach
Examples
## Not run:
mygenerate <- function(condition, fixed_objects = NULL){
N1 <- condition$sample_sizes_group1
N2 <- condition$sample_sizes_group2
sd <- condition$standard_deviations
group1 <- rnorm(N1)
group2 <- rnorm(N2, sd=sd)
dat <- data.frame(group = c(rep('g1', N1), rep('g2', N2)),
DV = c(group1, group2))
# just a silly example of a simulated parameter
pars <- list(random_number = rnorm(1))
list(dat=dat, parameters=pars)
}
# similar to above, but using the Attach() function instead of indexing
mygenerate <- function(condition, fixed_objects = NULL){
Attach(condition)
N1 <- sample_sizes_group1
N2 <- sample_sizes_group2
sd <- standard_deviations
group1 <- rnorm(N1)
group2 <- rnorm(N2, sd=sd)
dat <- data.frame(group = c(rep('g1', N1), rep('g2', N2)),
DV = c(group1, group2))
dat
}
mygenerate2 <- function(condition, fixed_objects = NULL){
mu <- sample(c(-1,0,1), 1)
dat <- rnorm(100, mu)
dat #return simple vector (discard mu information)
}
mygenerate3 <- function(condition, fixed_objects = NULL){
mu <- sample(c(-1,0,1), 1)
dat <- data.frame(DV = rnorm(100, mu))
dat
}
## End(Not run)
Results
|