The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

An introduction to gexp package

Ivan Bezerra Allaman
José Cláudio Faria

2023-06-20

The gexp package was elaborated inspired by the personal functions of Professor José Cláudio Faria, whose objective is to generate one or p random variables according to the type of experiment, whose effects of the treatments are indicated by the user.

Most packages like agricolae, for example, have functions that allow the user to generate only designs, thus helping the researcher who wants to set up an experiment. However, if the user has the interest in generating random variables according to the type of experiment and still, being able to manipulate which treatments will be different, then the gexp package has this differential.

The experiments included in the package are: a completely randomized design (CRD), randomized complete block design (RCBD), latin square design (LSD), factorial schemes considering CRD, DBC and DQL designs and a schema in split-plots also considering the CRD, RCBD and LSD designs (Aquino 1992).

The arguments of the function are based on a linear model with the following matrix form (Ferreira (2008), Rencher and Schaalje (2007)):

\[Y = X\beta + E \hspace{5cm} (1)\]

then:

Y is a n\(\times\)p matrix, with n observation of p random variables;

X is a n\(\times\)m matrix, where m is the number of parameters that influence the response variable (\(\mu, \alpha's, \beta's, etc.\));

\(\beta\) is a m\(\times\)p matrix of factors effects;

\(E\) is a n\(\times\)p matrix of the errors with p-variate normal distribution with mean vectors 0 and \(\Sigma\) covariance;

In the case of the split-plot design, the package works considering the following linear mixed model (Naes, Aastveit, and Sahni 2007):

\[Y = X\beta + Zu + E \hspace{5cm} (2)\]

then:

Z is a n\(\times\)q matrix, where q is the number of parameters of the interaction that influence the plot error (CRD - repetition:\(\alpha\), RCBD - block:\(\alpha\), LSD - row:column:\(\alpha\));

u is a q\(\times\)p matrix of the plot errors with p-variate normal distribution with mean vectors 0 and \(\Sigma_{plot}\) covariance;

\(E\) is a n\(\times\)p matrix of the errors with p-variate normal distribution with mean vectors 0 and \(\Sigma_{sub-plot}\) covariance of subplot;

The other components of the equation 2 are analogous to equation 1.

The symbology adopted was as follows:

Sources of Variation Symbol
Treatments \(\alpha,\tau\)
Block \(\beta\)
Interaction \(\gamma\)
Row block \(\eta\)
Column block \(\delta\)

The multivariate case, will only be addressed in the CRD, because for the other designs the reasoning is the same.

Simulating an Completely Randomized Design (CRD)

Univariate case

Let us assume that we want to generate a single random variable according to a CRD with a factor and two levels being 3 replicates. Then we can denote \(Y_{ik}\) as being the random variable observed in the k-th experimental unit (k = 1, 2, 3) that received the i-th level of factor X1 (i = 1,2). Also, assuming that this variable is under the effect of a constant (\(\mu = 15\)) and each level of the factor under study influence \(\alpha_1 = 1\) and \(\alpha_2 = -2\) the response variable respectively, we will have the following matrix configuration:

\[ \begin{eqnarray} \begin{bmatrix} Y_{11} \\ Y_{21} \\ Y_{12} \\ Y_{22} \\ Y_{13} \\ Y_{23} \end{bmatrix} &=& \begin{array}{p{5cm}} \begin{matrix} \mu & \!\scriptsize{x11}\! & \scriptsize{x12} \end{matrix}\\ \left[\begin{array}{c|cc} 1\hphantom{0} & 1\hphantom{0} & 0 \\ 1\hphantom{0} & 0\hphantom{0} & 1 \\ 1\hphantom{0} & 1\hphantom{0} & 0 \\ 1\hphantom{0} & 0\hphantom{0} & 1 \\ 1\hphantom{0} & 1\hphantom{0} & 0 \\ 1\hphantom{0} & 0\hphantom{0} & 1 \end{array}\right] \end{array} \cdot \begin{bmatrix} \mu \\ \alpha_{1} \\ \alpha_{2} \\ \end{bmatrix} + \begin{bmatrix} e_{11} \\ e_{21} \\ e_{12} \\ e_{22} \\ e_{13} \\ e_{23} \end{bmatrix} \\ &=& \begin{array}{c} \begin{matrix} \mu & \!\scriptsize{x11}\! & \scriptsize{x12} \end{matrix}\\ \left[\begin{array}{c|cc} 1\hphantom{0} & 1\hphantom{0} & 0 \\ 1\hphantom{0} & 0\hphantom{0} & 1 \\ 1\hphantom{0} & 1\hphantom{0} & 0 \\ 1\hphantom{0} & 0\hphantom{0} & 1 \\ 1\hphantom{0} & 1\hphantom{0} & 0 \\ 1\hphantom{0} & 0\hphantom{0} & 1 \end{array}\right] \end{array} \cdot \begin{bmatrix} 15 \\ 1 \\ -2 \\ \end{bmatrix} + \begin{bmatrix} e_{11} \\ e_{21} \\ e_{12} \\ e_{22} \\ e_{13} \\ e_{23} \end{bmatrix} \\ &=& \begin{bmatrix} 16 \\ 13 \\ 16 \\ 13 \\ 16 \\ 13 \end{bmatrix} + \begin{bmatrix} e_{11} \\ e_{21} \\ e_{12} \\ e_{22} \\ e_{13} \\ e_{23} \end{bmatrix} \end{eqnarray} \]

If we consider an error with mean 0 and variance 0 then we have the following simulated random variable:

\[ \begin{bmatrix} Y_{11} \\ Y_{21} \\ Y_{12} \\ Y_{22} \\ Y_{13} \\ Y_{23} \end{bmatrix} = \begin{bmatrix} 16 \\ 13 \\ 16 \\ 13 \\ 16 \\ 13 \end{bmatrix} \]

With the gexp package we have:

library(gexp)
crd <- gexp(mu   = 15,
            err  = matrix(rep(0, 6),
                          nrow = 6),
            r    = 3,
            fe   = list(alpha = c(1, -2)))
summary(crd)
#> Database 
#>   r  X1 Y1
#> 1 1 x11 16
#> 2 2 x11 16
#> 3 3 x11 16
#> 4 1 x12 13
#> 5 2 x12 13
#> 6 3 x12 13

Multivariate Case

Let us now assume that we want to generate two random variables by considering the same number of factors and the same number of repetitions of the previous case. Then we can denote \(Y_{ikl}\) as being the lth random variable (l = 1,2) observed in the k-th experimental unit (k = 1,2,3) that received the i-th factor level X1 (i = 1,2). Also, assuming that this variable is under the effect of a constant (\(\mu_1 = 15\) and \(\mu_2 = 6\)) and each level of the factor under study influence \(\alpha_{11} = 1\) and \(\alpha_{21} = -2\) the variable 1 and, \(\alpha_{12} = 2\) and \(\alpha_{22} = 3\) the variable 2, we will have the following matrix configuration:

\[ \begin{eqnarray} \begin{bmatrix} Y_{111} & Y_{112} \\ Y_{211} & Y_{212} \\ Y_{121} & Y_{122} \\ Y_{221} & Y_{222} \\ Y_{131} & Y_{132} \\ Y_{231} & Y_{232} \end{bmatrix} &=& \begin{array}{c} \begin{matrix} \mu & \!\scriptsize{x11}\! & \scriptsize{x12} \end{matrix}\\ \left[\begin{array}{c|cc} 1\hphantom{0} & 1\hphantom{0} & 0 \\ 1\hphantom{0} & 0\hphantom{0} & 1 \\ 1\hphantom{0} & 1\hphantom{0} & 0 \\ 1\hphantom{0} & 0\hphantom{0} & 1 \\ 1\hphantom{0} & 1\hphantom{0} & 0 \\ 1\hphantom{0} & 0\hphantom{0} & 1 \end{array}\right] \end{array} \cdot \begin{bmatrix} \mu_1 & \mu_2 \\ \alpha_{11} & \alpha_{12} \\ \alpha_{21} & \alpha_{22} \\ \end{bmatrix} + \begin{bmatrix} e_{111} & e_{112} \\ e_{211} & e_{212} \\ e_{121} & e_{122} \\ e_{221} & e_{222} \\ e_{131} & e_{132} \\ e_{231} & e_{232} \end{bmatrix} \\ &=& \begin{array}{c} \begin{matrix} \mu & \!\scriptsize{x11}\! & \scriptsize{x12} \end{matrix}\\ \left[\begin{array}{c|cc} 1\hphantom{0} & 1\hphantom{0} & 0 \\ 1\hphantom{0} & 0\hphantom{0} & 1 \\ 1\hphantom{0} & 1\hphantom{0} & 0 \\ 1\hphantom{0} & 0\hphantom{0} & 1 \\ 1\hphantom{0} & 1\hphantom{0} & 0 \\ 1\hphantom{0} & 0\hphantom{0} & 1 \end{array}\right] \end{array} \cdot \begin{bmatrix} 15 & 6 \\ 1 & 2 \\ -2 & 3 \\ \end{bmatrix} + \begin{bmatrix} e_{111} & e_{112} \\ e_{211} & e_{212} \\ e_{121} & e_{122} \\ e_{221} & e_{222} \\ e_{131} & e_{132} \\ e_{231} & e_{232} \end{bmatrix} \\ &=& \begin{bmatrix} 16 & 8 \\ 13 & 9 \\ 16 & 8 \\ 13 & 9 \\ 16 & 8 \\ 13 & 9 \end{bmatrix} + \begin{bmatrix} e_{111} & e_{112} \\ e_{211} & e_{212} \\ e_{121} & e_{122} \\ e_{221} & e_{222} \\ e_{131} & e_{132} \\ e_{231} & e_{232} \end{bmatrix} \end{eqnarray} \]

