Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error for design.alpha(trt = 1:8, k = 2, r = 2) #5

Open
SchmidtPaul opened this issue Jan 31, 2023 · 3 comments
Open

Error for design.alpha(trt = 1:8, k = 2, r = 2) #5

SchmidtPaul opened this issue Jan 31, 2023 · 3 comments

Comments

@SchmidtPaul
Copy link

Hi, I just tried to run the following code and received this error:

library(agricolae)

r <- 2
k <- 2
trt <- 1:8

design.alpha(trt = trt, k = k, r = r)
#> Error in `[<-`(`*tmp*`, i, 2, value = alpha[i - 1, 2] + 1): Indizierung außerhalb der Grenzen

Created on 2023-01-31 with reprex v2.0.2

According to the details of the function's documentation we should have case I.

Parameters for the alpha design: I. r=2, k <= s; II. r=3, s odd, k <= s; III.r=3, s even, k <= s-1; IV. r=4, s odd but not a multiple of 3, k<=s
r= replications s=number of blocks k=size of block Number of treatment is equal to k*s

Hence, r = 2 ✔️ and since s = length(trt)/k = 4, we also have k <= s ✔️

As a consequence, we end up in the respective if statement if (r == 2 & k<=s ) (click for permalink to code on github):

        if (r == 2 & k<=s  ) {
            alpha <- matrix(0, nrow = k, ncol = r)
            alpha[2, 2] <- 1
            for (i in 3:k) {
                alpha[i, 2] <- alpha[i - 1, 2] + 1
            }
            serie <- "I"
        }

However, the for statement has a 3:k in it, which - I guess - only works for k >= 3?

So I am not sure - is this intended because r=2 & k=2 is too small? Or what am I missing?

@SchmidtPaul
Copy link
Author

Furthermore, it does work in {FielDHub}:

r <- 2
k <- 2
trt <- 1:8

length(trt) / k # = s
#> [1] 4

out <- FielDHub::alpha_lattice(t = length(trt),
                        k = k,
                        r = r)

out
#> Alpha Lattice Design 
#> 
#> Information on the design parameters: 
#> List of 7
#>  $ Reps            : num 2
#>  $ iBlocks         : num 4
#>  $ NumberTreatments: int 8
#>  $ NumberLocations : num 1
#>  $ Locations       : int 1
#>  $ seed            : num 5397
#>  $ lambda          : num 0.286
#> 
#>  10 First observations of the data frame with the alpha_lattice field book: 
#>    ID LOCATION PLOT REP IBLOCK UNIT ENTRY TREATMENT
#> 1   1        1  101   1      1    1     1       G-1
#> 2   2        1  102   1      1    2     3       G-3
#> 3   3        1  103   1      2    1     2       G-2
#> 4   4        1  104   1      2    2     6       G-6
#> 5   5        1  105   1      3    1     8       G-8
#> 6   6        1  106   1      3    2     5       G-5
#> 7   7        1  107   1      4    1     7       G-7
#> 8   8        1  108   1      4    2     4       G-4
#> 9   9        1  201   2      1    1     4       G-4
#> 10 10        1  202   2      1    2     2       G-2

Created on 2023-01-31 with reprex v2.0.2

@Sherry520
Copy link
Contributor

Yes, it works only for k>=3 when r=2.

if (r == 2 & k<=s ) {
alpha <- matrix(0, nrow = k, ncol = r)
alpha[2, 2] <- 1
for (i in 3:k) {
alpha[i, 2] <- alpha[i - 1, 2] + 1
}
serie <- "I"
}

@SchmidtPaul
Copy link
Author

Thanks for the reply @Sherry520
So I understand that the code only works for k>=3 when r=2, yes.
But aren't real-life alpha designs possible with r=2 and k=2? I show above that FielDHub can do it. Should the code of {agricolae} not be adjusted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants