Help with Design of Experiment - Williams Latin Square

Hello,

If someone can please help me designing a williams latin square design for 3 treatments and 80 subjects. I am using library(crossdes) package for this. My specific question is how I can specify the number of subjects.
williams(3)
It gave this:
`

williams(3)
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 2 3 1
[3,] 3 1 2
[4,] 3 2 1
[5,] 1 3 2
[6,] 2 1 3
`

Hi @sharmachetan,
You asked this question some time ago, so you may have an answer already.
Does this help?

suppressPackageStartupMessages(library(tidyverse))
library(crossdes)
#> Loading required package: AlgDesign
#> Loading required package: gtools
set.seed(42)
df <- as.data.frame(williams(3))

df$trt_combination <- paste0(df$V1, df$V2, df$V3)
df$trt_number <- 1:6

df
#>   V1 V2 V3 trt_combination trt_number
#> 1  1  2  3             123          1
#> 2  2  3  1             231          2
#> 3  3  1  2             312          3
#> 4  3  2  1             321          4
#> 5  1  3  2             132          5
#> 6  2  1  3             213          6

# Assumes no blocking or structure in subjects 1:80 (e.g sex, age cohort, etc).
# Better to recruit n*6 subjects, e.g. 78 or 84!
subj_df <- data.frame(subject = 1:80,
                      rand_trt = sample(c(rep(1:6, each=13), 1:2)))

head(subj_df)
#>   subject rand_trt
#> 1       1        4
#> 2       2        5
#> 3       3        2
#> 4       4        6
#> 5       5        2
#> 6       6        2

full_df <- left_join(subj_df, df, by=c("rand_trt" = "trt_number"))
head(full_df, n=10)
#>    subject rand_trt V1 V2 V3 trt_combination
#> 1        1        4  3  2  1             321
#> 2        2        5  1  3  2             132
#> 3        3        2  2  3  1             231
#> 4        4        6  2  1  3             213
#> 5        5        2  2  3  1             231
#> 6        6        2  2  3  1             231
#> 7        7        4  3  2  1             321
#> 8        8        2  2  3  1             231
#> 9        9        6  2  1  3             213
#> 10      10        3  3  1  2             312

table(full_df$trt_combination)
#> 
#> 123 132 213 231 312 321 
#>  14  13  13  14  13  13

Created on 2022-11-18 with reprex v2.0.2

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.