If we consider an error with averages 0 and a matrix of variance-covariance 0 then we will have the following simulated random variables:

\[ \begin{bmatrix} Y_{111} & Y_{112} \\ Y_{211} & Y_{212} \\ Y_{121} & Y_{122} \\ Y_{221} & Y_{222} \\ Y_{131} & Y_{132} \\ Y_{231} & Y_{232} \end{bmatrix} = \begin{bmatrix} 16 & 8 \\ 13 & 9 \\ 16 & 8 \\ 13 & 9 \\ 16 & 8 \\ 13 & 9 \end{bmatrix} \]

With the gexp package we have:

crd_mv <- gexp(mu = c(15, 6),
               err = matrix(c(0, 0,
                              0, 0,
                              0, 0,
                              0, 0,
                              0, 0,
                              0, 0), 
                            ncol = 2),
               r = 3L,
               fe = list(alpha = matrix(c(1, -2,
                                           2,  3), 
                                         ncol = 2)))
summary(crd_mv)
#> Database 
#>   r  X1 Y1 Y2
#> 1 1 x11 16  8
#> 2 2 x11 16  8
#> 3 3 x11 16  8
#> 4 1 x12 13  9
#> 5 2 x12 13  9
#> 6 3 x12 13  9

Simulating a Randomized Completely Block Design (RCBD)

Assuming we want to generate a single random variable according to a RCBD with a factor and two levels being a block with three levels. Then we can denote \(Y_ {ij}\) as the random variable observed in the j-th block (j = 1, 2, 3) that received the i-th level of factor X1 (i = 1, 2). Also, assuming that this variable is under the effect of a constant (\(\mu = 15\)) and each level of the factor under study influence \(\alpha_1 = 1\) and \(\alpha_2 = -2\) the variable response respectively, and each block influences in \(\beta_1 = 2, \beta_2 = 4\) and \(\beta_3 = 6\) respectively, we will have the following matrix configuration:

\[ \begin{eqnarray} \begin{bmatrix} Y_{11} \\ Y_{21} \\ Y_{12} \\ Y_{22} \\ Y_{13} \\ Y_{23} \end{bmatrix} &=& \begin{array}{c} \begin{matrix} \mu & \!\scriptsize{x11}\!&\scriptsize{x12}\hphantom{0}&\scriptsize{b1}&\scriptsize{b2}&\scriptsize{b3} \end{matrix}\\ \left[\begin{array}{c|cc|ccc} 1 & 1\hphantom{0}& 0\hphantom{0}& 1\hphantom{0}& 0\hphantom{0}& 0\\ 1 & 0\hphantom{0}& 1\hphantom{0}& 1\hphantom{0}& 0\hphantom{0}& 0\\ 1 & 1\hphantom{0}& 0\hphantom{0}& 0\hphantom{0}& 1\hphantom{0}& 0\\ 1 & 0\hphantom{0}& 1\hphantom{0}& 0\hphantom{0}& 1\hphantom{0}& 0\\ 1 & 1\hphantom{0}& 0\hphantom{0}& 0\hphantom{0}& 0\hphantom{0}& 1\\ 1 & 0\hphantom{0}& 1\hphantom{0}& 0\hphantom{0}& 0\hphantom{0}& 1\\ \end{array}\right] \end{array} \cdot \begin{bmatrix} \mu \\ \alpha_1 \\ \alpha_2 \\ \beta_1 \\ \beta_2 \\ \beta_3 \\ \end{bmatrix} + \begin{bmatrix} e_{11} \\ e_{21} \\ e_{12} \\ e_{22} \\ e_{13} \\ e_{23} \end{bmatrix} \\ &=& \begin{array}{c} \begin{matrix} \mu & \!\scriptsize{x11}\!&\scriptsize{x12}\hphantom{0}&\scriptsize{b1}&\scriptsize{b2}&\scriptsize{b3} \end{matrix}\\ \left[\begin{array}{c|cc|ccc} 1 & 1\hphantom{0}& 0\hphantom{0}& 1\hphantom{0}& 0\hphantom{0}& 0\\ 1 & 0\hphantom{0}& 1\hphantom{0}& 1\hphantom{0}& 0\hphantom{0}& 0\\ 1 & 1\hphantom{0}& 0\hphantom{0}& 0\hphantom{0}& 1\hphantom{0}& 0\\ 1 & 0\hphantom{0}& 1\hphantom{0}& 0\hphantom{0}& 1\hphantom{0}& 0\\ 1 & 1\hphantom{0}& 0\hphantom{0}& 0\hphantom{0}& 0\hphantom{0}& 1\\ 1 & 0\hphantom{0}& 1\hphantom{0}& 0\hphantom{0}& 0\hphantom{0}& 1\\ \end{array}\right] \end{array} \cdot \begin{bmatrix} 15 \\ 1 \\ -2 \\ 2 \\ 4 \\ 6 \end{bmatrix} + \begin{bmatrix} e_{11} \\ e_{21} \\ e_{12} \\ e_{22} \\ e_{13} \\ e_{23} \end{bmatrix} \\ &=& \begin{bmatrix} 18 \\ 15 \\ 20 \\ 17 \\ 22 \\ 19 \end{bmatrix} + \begin{bmatrix} e_{11} \\ e_{21} \\ e_{12} \\ e_{22} \\ e_{13} \\ e_{23} \end{bmatrix} \end{eqnarray} \]

Assuming an error with mean 0 and variance 0, we have:

\[ \begin{bmatrix} Y_{11} \\ Y_{21} \\ Y_{12} \\ Y_{22} \\ Y_{13} \\ Y_{23} \end{bmatrix} = \begin{bmatrix} 18 \\ 15 \\ 20 \\ 17 \\ 22 \\ 19 \end{bmatrix} \]

With the gexp package we have:

rcbd <- gexp(mu = 15,
             r = 1,
             err = matrix(rep(0, 6),
                           nrow = 6),
             fe = list(alpha = c(1, -2)),
             blke = c(2, 4, 6),
             design = 'RCBD')
summary(rcbd)
#> Database 
#>   r Block  X1 Y1
#> 1 1     1 x11 18
#> 2 1     2 x11 20
#> 3 1     3 x11 22
#> 4 1     1 x12 15
#> 5 1     2 x12 17
#> 6 1     3 x12 19

Simulating a Latin Square Design (LSD)

Assuming we want to generate a single random variable according to a LSD with a factor and three levels, with a blocking factor in the row sense with three levels and another blocking factor in the column sense with three levels. Then we can denote \(Y_{rci}\) as being the random variable observed in the c-th column (c = 1, 2, 3) and r-th row (r = 1, 2, 3) that received the i-th level of factor X1 (i = 1, 2, 3). Also, assuming this variable is under the effect of a constant (\(\mu = 15\)) and each level of the factor under study influence \(\alpha_1 = 1, \alpha_2 = -2\) e \(\alpha_3 = 3\) the response variable respectively, each row influencing in \(\eta_1 = 2,\eta_2 = 3\) and \(\eta_3 = 4\) respectively and each column influencing in \(\delta_1 = 6, \delta_2 = 7\) and \(\delta_3 = 8\) respectively we will have the following matrix configuration:

