0
$\begingroup$

I have a large dataset from a study I conducted in which I'm attempting, for pedagogical reasons, to use for a class. However, due to IRB constraints, I cannot use the real data.

Instead, I would like to re-sample the entire dataset while attempting to keep the original structure of the distributions (i.e., I do not want to artificially manipulate the data into forced normalcy).

However, anytime I use any type of monte carlo or bootstrap method (e.g., sample()), all it seems to do is just re-order the data. Further, due to the nested, repeated measures of the data I'm having a difficult time truly simulating it. Rather, any successful method I've used results in subjects whose repeated values are different when they should be the same.

I've posted an example of the structure of the data below.

enter image description here

You'll notice that the subjects are nested into groups, where multiple measurement days (3 in total), and each measurement day has three different measurement sessions.

Variables 1 - 3 are the same, as they were measured in the beginning of the study and therefore are not repeated (the data is in long-form).

Variable 4 is a repeated measurement, however, is repeated through each measurement day and session.

Can anyone provide a suggestion as to how I can completely re-sample this with replacement such that it maintains its original structure?

I have followed instruction from: https://stackoverflow.com/questions/38466788/r-coding-bootstrap-a-dataset-with-repeated-measures

Which suggested the following code: data[sample(x = nrow(data), size = nrow(data), replace = TRUE), ]

would work, but as mentioned earlier, this only re-orders the data and does not actually replace the data.

$\endgroup$
0
$\begingroup$

Since you have exactly 3 measurements per subject, it is easier.
Suppose the name of your dataset is x with 3n rows and the ids are 1, 2, ..., n. The resampled dataset is called xb.
This is how to do it in R:

n=4
ids=sample(n,n,replace=T)
xb=x[rep(ids*3,each=3)-rep(c(2,1,0),n),]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.