Need help to randomized a data frame

I everybody !

I need some help for my little research project this summer. I make a bait trial to measured the capture rate of the small indian mongoose among five different bait. My set up is composed of 15 traps and I want to collect data during 15 days. I want to make a rotation of the bait everyday to make sure that the capture rate according to the different bait type be due to a dietary preference. So, if i have 15 traps and 5 bait types, I want to have 3 traps of each bait everyday. The problem is the following : I find some code on the internet for the "randomized block design", but I don't figured out how to translate that to my situation.

For example, I tried this code :

trt = letters[1:5] # I have 5 treatments (5 bait types)
design.lsd(trt=treatment, r=15)

and the result is the following :

$sketch
[,1] [,2] [,3] [,4] [,5]
[1,] "d" "e" "b" "c" "a"
[2,] "a" "b" "d" "e" "c"
[3,] "b" "c" "e" "a" "d"
[4,] "e" "a" "c" "d" "b"
[5,] "c" "d" "a" "b" "e"

$book
plots row col treatment
1 101 1 1 d
2 102 1 2 e
3 103 1 3 b
4 104 1 4 c
5 105 1 5 a
6 201 2 1 a
7 202 2 2 b
8 203 2 3 d
9 204 2 4 e
10 205 2 5 c
11 301 3 1 b
12 302 3 2 c
13 303 3 3 e
14 304 3 4 a
15 305 3 5 d
16 401 4 1 e
17 402 4 2 a
18 403 4 3 c
19 404 4 4 d
20 405 4 5 b
21 501 5 1 c
22 502 5 2 d
23 503 5 3 a
24 504 5 4 b
25 505 5 5 e

So, I think it's a good start because I randomized my bait types for each traps for everyday, but I search something like that :

        Days 

Trap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
1 A
2 C
3 B
4 D
5 E
6 B
7 E
8 A
9 D
10 C
11 C
12 A
13 E
14 B
15 D

I show one colomn to show what kind of table I want to make

I hope that my question was clear and thanks a lot for your help !

Welcome to the community!

design.lsd function provided in the agricolae package is for Latin Square Designs, which eliminates two sources of nuisance variability. On the other hand, Randomised Block Designs controls one source of nuisance variability. Please do correct me if I'm wrong, but I don't think you are considering any nuisance variability at all, so you just need Completely Randomised Designs.

But you can do it without any package. Here's a way to do it:

set.seed(seed = 32646)

trt <- letters[1:5]
r <- 3

replicate(n = 15,
          expr = sample(x = rep(x = trt,
                                times = r)))
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
#>  [1,] "e"  "b"  "d"  "e"  "a"  "e"  "c"  "d"  "c"  "b"   "b"   "a"   "e"  
#>  [2,] "a"  "c"  "a"  "b"  "a"  "a"  "c"  "c"  "d"  "c"   "c"   "b"   "e"  
#>  [3,] "e"  "e"  "c"  "c"  "e"  "d"  "e"  "a"  "a"  "c"   "a"   "c"   "b"  
#>  [4,] "d"  "c"  "b"  "e"  "e"  "a"  "a"  "b"  "e"  "c"   "d"   "d"   "a"  
#>  [5,] "a"  "d"  "e"  "a"  "c"  "c"  "e"  "b"  "c"  "b"   "c"   "c"   "c"  
#>  [6,] "a"  "b"  "d"  "b"  "d"  "b"  "c"  "d"  "e"  "a"   "c"   "e"   "a"  
#>  [7,] "b"  "a"  "c"  "d"  "a"  "b"  "e"  "a"  "d"  "e"   "a"   "a"   "b"  
#>  [8,] "d"  "a"  "b"  "a"  "c"  "e"  "d"  "c"  "c"  "e"   "e"   "a"   "c"  
#>  [9,] "c"  "a"  "a"  "c"  "d"  "e"  "b"  "a"  "a"  "a"   "d"   "b"   "d"  
#> [10,] "e"  "e"  "e"  "c"  "d"  "d"  "b"  "b"  "b"  "d"   "a"   "d"   "a"  
#> [11,] "b"  "e"  "e"  "e"  "e"  "a"  "a"  "e"  "b"  "e"   "d"   "c"   "b"  
#> [12,] "c"  "d"  "c"  "b"  "b"  "c"  "b"  "c"  "b"  "d"   "b"   "e"   "c"  
#> [13,] "b"  "b"  "b"  "a"  "b"  "c"  "a"  "e"  "a"  "d"   "e"   "e"   "e"  
#> [14,] "d"  "c"  "d"  "d"  "b"  "d"  "d"  "e"  "e"  "a"   "e"   "d"   "d"  
#> [15,] "c"  "d"  "a"  "d"  "c"  "b"  "d"  "d"  "d"  "b"   "b"   "b"   "d"  
#>       [,14] [,15]
#>  [1,] "c"   "b"  
#>  [2,] "d"   "a"  
#>  [3,] "e"   "a"  
#>  [4,] "e"   "c"  
#>  [5,] "a"   "e"  
#>  [6,] "e"   "d"  
#>  [7,] "d"   "c"  
#>  [8,] "c"   "a"  
#>  [9,] "b"   "d"  
#> [10,] "c"   "b"  
#> [11,] "b"   "b"  
#> [12,] "b"   "c"  
#> [13,] "a"   "e"  
#> [14,] "a"   "d"  
#> [15,] "d"   "e"

Created on 2019-06-08 by the reprex package (v0.3.0)

There are \frac{(5 \times 3)!}{(3!) ^ 5} possibilities, and you need just 15. So unless you're unlucky, you won't get repetitions.

Hope this helps.

PS: I suppose you can also use replicate(n = 15, expr = agricolae::design.crd(trt = trt, r = r)$book$trt)

Thank you so much for your help, that was very helpful and that's exactly what i'm trying to make !

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