\[ \begin{eqnarray} \begin{bmatrix} Y_{111} \\ Y_{122} \\ Y_{133} \\ Y_{212} \\ Y_{223} \\ Y_{231} \\ Y_{313} \\ Y_{321} \\ Y_{332} \end{bmatrix} &=& \begin{array}{c} \begin{matrix} \mu & \!\scriptsize{r1}\!&\scriptsize{r2}&\scriptsize{r3}&\scriptsize{c1}&\scriptsize{c2}&\scriptsize{c3}&\scriptsize{x11}&\scriptsize{x12}&\scriptsize{x13} \end{matrix}\\ \left[\begin{array}{c|ccc|ccc|ccc} 1&1&0&0\hphantom{0}&1&0\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\\ 1&1&0&0\hphantom{0}&0&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\\ 1&1&0&0\hphantom{0}&0&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\\ 1&0&1&0\hphantom{0}&1&0\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\\ 1&0&1&0\hphantom{0}&0&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\\ 1&0&1&0\hphantom{0}&0&0\hphantom{0}&1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\\ 1&0&0&1\hphantom{0}&1&0\hphantom{0}&0\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\\ 1&0&0&1\hphantom{0}&0&1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\\ 1&0&0&1\hphantom{0}&0&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\\ \end{array}\right] \end{array} \cdot \begin{bmatrix} \mu \\ \eta_1 \\ \eta_2 \\ \eta_3 \\ \delta_1 \\ \delta_2 \\ \delta_3 \\ \alpha_1 \\ \alpha_2 \\ \alpha_3 \\ \end{bmatrix} + \begin{bmatrix} e_{111} \\ e_{122} \\ e_{133} \\ e_{212} \\ e_{223} \\ e_{231} \\ e_{313} \\ e_{321} \\ e_{332} \end{bmatrix} \\ &=& \begin{array}{c} \begin{matrix} \mu & \!\scriptsize{r1}\!&\scriptsize{r2}&\scriptsize{r3}&\scriptsize{c1}&\scriptsize{c2}&\scriptsize{c3}&\scriptsize{x11}&\scriptsize{x12}&\scriptsize{x13} \end{matrix}\\ \left[\begin{array}{c|ccc|ccc|ccc} 1&1&0&0\hphantom{0}&1&0\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\\ 1&1&0&0\hphantom{0}&0&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\\ 1&1&0&0\hphantom{0}&0&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\\ 1&0&1&0\hphantom{0}&1&0\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\\ 1&0&1&0\hphantom{0}&0&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\\ 1&0&1&0\hphantom{0}&0&0\hphantom{0}&1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\\ 1&0&0&1\hphantom{0}&1&0\hphantom{0}&0\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\\ 1&0&0&1\hphantom{0}&0&1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\\ 1&0&0&1\hphantom{0}&0&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\\ \end{array}\right] \end{array} \cdot \begin{bmatrix} 15 \\ 2 \\ 3 \\ 4 \\ 6 \\ 7 \\ 8 \\ 1 \\ -2 \\ 3 \\ \end{bmatrix} + \begin{bmatrix} e_{111} \\ e_{122} \\ e_{133} \\ e_{212} \\ e_{223} \\ e_{231} \\ e_{313} \\ e_{321} \\ e_{332} \end{bmatrix} \\ &=& \begin{bmatrix} 24 \\ 22 \\ 28 \\ 22 \\ 28 \\ 27 \\ 28 \\ 27 \\ 25 \\ \end{bmatrix} + \begin{bmatrix} e_{111} \\ e_{122} \\ e_{133} \\ e_{212} \\ e_{223} \\ e_{231} \\ e_{313} \\ e_{321} \\ e_{332} \end{bmatrix} \end{eqnarray} \]

Considering that the error has mean 0 and variance 0 we have:

\[ \begin{bmatrix} Y_{111} \\ Y_{122} \\ Y_{133} \\ Y_{212} \\ Y_{223} \\ Y_{231} \\ Y_{313} \\ Y_{321} \\ Y_{332} \end{bmatrix} = \begin{bmatrix} 24 \\ 22 \\ 28 \\ 22 \\ 28 \\ 27 \\ 28 \\ 27 \\ 25 \\ \end{bmatrix} \]

Using the gexp function we have:

lsd <- gexp(mu = 15,
            r = 1,
            err = matrix(rep(0, 9), 
                           nrow = 9),
            fe = list(alpha = c(1, -2, 3)),
            rowe = c(2, 3, 4),
            cole = c(6, 7, 8),
            design = 'LSD')
summary(lsd)
#> Database 
#>   Row Column  X1 Y1
#> 1   1      1 x11 24
#> 2   2      1 x12 22
#> 3   3      1 x13 28
#> 4   1      2 x12 22
#> 5   2      2 x13 28
#> 6   3      2 x11 27
#> 7   1      3 x13 28
#> 8   2      3 x11 27
#> 9   3      3 x12 25

Factorial Experiments

CRD

Considering that we want to generate a single random variable according to a CRD in a factorial scheme of type 2 x 3 (two levels of factor X1 and three levels of factor X2) with 2 replicates. Then we can denote \(Y_{ijk}\) as being the random variable observed in the k-th experimental unit (k = 1, 2) that received the i-th level of factor X1 (i = 1,2) and jth level of factor X2 (j = 1,2,3). Also, assuming this variable is under the effect of a constant (\(\mu = 15\)), and each level of factor X1 influences \(\alpha_1 = 1\) and \(\alpha_2 = -2\), each level of factor X2 influences in \(\tau_1 = 1, \tau_2 = -1\) and \(\tau_3 = 1\) and the effect of the interaction is \(\gamma_{11} = 3,\gamma_{21} = 1,\gamma_{12} = 1,\gamma_{22} = -5,\gamma_{13} = 1\) And \(\gamma_{23} = 1\) respectively, we shall have following matrix configuration:

