Calculating the design

A full run of the three wrapper functions is executed below, printing messages on the level of processing steps, but not the iterations within every optimization.

set.seed(44)

# Assign treatments to animals, respecting user provided as well as passed constraints
design_trt <- InVivo_assignTreatments(invivo_study_samples, invivo_study_treatments,
  form_cages_by = c("Strain", "Sex", "Litter_combine_females"),
  balance_treatment_vars = c("Strain", "Sex", "ArrivalWeight", "AgeGroup"),
  n_shuffle = c(rep(5, 200), rep(3, 300), rep(2, 500), rep(1, 3000)),
  quiet_process = FALSE,
  quiet_optimize = TRUE
)
#> Performing treatment assignment with constrained animal selection.
#> Using constraints in variables: Strain, Sex
#> Checking if solution is possible:
#>    ... Yes!
#> Setting up batch container.
#> Constructing scoring functions:
#>      ... user specified treatment allocation constraint (Treatment-Strain-Sex)
#>      ... facilitating homogeneity of treatment in cages (CageGroup)
#>      ... ANOVA -logP for numerical variables balanced across treatment (ArrivalWeight, AgeGroup)
#> Success. User provided constraints could be fully met.

# Form cages with reasonable animal numbers and compliant with all constraints
design_cage <- Invivo_assignCages(design_trt,
  cagegroup_vars = c("Treatment", "Strain", "Sex", "Litter_combine_females"),
  unique_vars = c("Earmark"),
  balance_cage_vars = c("ArrivalWeight", "AgeGroup"),
  n_min = 2, n_max = 5, n_ideal = 2, prefer_big_groups = T, strict = F,
  maxiter = 1000,
  quiet_process = FALSE,
  quiet_optimize = TRUE
)
#> Setting up batch container.
#> 
#> Formed 22 homogeneous groups using 59 samples.
#> 27 subgroups needed to satisfy size constraints.
#> 
#> Finding possible ways to allocate variable of interest with 1 levels ...
#> 
#> Finished with 27 recursive calls.
#> 1 allocations found.
#> 
#> Expecting 27 cages to be created and 4 single-housed animals.
#> Constructing scoring functions:
#>      ... ANOVA -logP for numerical variables balanced across cages (ArrivalWeight, AgeGroup)
#> Adding 4 attributes to samples.

# Arrange cages in sub-grid of one rack (or several racks), avoiding spatial clusters
design_rack <- Invivo_arrangeCages(design_cage,
  distribute_cagerack_vars = c("Treatment", "Strain", "Sex"),
  rack_size_x = 7,
  rack_size_y = 10,
  n_shuffle = c(rep(5, 100), rep(3, 200), rep(2, 300), rep(1, 500)),
  quiet_process = FALSE,
  quiet_optimize = TRUE
)
#> Needing 1 rack with a grid of 4 x 7 cages.
#> There will be 1 empty position overall.
#> Setting up batch container.
#> 
#> Distributing target variables (Treatment, Strain, Sex) within rack
#>    ... Rack 1
#> ... Performing simple mean/stddev adjustment.
#>    ... final scores: Plate_Treatment: 5.12, Plate_Strain: 5.48, Plate_Sex: 5.72

Visualization of the study design

Cage composition

There are 27 cages in total.

Strains and age groups should be evenly split (balanced) across the treatments. Also,in each cage there should be only animals with the same treatment, strain and sex.

Females are exclusively used for treatment 2, as was specified in the treatment list.

Body weights

Body weights should be balanced across treatments as well as possible.

The plot illustrates that this is true for the overall weight distribution (box plots). Interestingly, as there are females (associated with considerable less body weight) involved in treatment 2, the optimization favored the selection of heavier males in this group to compensate, achieving better cross-treatment balance of this factor.

Red diamonds mark the mean values for a specific sex within each treatment group.

Cage arrangement in rack

The following plots show the organization of the cage rack, individual cages colored by different variables each time.

Individual animals in cages

Finally, an overview plot illustrates the placement of animals in the cages. Notice the distinct earmarks within each cage, a ‘soft’ design constraint that could be achieved with the given solution.