I want to simulate a dataset whereby I have a continuous variable that represents a response to treatment (normally distributed). The dataset should also include sex (50:50) and age (normally distributed) when starting treatment.
I want to create the dataset such that:
If I perform a linear regression on sex or age across all individuals, I would obtain beta estimates similar to effect estimates of age and sex previously published. I know how to simulate such a dataset using the
simglm
library in R.If I split individuals based on sex and then subsequently split again based on above or below median age, I would obtain mean estimates of response as previously published within those groups. I know how to simulate differences in response in each group (e.g. males and under median age) using random variables drawn from different distributions using functions like
rnorm()
in R where the differences in means across groups reflect previously published average response estimates.
The issue is that I don't know how to essentially do the two tasks above "simultaneously" to achieve both objectives. I realise that the dataset I wish to create is described as "hierarchical" / "multilevel" but am not quite sure how to get to a place where I can implement a simulated model that does both 1 and 2 above. Does anyone have any ideas of how this could be done in R? I was thinking that the simglm
package might be able to do this but I've struggled to follow the vignette re random effects that may or may not help here.
Thanks in advance.