\[ \begin{eqnarray} \begin{bmatrix} Y_{111} \\ Y_{211} \\ Y_{121} \\ Y_{221} \\ Y_{131} \\ Y_{231} \\ Y_{112} \\ Y_{212} \\ Y_{122} \\ Y_{222} \\ Y_{132} \\ Y_{232} \end{bmatrix} &=& \begin{array}{c} \begin{matrix} \hspace{0.2cm}\mu&\scriptsize{x11}&\scriptsize{x12}\hspace{0.1cm}&\scriptsize{x21}&\scriptsize{x22}&\scriptsize{x23}&\scriptsize{x11x21}&\scriptsize{x12x21}&\scriptsize{x11x22}&\scriptsize{x12x22}&\scriptsize{x11x23}&\scriptsize{x12x23}\hspace{0.6cm} \end{matrix}\\ \left[\begin{array}{c|cc|ccc|cccccc} 1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{000}&0\hphantom{0000}&0\hphantom{0000}&0\hphantom{0000}& 0\hphantom{0000}&0\hphantom{000}\\ 1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&0\hphantom{000}&1\hphantom{0000}&0\hphantom{0000}&0\hphantom{0000}& 0\hphantom{0000}&0\hphantom{000}\\ 1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{000}&0\hphantom{0000}&1\hphantom{0000}&0\hphantom{0000}& 0\hphantom{0000}&0\hphantom{000}\\ 1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{000}&0\hphantom{0000}&0\hphantom{0000}&1\hphantom{0000}& 0\hphantom{0000}&0\hphantom{000}\\ 1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{000}&0\hphantom{0000}&0\hphantom{0000}&0\hphantom{0000}& 1\hphantom{0000}&0\hphantom{000}\\ 1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{000}&0\hphantom{0000}&0\hphantom{0000}&0\hphantom{0000}& 0\hphantom{0000}&1\hphantom{000}\\ 1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{000}&0\hphantom{0000}&0\hphantom{0000}&0\hphantom{0000}& 0\hphantom{0000}&0\hphantom{000}\\ 1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&0\hphantom{000}&1\hphantom{0000}&0\hphantom{0000}&0\hphantom{0000}& 0\hphantom{0000}&0\hphantom{000}\\ 1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{000}&0\hphantom{0000}&1\hphantom{0000}&0\hphantom{0000}& 0\hphantom{0000}&0\hphantom{000}\\ 1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{000}&0\hphantom{0000}&0\hphantom{0000}&1\hphantom{0000}& 0\hphantom{0000}&0\hphantom{000}\\ 1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{000}&0\hphantom{0000}&0\hphantom{0000}&0\hphantom{0000}& 1\hphantom{0000}&0\hphantom{000}\\ 1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{000}&0\hphantom{0000}&0\hphantom{0000}&0\hphantom{0000}& 0\hphantom{0000}&1\hphantom{000}\\ \end{array}\right] \end{array} \cdot \begin{bmatrix} \mu \\ \alpha_1\\ \alpha_2\\ \tau_1\\ \tau_2\\ \tau_3\\ \gamma_{11}\\ \gamma_{21}\\ \gamma_{12}\\ \gamma_{22}\\ \gamma_{13}\\ \gamma_{23} \end{bmatrix} + \begin{bmatrix} e_{111} \\ e_{211} \\ e_{121} \\ e_{221} \\ e_{131} \\ e_{231} \\ e_{112} \\ e_{212} \\ e_{122} \\ e_{222} \\ e_{132} \\ e_{232} \end{bmatrix} \\ &=& \begin{array}{c} \begin{matrix} \hspace{0.2cm}\mu&\scriptsize{x11}&\scriptsize{x12}\hspace{0.1cm}&\scriptsize{x21}&\scriptsize{x22}&\scriptsize{x23}&\scriptsize{x11x21}&\scriptsize{x12x21}&\scriptsize{x11x22}&\scriptsize{x12x22}&\scriptsize{x11x23}&\scriptsize{x12x23}\hspace{0.6cm} \end{matrix}\\ \left[\begin{array}{c|cc|ccc|cccccc} 1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{000}&0\hphantom{0000}&0\hphantom{0000}&0\hphantom{0000}& 0\hphantom{0000}&0\hphantom{000}\\ 1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&0\hphantom{000}&1\hphantom{0000}&0\hphantom{0000}&0\hphantom{0000}& 0\hphantom{0000}&0\hphantom{000}\\ 1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{000}&0\hphantom{0000}&1\hphantom{0000}&0\hphantom{0000}& 0\hphantom{0000}&0\hphantom{000}\\ 1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{000}&0\hphantom{0000}&0\hphantom{0000}&1\hphantom{0000}& 0\hphantom{0000}&0\hphantom{000}\\ 1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{000}&0\hphantom{0000}&0\hphantom{0000}&0\hphantom{0000}& 1\hphantom{0000}&0\hphantom{000}\\ 1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{000}&0\hphantom{0000}&0\hphantom{0000}&0\hphantom{0000}& 0\hphantom{0000}&1\hphantom{000}\\ 1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{000}&0\hphantom{0000}&0\hphantom{0000}&0\hphantom{0000}& 0\hphantom{0000}&0\hphantom{000}\\ 1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&0\hphantom{000}&1\hphantom{0000}&0\hphantom{0000}&0\hphantom{0000}& 0\hphantom{0000}&0\hphantom{000}\\ 1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{000}&0\hphantom{0000}&1\hphantom{0000}&0\hphantom{0000}& 0\hphantom{0000}&0\hphantom{000}\\ 1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{000}&0\hphantom{0000}&0\hphantom{0000}&1\hphantom{0000}& 0\hphantom{0000}&0\hphantom{000}\\ 1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{000}&0\hphantom{0000}&0\hphantom{0000}&0\hphantom{0000}& 1\hphantom{0000}&0\hphantom{000}\\ 1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{000}&0\hphantom{0000}&0\hphantom{0000}&0\hphantom{0000}& 0\hphantom{0000}&1\hphantom{000}\\ \end{array}\right] \end{array} \cdot \begin{bmatrix} 15 \\ 1\\ -2\\ 1\\ -1\\ 1\\ 3\\ 1\\ 1\\ -5\\ 1\\ 1 \end{bmatrix} + \begin{bmatrix} e_{111} \\ e_{211} \\ e_{121} \\ e_{221} \\ e_{131} \\ e_{231} \\ e_{112} \\ e_{212} \\ e_{122} \\ e_{222} \\ e_{132} \\ e_{232} \end{bmatrix} \\ &=& \begin{bmatrix} 20 \\ 15\\ 16\\ 7\\ 18\\ 15\\ 20\\ 15\\ 16\\ 7\\ 18\\ 15 \end{bmatrix} + \begin{bmatrix} e_{111} \\ e_{211} \\ e_{121} \\ e_{221} \\ e_{131} \\ e_{231} \\ e_{112} \\ e_{212} \\ e_{122} \\ e_{222} \\ e_{132} \\ e_{232} \end{bmatrix} \end{eqnarray} \]

Considering that the error has mean 0 and variance 0 we have:

\[ \begin{bmatrix} Y_{111} \\ Y_{211} \\ Y_{121} \\ Y_{221} \\ Y_{131} \\ Y_{231} \\ Y_{112} \\ Y_{212} \\ Y_{122} \\ Y_{222} \\ Y_{132} \\ Y_{232} \end{bmatrix} = \begin{bmatrix} 20 \\ 15\\ 16\\ 7\\ 18\\ 15\\ 20\\ 15\\ 16\\ 7\\ 18\\ 15 \end{bmatrix} \]

Using the gexp function we have:

FE_crd <- gexp(mu = 15,
               r = 2, 
               err = matrix(rep(0, 12),
                            nrow = 12),
               fe = list(alpha = c(1, -2),
                         tau = c(1, -1, 1)),
               inte = c(3, 1, 1, 
                        -5, 1, 1),
               type = 'FE')
summary(FE_crd)
#> Database 
#>    r  X1  X2 Y1
#> 1  1 x11 x21 20
#> 2  2 x11 x21 20
#> 3  1 x12 x21 15
#> 4  2 x12 x21 15
#> 5  1 x11 x22 16
#> 6  2 x11 x22 16
#> 7  1 x12 x22  7
#> 8  2 x12 x22  7
#> 9  1 x11 x23 18
#> 10 2 x11 x23 18
#> 11 1 x12 x23 15
#> 12 2 x12 x23 15

Split-plot experiments

CRD

Supondo que queiramos gerar uma variável aleatória segundo um DIC em parcelas subdivididas com dois níveis do fator X1 na parcela e dois níveis do fator X2 na subparcela com 3 repetições. Então, podemos denominar \(Y_{ijk}\) como sendo a variável aleatória observada na subparcela na k-ésima unidade experimental (k = 1, 2 e 3) que recebeu o i-ésimo nível do fator X1 (i=1,2) e j-ésimo nível do fator X2 (j=1,2). Ainda, supondo que esta variável esteja sob o efeito de uma constante (\(\mu=15\)), e cada nível do fator X1 influenciem em \(\alpha_{1}=1\) e \(\alpha_{2}=-2\), cada nível do fator X2 influenciam em \(\tau_{1}=1\) e \(\tau_{2}=-1\) e que o efeito da interação seja de \(\gamma_{11}=3, \gamma_{21}=1, \gamma_{12}=1\) e \(\gamma_{22}=-5\) respectivamente, teremos a seguinte configuração matricial conforme a equação 2.

Portanto, tem-se a seguinte configuração matricial:

