De novo simulation of data from an experimental design data frame.
With a focus on R (though other language solution would be great).
In designing an experiment or a survey, simulating data and conducting an analysis on this simulated data can provide terrific insight into advantages and weaknesses of the design.
Such an approach can also be essential to the understanding and proper use of statistical tests.
However, this process tends to be somewhat tedious and many are led to skip past this important step in an experiment or survey.
Statistical models and test contain most of the information required to simulate the data (including an assumption or an explicit statement of the distribution).
Given an an analysis model (and its associated assumptions eg. normality and balance), the levels of a factor and a measure of significance (such as p-value), I would like to obtain simulated data (ideally with a generalized function akin to print(), predict(), simulate()).
Is such a generalized simulation framework possible?
If so, is such a framework currently available?
Example, I would like a function, such as:
sim(aov(response~factor1+factor2*factor3),
p.values=list(factor1=0.05,
factor2=0.05,
factor3=0.50,
factor2:factor3=0.05),
levels=list(factor1=1:10,
factor2=c("A", "B", "C"),
factor3=c("A", "B", "C")))
ie, a generalized version of:
sim.lm<-function(){
library(DoE.base)
design<-fac.design(nlevels=c(10,3,3),
factor.names=c("factor1", "factor2", "factor3"),
replications=3,
randomize=F)
response<-with(design, as.numeric(factor1)+
as.numeric(factor2)+
as.numeric(factor3)+
as.numeric(factor2)*as.numeric(factor3)+
rnorm(length(factor1)))
simulation<-data.frame(design, response)}
OR
sim(glm(response~factor1+factor2*factor3, family=poisson),
p.values=list(factor1=0.05,
factor2=0.05,
factor3=0.50,
factor2:factor3=0.05),
levels=list(factor1=1:10,
factor2=c("A", "B", "C"),
factor3=c("A", "B", "C")))
OR
library(lme4)
sim(lmer(response~factor1+factor2 + (factor2|factor3)),
F_value=list(factor1=50,
factor2=50),
levels=list(factor1=1:10,
factor2=c("A", "B", "C"),
factor3=c("A", "B", "C")))
that would create a complete corresponding data.frame
potential examples of specific functions (please edit at will)
- arima.sim
function exist to create a data.frame of the factor levels, without the modelled response:
eg. conf.design
http://cran.r-project.org/web/views/ExperimentalDesign.html