Skip to main content
4 of 4
added 2 characters in body
lnNoam
  • 243
  • 1
  • 7

Disclaimer: I do not suggest using this solution for any real-world applications. This is simply a demonstration.


I'm not sure what your background is, but this is really easy to do in code. You could simply run a random number generator and print off the results for the clinician.

Here is an example solution in R:

ngen <- function(patients, weeks){
  df <- data.frame( t( replicate(patients, sample(c("A","B"), weeks, replace=T)) ) )
  colnames(df) <- paste(replicate(ncol(df), "Week"), as.character(1:ncol(df)))
  rownames(df) <- paste(replicate(nrow(df), "Patient"), as.character(1:nrow(df)))
  print(df)
}

Example Usage:

ngen(patients = 10, weeks = 5)

           Week 1 Week 2 Week 3 Week 4 Week 5
Patient 1       A      B      A      B      A
Patient 2       B      B      A      B      A
Patient 3       A      B      A      A      B
Patient 4       A      A      A      A      A
Patient 5       A      B      A      A      A
Patient 6       B      B      B      A      B
Patient 7       A      A      A      B      A
Patient 8       A      B      A      B      B
Patient 9       B      A      A      B      B
Patient 10      B      A      B      A      B

Check by simulating 10,000 weeks:

m <- ngen(patients = 10, weeks = 10000)

# look at patient 1:
mean(as.numeric(m[1,]) - 1)

The mean condition for patient 1 is 0.5, i.e., even chance of being in condition A or condition B as n weeks goes to infinity.

lnNoam
  • 243
  • 1
  • 7