\[ \begin{eqnarray} \begin{bmatrix} Y_{111} \\ Y_{211} \\ Y_{121} \\ Y_{221} \\ Y_{112} \\ Y_{212} \\ Y_{122} \\ Y_{222} \\ Y_{113} \\ Y_{213} \\ Y_{123} \\ Y_{223} \end{bmatrix} &=& \begin{array}{c} \begin{matrix} \mu&\scriptsize{x11}&\scriptsize{x12}&\scriptsize{x21}&\scriptsize{x22}&\scriptsize{x11x21}&\scriptsize{x12x21}&\scriptsize{x11x22}&\scriptsize{x12x22} \end{matrix}\\ \left[\begin{array}{c|cc|cc|cccc} 1\hphantom{0}& 1\hphantom{0} & 0\hphantom{0} & 1\hphantom{0} & 0\hphantom{00} & 1\hphantom{000} & 0\hphantom{000} & 0\hphantom{000} & 0\hphantom{00}\\ 1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&1\hphantom{0}&0\hphantom{00}&0\hphantom{000}&1\hphantom{000}&0\hphantom{000}&0\hphantom{00}\\ 1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{00}&0\hphantom{000}&0\hphantom{000}&1\hphantom{000}&0\hphantom{00}\\ 1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&1\hphantom{00}&0\hphantom{000}&0\hphantom{000}&0\hphantom{000}&1\hphantom{00}\\ 1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{00}&1\hphantom{000}&0\hphantom{000}&0\hphantom{000}&0\hphantom{00}\\ 1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&1\hphantom{0}&0\hphantom{00}&0\hphantom{000}&1\hphantom{000}&0\hphantom{000}&0\hphantom{00}\\ 1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{00}&0\hphantom{000}&0\hphantom{000}&1\hphantom{000}&0\hphantom{00}\\ 1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&1\hphantom{00}&0\hphantom{000}&0\hphantom{000}&0\hphantom{000}&1\hphantom{00}\\ 1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{00}&1\hphantom{000}&0\hphantom{000}&0\hphantom{000}&0\hphantom{00}\\ 1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&1\hphantom{0}&0\hphantom{00}&0\hphantom{000}&1\hphantom{000}&0\hphantom{000}&0\hphantom{00}\\ 1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{00}&0\hphantom{000}&0\hphantom{000}&1\hphantom{000}&0\hphantom{00}\\ 1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&1\hphantom{00}&0\hphantom{000}&0\hphantom{000}&0\hphantom{000}&1\hphantom{00}\\ \end{array}\right] \end{array} \cdot \begin{bmatrix} \mu \\ \alpha_1\\ \alpha_2\\ \tau_1\\ \tau_2\\ \gamma_{11}\\ \gamma_{21}\\ \gamma_{12}\\ \gamma_{22} \end{bmatrix} + \begin{array}{c} \begin{matrix} \scriptsize{x11r1}&\scriptsize{x12r1}\hspace{0.1cm}&\scriptsize{x11r2}&\scriptsize{x12r2}&\scriptsize{x11r3}&\scriptsize{x12r3}\hspace{0.6cm} \end{matrix}\\ \left[\begin{array}{cccccc} 1\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 1\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{00}& 0\hphantom{0} \\ 1\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 1\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 0\hphantom{000}& 1\hphantom{000}& 0\hphantom{000}& 0\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 1\hphantom{000}& 0\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 0\hphantom{000}& 1\hphantom{000}& 0\hphantom{000}& 0\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 1\hphantom{000}& 0\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 1\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{00}& 1\hphantom{0} \\ 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 1\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{00}& 1\hphantom{0} \\ \end{array}\right] \end{array} \cdot \begin{bmatrix} u_{11} \\ u_{21} \\ u_{12} \\ u_{22} \\ u_{13} \\ u_{23} \end{bmatrix} + \begin{bmatrix} e_{111} \\ e_{211} \\ e_{121} \\ e_{221} \\ e_{112} \\ e_{212} \\ e_{122} \\ e_{222} \\ e_{113} \\ e_{213} \\ e_{123} \\ e_{223} \end{bmatrix} \\ &=& \begin{array}{c} \begin{matrix} \mu&\scriptsize{x11}&\scriptsize{x12}&\scriptsize{x21}&\scriptsize{x22}&\scriptsize{x11x21}&\scriptsize{x12x21}&\scriptsize{x11x22}&\scriptsize{x12x22} \end{matrix}\\ \left[\begin{array}{c|cc|cc|cccc} 1\hphantom{0}& 1\hphantom{0} & 0\hphantom{0} & 1\hphantom{0} & 0\hphantom{00} & 1\hphantom{000} & 0\hphantom{000} & 0\hphantom{000} & 0\hphantom{00}\\ 1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&1\hphantom{0}&0\hphantom{00}&0\hphantom{000}&1\hphantom{000}&0\hphantom{000}&0\hphantom{00}\\ 1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{00}&0\hphantom{000}&0\hphantom{000}&1\hphantom{000}&0\hphantom{00}\\ 1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&1\hphantom{00}&0\hphantom{000}&0\hphantom{000}&0\hphantom{000}&1\hphantom{00}\\ 1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{00}&1\hphantom{000}&0\hphantom{000}&0\hphantom{000}&0\hphantom{00}\\ 1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&1\hphantom{0}&0\hphantom{00}&0\hphantom{000}&1\hphantom{000}&0\hphantom{000}&0\hphantom{00}\\ 1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{00}&0\hphantom{000}&0\hphantom{000}&1\hphantom{000}&0\hphantom{00}\\ 1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&1\hphantom{00}&0\hphantom{000}&0\hphantom{000}&0\hphantom{000}&1\hphantom{00}\\ 1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{00}&1\hphantom{000}&0\hphantom{000}&0\hphantom{000}&0\hphantom{00}\\ 1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&1\hphantom{0}&0\hphantom{00}&0\hphantom{000}&1\hphantom{000}&0\hphantom{000}&0\hphantom{00}\\ 1\hphantom{0}&1\hphantom{0}&0\hphantom{0}&0\hphantom{0}&1\hphantom{00}&0\hphantom{000}&0\hphantom{000}&1\hphantom{000}&0\hphantom{00}\\ 1\hphantom{0}&0\hphantom{0}&1\hphantom{0}&0\hphantom{0}&1\hphantom{00}&0\hphantom{000}&0\hphantom{000}&0\hphantom{000}&1\hphantom{00}\\ \end{array}\right] \end{array} \cdot \begin{bmatrix} 15 \\ 1\\ -2\\ 1\\ -1\\ 3\\ 1\\ 1\\ -5 \end{bmatrix} + \begin{array}{c} \begin{matrix} \scriptsize{x11r1}&\scriptsize{x12r1}\hspace{0.1cm}&\scriptsize{x11r2}&\scriptsize{x12r2}&\scriptsize{x11r3}&\scriptsize{x12r3}\hspace{0.6cm} \end{matrix}\\ \left[\begin{array}{cccccc} 1\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 1\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{00}& 0\hphantom{0} \\ 1\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 1\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 0\hphantom{000}& 1\hphantom{000}& 0\hphantom{000}& 0\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 1\hphantom{000}& 0\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 0\hphantom{000}& 1\hphantom{000}& 0\hphantom{000}& 0\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 1\hphantom{000}& 0\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 1\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{00}& 1\hphantom{0} \\ 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 1\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{00}& 1\hphantom{0} \\ \end{array}\right] \end{array} \cdot \begin{bmatrix} u_{11} \\ u_{21} \\ u_{12} \\ u_{22} \\ u_{13} \\ u_{23} \end{bmatrix} + \begin{bmatrix} e_{111} \\ e_{211} \\ e_{121} \\ e_{221} \\ e_{112} \\ e_{212} \\ e_{122} \\ e_{222} \\ e_{113} \\ e_{213} \\ e_{123} \\ e_{223} \end{bmatrix} \\ &=& \begin{bmatrix} 20 \\ 15 \\ 16 \\ 7 \\ 20 \\ 15 \\ 16 \\ 7 \\ 20 \\ 15 \\ 16 \\ 7 \end{bmatrix} + \begin{array}{c} \begin{matrix} \scriptsize{x11r1}&\scriptsize{x12r1}\hspace{0.1cm}&\scriptsize{x11r2}&\scriptsize{x12r2}&\scriptsize{x11r3}&\scriptsize{x12r3}\hspace{0.6cm} \end{matrix}\\ \left[\begin{array}{cccccc} 1\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 1\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{00}& 0\hphantom{0} \\ 1\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 1\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 0\hphantom{000}& 1\hphantom{000}& 0\hphantom{000}& 0\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 1\hphantom{000}& 0\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 0\hphantom{000}& 1\hphantom{000}& 0\hphantom{000}& 0\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 1\hphantom{000}& 0\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 1\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{00}& 1\hphantom{0} \\ 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 1\hphantom{00}& 0\hphantom{0} \\ 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{000}& 0\hphantom{00}& 1\hphantom{0} \\ \end{array}\right] \end{array} \cdot \begin{bmatrix} u_{11} \\ u_{21} \\ u_{12} \\ u_{22} \\ u_{13} \\ u_{23} \end{bmatrix} + \begin{bmatrix} e_{111} \\ e_{211} \\ e_{121} \\ e_{221} \\ e_{112} \\ e_{212} \\ e_{122} \\ e_{222} \\ e_{113} \\ e_{213} \\ e_{123} \\ e_{223} \end{bmatrix} \end{eqnarray} \]

Considering that the error of plot and subplot has mean 0 and variance 0 we have:

\[ \begin{bmatrix} Y_{111} \\ Y_{211} \\ Y_{121} \\ Y_{221} \\ Y_{112} \\ Y_{212} \\ Y_{122} \\ Y_{222} \\ Y_{113} \\ Y_{213} \\ Y_{123} \\ Y_{223} \end{bmatrix} = \begin{bmatrix} 20 \\ 15 \\ 16 \\ 7 \\ 20 \\ 15 \\ 16 \\ 7 \\ 20 \\ 15 \\ 16 \\ 7 \end{bmatrix} \]

Using the gexp package we have:

