0
$\begingroup$

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:

  1. 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.

  2. 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.

$\endgroup$
5
  • $\begingroup$ Tell us more about your data structure. Are the people (or whatever your units of analysis are) at level 1 or level 2? In other words do you have people clustered within higher level units (families, classrooms, etc) or measures clustered within people. $\endgroup$ Commented Aug 4, 2023 at 16:33
  • $\begingroup$ Hi Jeremy. I think the individuals will be level 1 in that they can be grouped into the mutually exclusive groups related to sex and lower/upper age groups that form to level 2? $\endgroup$
    – Jack Box
    Commented Aug 4, 2023 at 20:44
  • $\begingroup$ This doesn't sound like hierarchical data. Typically this is where individuals are nested within groups, and these groups are sampled from a population (e.g. you have analyze 100 individuals who are in 50 families - your families are considered a random sample of possible families). You have two sexes, this is not a random sample of all sexes, it's all (2) of them. $\endgroup$ Commented Aug 4, 2023 at 21:20
  • $\begingroup$ OK thanks. So do you know a way to solve the problem I describe? $\endgroup$
    – Jack Box
    Commented Aug 4, 2023 at 21:25
  • 1
    $\begingroup$ I would use the mvrnorm() function in the MASS package. This will generate data that are sampled from a population with specificed means and covariances. $\endgroup$ Commented Aug 4, 2023 at 22:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.