# An introduction to gexp package

knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) 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 for IHD, DBC and DQL and a schema in subdivided plots also considering the CRD, RCBD and LSD [@Aquino:1992]. The arguments of the function are based on a linear model with the following matrix form [@Ferreira:2008, @Rencher: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: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) dic <- gexp(mu = 15, err = matrix(rep(0, 6), nrow = 6), r = 3, fe = list(alpha = c(1, -2))) summary(dic) ## 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$\mu2 = 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 & \mu2 \ \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: dic_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(dic_mv) # 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 \ \beta3 \ \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), type = 'RCBD') summary(rcbd) # 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_{r}$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{r} \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 \ \alpha3 \ \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{r} \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, err = matrix(rep(0, 9), nrow = 9), fe = list(alpha = c(1, -2, 3)), rowe = c(2, 3, 4), cole = c(6, 7, 8), nrand = 0, type = 'LSD') summary(lsd) # 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$\tau3 = 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\ \tau3\ \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: fat_dic <- 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(fat_dic) # 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\ \tau2\ \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: split_dic <- 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(split_dic) # 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} \beta0 & !\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} \beta0 & !\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 = NULL, r = 3, err = matrix(rep(0,12), nrow = 12), fe = list(f1 = c(2, 3, 0, 0)), contrasts = list(f1 = cont_crd)) summary(crd_l) Below the simulation chart. with(crd_l$dfm, plot(Y1 ~ rep(level, 3), axes = FALSE, ylim = c(0,50), xlab = 'X1')) axis(1, pos = 0) axis(2, pos = 0) abline(h = 2, col = 'red') abline(2, 3, col = 'red', lty = 2) text(-0.5,2,'2',col = 'red', xpd = TRUE)

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} \beta0 & !\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} \beta0 & !\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 = NULL, r = 3, err = matrix(rep(0,12), nrow = 12), fe = list(f1 = c(2, 3, 4, 0)), contrasts = list(f1 = cont_crd)) summary(crd_q)

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(random = TRUE) summary(crd_design)

Graficamente, temos:

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, type = 'RCBD', random = TRUE) summary(rcbd_designs)

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, type = 'RCBD', random = TRUE) summary(rcbd_designc)

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(type = 'LSD', random = TRUE) summary(lsd_design)

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', random = TRUE) summary(fat_design)

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', random = TRUE) summary(split_design)

Using the graph we have:

plot(split_design)

## Interactive

### DIC

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:

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