SPE_crd <- gexp(mu = 15,
                  err = matrix(rep(0, 12),
                                nrow = 12),
                  errp = matrix(rep(0, 6),
                                nrow = 6),
                  r = 3,
                  fe = list(alpha = c(1, -2),
                              tau = c(1, -1)),
                  inte = c(3, 1, 1, -5),
                  type = 'SPE')
summary(SPE_crd)
#> Database 
#>    r  X1  X2 Y1
#> 1  1 x11 x21 20
#> 2  2 x11 x21 20
#> 3  3 x11 x21 20
#> 4  1 x12 x21 15
#> 5  2 x12 x21 15
#> 6  3 x12 x21 15
#> 7  1 x11 x22 16
#> 8  2 x11 x22 16
#> 9  3 x11 x22 16
#> 10 1 x12 x22  7
#> 11 2 x12 x22  7
#> 12 3 x12 x22  7

Simulating a CRD with a quantitative factor

Non-Orthogonal Contrast

Linear Effect

Let us suppose that we want to generate a single random variable according to a CRD with one factor and four levels (0, 5, 10, 15) being 3 repetitions. Then we can denote \(Y_ {ik}\) as being the random variable observed in the k-th experimental unit (k = 1, 2, 3) that received the i-th level of factor X1 (i = 1,2,3,4). In this case, it is only possible to adjust a regression up to the third degree. As the treatment is quantitative, instead of indicating the effects of treatments as deviations from the general mean, we will indicate the value we want for each regression coefficient. So, instead of having \(\mu, \alpha_1, \alpha_2, \alpha_3\) and \(\alpha_4\), we have \(\beta_0\) (the intercept), \(\beta_1\) (the angular coefficient), \(\beta_2\) the quadratic coefficient) and \(\beta_3\) (the cubic coefficient). Since the effect we want is linear, then we can provide the following values for betas: \(\beta_0 = 2, \beta_1 = 3, \beta_2 = 0\) and \(\beta_3 = 0\). Therefore, we will have the following matrix configuration:

\[ \begin{eqnarray} \begin{bmatrix} Y_{11} \\ Y_{21} \\ Y_{31} \\ Y_{41} \\ Y_{12} \\ Y_{22} \\ Y_{32} \\ Y_{42} \\ Y_{13} \\ Y_{23} \\ Y_{33} \\ Y_{43} \end{bmatrix} &=& \begin{array}{p{5cm}} \begin{matrix} \beta_0 & \!\scriptsize{x11}\! & \scriptsize{x12} & \scriptsize{x13} \end{matrix}\\ \left[\begin{array}{c|cc} 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 \\ 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 \\ 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 \\ \end{array}\right] \end{array} \cdot \begin{bmatrix} \beta_{0} \\ \beta_{1} \\ \beta_{2} \\ \beta_{3} \end{bmatrix} + \begin{bmatrix} e_{11} \\ e_{21} \\ e_{31} \\ e_{41} \\ e_{12} \\ e_{22} \\ e_{23} \\ e_{24} \\ e_{13} \\ e_{23} \\ e_{33} \\ e_{43} \end{bmatrix} \\ &=& \begin{array}{c} \begin{matrix} \beta_0 & \!\scriptsize{x11}\! & \scriptsize{x12} & \scriptsize{x13} \end{matrix}\\ \left[\begin{array}{c|cc} 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 \\ 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 \\ 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 \\ \end{array}\right] \end{array} \cdot \begin{bmatrix} 2 \\ 3 \\ 0 \\ 0 \\ \end{bmatrix} + \begin{bmatrix} e_{11} \\ e_{21} \\ e_{31} \\ e_{41} \\ e_{12} \\ e_{22} \\ e_{23} \\ e_{24} \\ e_{13} \\ e_{23} \\ e_{33} \\ e_{43} \end{bmatrix} \\ &=& \begin{bmatrix} 2 \\ 17 \\ 32 \\ 47 \\ 2 \\ 17 \\ 32 \\ 47 \\ 2 \\ 17 \\ 32 \\ 47 \end{bmatrix} + \begin{bmatrix} e_{11} \\ e_{21} \\ e_{31} \\ e_{41} \\ e_{12} \\ e_{22} \\ e_{23} \\ e_{24} \\ e_{13} \\ e_{23} \\ e_{33} \\ e_{43} \end{bmatrix} \end{eqnarray} \]

If we consider an error with mean 0 and variance 0 then we have the following simulated random variable:

\[ \begin{bmatrix} Y_{11} \\ Y_{21} \\ Y_{31} \\ Y_{41} \\ Y_{12} \\ Y_{22} \\ Y_{32} \\ Y_{42} \\ Y_{13} \\ Y_{23} \\ Y_{33} \\ Y_{43} \end{bmatrix} = \begin{bmatrix} 2 \\ 17 \\ 32 \\ 47 \\ 2 \\ 17 \\ 32 \\ 47 \\ 2 \\ 17 \\ 32 \\ 47 \end{bmatrix} \]

Using the gexp package we have:

level <- seq(0, 15, 5)
cont_crd <- matrix(c(level,
                     level^2,
                     level^3),
                   ncol = 3)

crd_l <- gexp(mu = 2,
              r = 3,
              err = matrix(rep(0,12),
                           nrow = 12),
              fe = list(f1 = c(3, 0, 0)),
              fl = list(dose = level),
              contrasts = list(dose = cont_crd))

summary(crd_l)
#> Database 
#>    r dose Y1
#> 1  1    0  2
#> 2  2    0  2
#> 3  3    0  2
#> 4  1    5 17
#> 5  2    5 17
#> 6  3    5 17
#> 7  1   10 32
#> 8  2   10 32
#> 9  3   10 32
#> 10 1   15 47
#> 11 2   15 47
#> 12 3   15 47

Below the simulation chart.

Quadratic effect

Taking advantage of the same previous example, adding only the quadratic effect to the data, that is, \(\beta_2 = 4\). Therefore, we will have the following matrix configuration:

\[ \begin{eqnarray} \begin{bmatrix} Y_{11} \\ Y_{21} \\ Y_{31} \\ Y_{41} \\ Y_{12} \\ Y_{22} \\ Y_{32} \\ Y_{42} \\ Y_{13} \\ Y_{23} \\ Y_{33} \\ Y_{43} \end{bmatrix} &=& \begin{array}{p{5cm}} \begin{matrix} \beta_0 & \!\scriptsize{x11}\! & \scriptsize{x12} & \scriptsize{x13} \end{matrix}\\ \left[\begin{array}{c|cc} 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 \\ 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 \\ 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 \\ \end{array}\right] \end{array} \cdot \begin{bmatrix} \beta_{0} \\ \beta_{1} \\ \beta_{2} \\ \beta_{3} \end{bmatrix} + \begin{bmatrix} e_{11} \\ e_{21} \\ e_{31} \\ e_{41} \\ e_{12} \\ e_{22} \\ e_{23} \\ e_{24} \\ e_{13} \\ e_{23} \\ e_{33} \\ e_{43} \end{bmatrix} \\ &=& \begin{array}{c} \begin{matrix} \beta_0 & \!\scriptsize{x11}\! & \scriptsize{x12} & \scriptsize{x13} \end{matrix}\\ \left[\begin{array}{c|cc} 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 \\ 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 \\ 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 \\ \end{array}\right] \end{array} \cdot \begin{bmatrix} 2 \\ 3 \\ 4 \\ 0 \\ \end{bmatrix} + \begin{bmatrix} e_{11} \\ e_{21} \\ e_{31} \\ e_{41} \\ e_{12} \\ e_{22} \\ e_{23} \\ e_{24} \\ e_{13} \\ e_{23} \\ e_{33} \\ e_{43} \end{bmatrix} \\ &=& \begin{bmatrix} 2 \\ 117 \\ 432 \\ 947 \\ 2 \\ 117 \\ 432 \\ 947 \\ 2 \\ 117 \\ 432 \\ 947 \end{bmatrix} + \begin{bmatrix} e_{11} \\ e_{21} \\ e_{31} \\ e_{41} \\ e_{12} \\ e_{22} \\ e_{23} \\ e_{24} \\ e_{13} \\ e_{23} \\ e_{33} \\ e_{43} \end{bmatrix} \end{eqnarray} \]

Using the gexp package we have:

crd_q <- gexp(mu = 2,
              r = 3,
              err = matrix(rep(0,12),
                           nrow = 12),
              fe = list(f1 = c(3, 4, 0)),
              fl = list(dose = level),
              contrasts = list(dose = cont_crd))

