Skip to main content
added 2 characters in body
Source Link
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 0A or condition 1B as n weeks goes to infinity.

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 0 or condition 1 as n weeks goes to infinity.

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.

added 2 characters in body
Source Link
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 0 or condition 1 as n weeks goes to infinity.

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,]))

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

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 0 or condition 1 as n weeks goes to infinity.

added 2 characters in body
Source Link
lnNoam
  • 243
  • 1
  • 7
ngen <- function(patients, weeks){
  df <- data.frame( t( replicate(patients, sample(0:1c("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)
}
           Week 1 Week 2 Week 3 Week 4 Week 5
Patient 1       1A      0B      1A      0B      1A
Patient 2       0B      1B      1A      0B      0A
Patient 3       0A      0B      1A      1A      0B
Patient 4       0A      1A      0A      1A      1A
Patient 5       1A      0B      0A      1A      1A
Patient 6       0B      1B      0B      1A      0B
Patient 7       0A      1A      1A      0B      0A
Patient 8       0A      0B      1A      0B      1B
Patient 9       1B      0A      0A      0B      1B
Patient 10      0B      1A      1B      1A      1B
ngen <- function(patients, weeks){
  df <- data.frame(t(replicate(patients, sample(0:1, 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)
}
           Week 1 Week 2 Week 3 Week 4 Week 5
Patient 1       1      0      1      0      1
Patient 2       0      1      1      0      0
Patient 3       0      0      1      1      0
Patient 4       0      1      0      1      1
Patient 5       1      0      0      1      1
Patient 6       0      1      0      1      0
Patient 7       0      1      1      0      0
Patient 8       0      0      1      0      1
Patient 9       1      0      0      0      1
Patient 10      0      1      1      1      1
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)
}
           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
Source Link
lnNoam
  • 243
  • 1
  • 7
Loading