summary(crd_q)
#> Database 
#>    r dose  Y1
#> 1  1    0   2
#> 2  2    0   2
#> 3  3    0   2
#> 4  1    5 117
#> 5  2    5 117
#> 6  3    5 117
#> 7  1   10 432
#> 8  2   10 432
#> 9  3   10 432
#> 10 1   15 947
#> 11 2   15 947
#> 12 3   15 947

Below the simulation chart.

Simulating a CRD in a factorial experiments with two quantitative factors

Linear Response Surface

Let us suppose that we want to generate a single random variable according to a CRD with two quantitative factors with levels 0, 5, 10, 15 and 2, 4, 6, 8 respectively, being 2 replicates. Then we can denote \(Y_{ijk}\) as being the random variable observed in the k-th experimental unit (k = 1, 2) that received the i-th level of factor X1 (i = 1,2,3,4) and j-th level of factor X2 (j = 1,2,3,4). In these cases, we should note that there is only one intercept. Therefore, such an intercept must appear in the first factor to be declared. In the others, the value of the intercept must be declared as 0 (only to compute the length of the vector correctly). Therefore, consider the following values for the first factor: \(\beta_0 = 1, \beta_1 = 3, \beta_2 = 0, \beta_3 = 0\). For the second factor we have: \(\beta_4 = 2, \beta_5 = 0, \beta_6 = 0\). Matrically we have:

\[ \begin{eqnarray} \begin{bmatrix} Y_{111} \\ Y_{211} \\ Y_{311} \\ Y_{411} \\ Y_{121} \\ Y_{221} \\ Y_{321} \\ Y_{421} \\ Y_{131} \\ Y_{231} \\ Y_{331} \\ Y_{431} \\ Y_{141} \\ Y_{241} \\ Y_{341} \\ Y_{441} \\ Y_{112} \\ Y_{212} \\ Y_{312} \\ Y_{412} \\ Y_{122} \\ Y_{222} \\ Y_{322} \\ Y_{422} \\ Y_{132} \\ Y_{232} \\ Y_{332} \\ Y_{432} \\ Y_{142} \\ Y_{242} \\ Y_{342} \\ Y_{442} \\ \end{bmatrix} &=& \begin{array}{p{5cm}} \begin{matrix} \beta_0 & \!\scriptsize{x11}\! & \scriptsize{x12} & \scriptsize{x13} & \!\scriptsize{x21}\! & \scriptsize{x22} & \scriptsize{x23} \end{matrix}\\ \left[\begin{array}{c|cc} 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 & 2\hphantom{0} & 2^2 & 2^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 & 2\hphantom{0} & 2^2 & 2^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 & 2\hphantom{0} & 2^2 & 2^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 & 2\hphantom{0} & 2^2 & 2^3 \\ 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 & 4\hphantom{0} & 4^2 & 4^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 & 4\hphantom{0} & 4^2 & 4^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 & 4\hphantom{0} & 4^2 & 4^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 & 4\hphantom{0} & 4^2 & 4^3 \\ 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 & 6\hphantom{0} & 6^2 & 6^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 & 6\hphantom{0} & 6^2 & 6^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 & 6\hphantom{0} & 6^2 & 6^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 & 6\hphantom{0} & 6^2 & 6^3 \\ 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 & 8\hphantom{0} & 8^2 & 8^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 & 8\hphantom{0} & 8^2 & 8^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 & 8\hphantom{0} & 8^2 & 8^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 & 8\hphantom{0} & 8^2 & 8^3 \\ 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 & 2\hphantom{0} & 2^2 & 2^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 & 2\hphantom{0} & 2^2 & 2^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 & 2\hphantom{0} & 2^2 & 2^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 & 2\hphantom{0} & 2^2 & 2^3 \\ 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 & 4\hphantom{0} & 4^2 & 4^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 & 4\hphantom{0} & 4^2 & 4^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 & 4\hphantom{0} & 4^2 & 4^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 & 4\hphantom{0} & 4^2 & 4^3 \\ 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 & 6\hphantom{0} & 6^2 & 6^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 & 6\hphantom{0} & 6^2 & 6^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 & 6\hphantom{0} & 6^2 & 6^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 & 6\hphantom{0} & 6^2 & 6^3 \\ 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 & 8\hphantom{0} & 8^2 & 8^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 & 8\hphantom{0} & 8^2 & 8^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 & 8\hphantom{0} & 8^2 & 8^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 & 8\hphantom{0} & 8^2 & 8^3 \\ \end{array}\right] \end{array} \cdot \begin{bmatrix} \beta_{0} \\ \beta_{1} \\ \beta_{2} \\ \beta_{3} \\ \beta_{4} \\ \beta_{5} \\ \beta_{6} \end{bmatrix} + \begin{bmatrix} e_{111} \\ e_{211} \\ e_{311} \\ e_{411} \\ e_{121} \\ e_{221} \\ e_{321} \\ e_{421} \\ e_{131} \\ e_{231} \\ e_{331} \\ e_{431} \\ e_{141} \\ e_{241} \\ e_{341} \\ e_{441} \\ e_{112} \\ e_{212} \\ e_{312} \\ e_{412} \\ e_{122} \\ e_{222} \\ e_{322} \\ e_{422} \\ e_{132} \\ e_{232} \\ e_{332} \\ e_{432} \\ e_{142} \\ e_{242} \\ e_{342} \\ e_{442} \\ \end{bmatrix} \\ &=& \begin{array}{c} \begin{matrix} \beta_0 & \!\scriptsize{x11}\! & \scriptsize{x12} & \scriptsize{x13} & \!\scriptsize{x21}\! & \scriptsize{x22} & \scriptsize{x23} \end{matrix}\\ \left[\begin{array}{c|cc} 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 & 2\hphantom{0} & 2^2 & 2^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 & 2\hphantom{0} & 2^2 & 2^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 & 2\hphantom{0} & 2^2 & 2^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 & 2\hphantom{0} & 2^2 & 2^3 \\ 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 & 4\hphantom{0} & 4^2 & 4^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 & 4\hphantom{0} & 4^2 & 4^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 & 4\hphantom{0} & 4^2 & 4^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 & 4\hphantom{0} & 4^2 & 4^3 \\ 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 & 6\hphantom{0} & 6^2 & 6^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 & 6\hphantom{0} & 6^2 & 6^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 & 6\hphantom{0} & 6^2 & 6^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 & 6\hphantom{0} & 6^2 & 6^3 \\ 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 & 8\hphantom{0} & 8^2 & 8^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 & 8\hphantom{0} & 8^2 & 8^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 & 8\hphantom{0} & 8^2 & 8^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 & 8\hphantom{0} & 8^2 & 8^3 \\ 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 & 2\hphantom{0} & 2^2 & 2^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 & 2\hphantom{0} & 2^2 & 2^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 & 2\hphantom{0} & 2^2 & 2^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 & 2\hphantom{0} & 2^2 & 2^3 \\ 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 & 4\hphantom{0} & 4^2 & 4^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 & 4\hphantom{0} & 4^2 & 4^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 & 4\hphantom{0} & 4^2 & 4^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 & 4\hphantom{0} & 4^2 & 4^3 \\ 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 & 6\hphantom{0} & 6^2 & 6^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 & 6\hphantom{0} & 6^2 & 6^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 & 6\hphantom{0} & 6^2 & 6^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 & 6\hphantom{0} & 6^2 & 6^3 \\ 1\hphantom{0} & 0\hphantom{0} & 0^2 & 0^3 & 8\hphantom{0} & 8^2 & 8^3 \\ 1\hphantom{0} & 5\hphantom{0} & 5^2 & 5^3 & 8\hphantom{0} & 8^2 & 8^3 \\ 1\hphantom{0} & 10\hphantom{0} & 10^2 & 10^3 & 8\hphantom{0} & 8^2 & 8^3 \\ 1\hphantom{0} & 15\hphantom{0} & 15^2 & 15^3 & 8\hphantom{0} & 8^2 & 8^3 \\ \end{array}\right] \end{array} \cdot \begin{bmatrix} 1 \\ 3 \\ 0 \\ 0 \\ 2 \\ 0 \\ 0 \end{bmatrix} + \begin{bmatrix} e_{111} \\ e_{211} \\ e_{311} \\ e_{411} \\ e_{121} \\ e_{221} \\ e_{321} \\ e_{421} \\ e_{131} \\ e_{231} \\ e_{331} \\ e_{431} \\ e_{141} \\ e_{241} \\ e_{341} \\ e_{441} \\ e_{112} \\ e_{212} \\ e_{312} \\ e_{412} \\ e_{122} \\ e_{222} \\ e_{322} \\ e_{422} \\ e_{132} \\ e_{232} \\ e_{332} \\ e_{432} \\ e_{142} \\ e_{242} \\ e_{342} \\ e_{442} \\ \end{bmatrix} \\ &=& \begin{bmatrix} 5 \\ 20 \\ 35 \\ 50 \\ 9 \\ 24 \\ 39 \\ 54 \\ 13 \\ 28 \\ 43 \\ 58 \\ 17 \\ 32 \\ 47 \\ 62 \\ 5 \\ 20 \\ 35 \\ 50 \\ 9 \\ 24 \\ 39 \\ 54 \\ 13 \\ 28 \\ 43 \\ 58 \\ 17 \\ 32 \\ 47 \\ 62 \end{bmatrix} + \begin{bmatrix} e_{111} \\ e_{211} \\ e_{311} \\ e_{411} \\ e_{121} \\ e_{221} \\ e_{321} \\ e_{421} \\ e_{131} \\ e_{231} \\ e_{331} \\ e_{431} \\ e_{141} \\ e_{241} \\ e_{341} \\ e_{441} \\ e_{112} \\ e_{212} \\ e_{312} \\ e_{412} \\ e_{122} \\ e_{222} \\ e_{322} \\ e_{422} \\ e_{132} \\ e_{232} \\ e_{332} \\ e_{432} \\ e_{142} \\ e_{242} \\ e_{342} \\ e_{442} \end{bmatrix} \end{eqnarray} \]

Using the gexp package we have:

level2 <- seq(2,8,2)
cont_crd2 <- matrix(c(level2,level2^2,level2^3),
                    ncol = 3)

crd_hb <- gexp(mu = 1,
               r = 2,
               err = matrix(rep(0,32),
                            nrow = 32),
               fe = list(f1 = c(3, 0, 0),
                         f2 = c(2, 0, 0)),
               fl = list(N = level,
                         P = level2),
               inte = c(6,0,0,0,0,0,0,0,0),
               contrasts = list(N = cont_crd,
                                P = cont_crd2),
              type = 'FE')

summary(crd_hb)
#> Database 
#>    r  N P  Y1
#> 1  1  0 2   5
#> 2  2  0 2   5
#> 3  1  5 2  80
#> 4  2  5 2  80
#> 5  1 10 2 155
#> 6  2 10 2 155
#> 7  1 15 2 230
#> 8  2 15 2 230
#> 9  1  0 4   9
#> 10 2  0 4   9
#> 11 1  5 4 144
#> 12 2  5 4 144
#> 13 1 10 4 279
#> 14 2 10 4 279
#> 15 1 15 4 414
#> 16 2 15 4 414
#> 17 1  0 6  13
#> 18 2  0 6  13
#> 19 1  5 6 208
#> 20 2  5 6 208
#> 21 1 10 6 403
#> 22 2 10 6 403
#> 23 1 15 6 598
#> 24 2 15 6 598
#> 25 1  0 8  17
#> 26 2  0 8  17
#> 27 1  5 8 272
#> 28 2  5 8 272
#> 29 1 10 8 527
#> 30 2 10 8 527
#> 31 1 15 8 782
#> 32 2 15 8 782

Below the simulation chart.

Quadratic response surface

Let’s omit matrix algebra as it is analogous to the one presented above. Considering now \(\beta_2 = 2\) and \(\beta_5 = 3\), we have the following result using the gexp package.

crd_hb2 <- gexp(mu = 1,
                r = 2,
                err = matrix(rep(0,32),
                             nrow = 32),
                fe = list(f1 = c(3, 2, 0),
                          f2 = c(2, 3, 0)),
                fl = list(N = level,
                          P = level2),
                inte = c(2,1,0,1,8,0,0,0,0), 
                contrasts = list(N = cont_crd,
                                 P = cont_crd2),
                type = 'FE')

summary(crd_hb2)
#> Database 
#>    r  N P     Y1
#> 1  1  0 2     17
#> 2  2  0 2     17
#> 3  1  5 2    972
#> 4  2  5 2    972
#> 5  1 10 2   3727
#> 6  2 10 2   3727
#> 7  1 15 2   8282
#> 8  2 15 2   8282
#> 9  1  0 4     57
#> 10 2  0 4     57
#> 11 1  5 4   3542
#> 12 2  5 4   3542
#> 13 1 10 4  13727
#> 14 2 10 4  13727
#> 15 1 15 4  30612
#> 16 2 15 4  30612
#> 17 1  0 6    121
#> 18 2  0 6    121
#> 19 1  5 6   7776
#> 20 2  5 6   7776
#> 21 1 10 6  30231
#> 22 2 10 6  30231
#> 23 1 15 6  67486
#> 24 2 15 6  67486
#> 25 1  0 8    209
#> 26 2  0 8    209
#> 27 1  5 8  13674
#> 28 2  5 8  13674
#> 29 1 10 8  53239
#> 30 2 10 8  53239
#> 31 1 15 8 118904
#> 32 2 15 8 118904

Below the simulation chart.

Doing experiment planning

Not interactive

CRD

Let’s suppose that we are interested in planning a DIC with three treatments (default) and five repetitions (default). In this case, as we are not interested in simulating data, we can give any value to the effects of the treatments, because what matters is the arrangement of the treatments in the experimental units.

So, using the gexp package we have:

crd_design <- gexp()
plot(crd_design) 

RCBD without repetition

Let us consider an RCBD in which the block is the very repetition of the experiment. Consider also three treatments (default) and three blocks (default).

With the gexp package we have:

rcbd_designs <- gexp(r = 1, 
                     design = 'RCBD')

Graphically, we have:

plot(rcbd_designs)

RCBD with repetition

Considering the same experiment previous, alternating the number of repetitions inside blocks. Let us now consider two replicates per block.

With the gexp package we have:

rcbd_designc <- gexp(r = 2, 
                     design = 'RCBD')

Graphically, we have:

plot(rcbd_designc)

LSD

Consider a LSD with three treatments (default), three rows and three columns. In this case we have the following planning.

lsd_design <- gexp(r = 1,
                   design = 'LSD')

Graphically, we have:

plot(lsd_design)

Factorial - CRD

Let us assume that we are interested in planning a 2x3 factorial (default) design with three replicates.

fat_design <- gexp(r = 3, 
                   type = 'FE')

Using the graph we have:

plot(fat_design)

Split-plot - CRD

Assuming that we are interested in planning a CRD in split-plot, with two treatments in the plot (default) and three treatments in the subplot (default), with three replications.

split_design <- gexp(r = 3, 
                     type = 'SPE')
summary(split_design)
#> Database 
#>    r  X1  X2   Y1
#> 1  1 x11 x21 28.2
#> 2  2 x11 x21 27.0
#> 3  3 x11 x21 28.1
#> 4  1 x12 x21 30.6
#> 5  2 x12 x21 29.5
#> 6  3 x12 x21 28.3
#> 7  1 x13 x21 29.4
#> 8  2 x13 x21 30.2
#> 9  3 x13 x21 28.2
#> 10 1 x11 x22 30.5
#> 11 2 x11 x22 28.3
#> 12 3 x11 x22 28.4
#> 13 1 x12 x22 29.8
#> 14 2 x12 x22 31.1
#> 15 3 x12 x22 27.6
#> 16 1 x13 x22 30.0
#> 17 2 x13 x22 30.5
#> 18 3 x13 x22 29.3

Using the graph we have:

plot(split_design)

Interactive

CRD

If the researcher has a sketch of the experimental area in the PNG, JPG or JPEG formats, it is possible to import such a file with the functions of the gexp package and to randomly distribute the treatments in the experimental units. Suppose we have a sketch with six fish tanks, and we want to distribute two treatments with three replicates in the image. Then we proceed from the following form:

crd_plot <- gexp(r = 3, 
                 fe = list(f1 = rep(1,2)))
plot(crd_plot,
     dynamic = TRUE)

References

Aquino, Luiz Henrique de. 1992. “Técnica Experimental Com Animais i.”
Ferreira, Daniel Furtado. 2008. Estatística Multivariada. Edited by UFLA. 1st ed.
Naes, T., A. H. Aastveit, and N. S. Sahni. 2007. “Analysis of Split-Plot Designs: An Overview and Comparison of Methods.” Qual. Reliab. Engng. Int. 23: 801–20.
Rencher, Alvin C., and Bruce G. Schaalje. 2007. Linear Models in Statistics. Edited by John Wiley & Sons. 2nd ed.

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.