gexp: Generator of Experiments

Description Usage Arguments Value References See Also Examples

View source: R/gexp.R

Description

The package provides computational resources useful in planning and modeling of structured experiments in the R environment.

The generic function S3 gexp was created to enable plan, create and model structured experiments, that is, under a design experimental. In the modeling it is possible to simulate results of experiments with possibility of user informing the effects and the random error(s). The designs are: Completely Randomized Design (CRD), Randomized complete block design (RCBD) and Latin Squares Design (LSD). The types of experiments are: Factorial Experimentation (FE) and Split-plot experiment (SPE).

The experiments can be generated with one or more variable response, in the latter case, it may be important for a structure covariance between them. It is also possible to plan experiments with of graphic parts for use in planning from figures or pictures of the experimental area.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
gexp(x, ...)

## Default S3 method:
gexp(
     x         = NULL,
     mu        = 26,
     err       = NULL,
     errp      = NULL,
     r         = 5L,
     fl        = NULL,
     blkl      = NULL,
     rowl      = NULL,
     coll      = NULL,
     fe        = NULL,
     inte      = NULL,
     blke      = NULL,
     rowe      = NULL,
     cole      = NULL,
     contrasts = NULL,
     type      = c('SIMPLE','FE','SPE'),
     design    = c('CRD','RCBD','LSD'), 
     round     = 2L,
     ...)

## S3 method for class 'simple_crd'
gexp(
     x, ...)

## S3 method for class 'simple_rcbd'
gexp(
     x, ...)

## S3 method for class 'simple_lsd'
gexp(
     x, ...)

## S3 method for class 'fe_crd'
gexp(
     x, ...)

## S3 method for class 'fe_rcbd'
gexp(
     x, ...) 

## S3 method for class 'fe_lsd'
gexp(
     x, ...) 

## S3 method for class 'spe_crd'
gexp(
     x, ...)

## S3 method for class 'spe_rcbd'
gexp(
     x, ...) 

## S3 method for class 'spe_lsd'
gexp(
     x, ...) 

Arguments

x

An object of gexp class.

mu

Is a numeric scalar, or a vector to Multivarite Data (MD), that represent the mean of each factor. Required NULL if the effect of at least one factor of the experiment is quantitative.

err

It is a vector, or matrix for MD, that represents the experimental error. The default value is NULL, that is, for each response variable a normal error is added with mean 0 and variance 1 generated by rmvnorm(sigma = diag(length(mu))).

errp

It is a vector, or a matrix for MD, of the error associated with the plots if type is equal to SPE (Split-Plot Experiments). The default value is NULL, that is, for each response variable a normal error is added with mean 0 and variance 1 generated by rmvnorm(sigma = diag(length(mu))).

r

It is a scalar of the number of repetitions of the experiment.

fl

List of a vector of characters, or a matrix (MD). It's a list of factor names.

blkl

List of a vector of characters, or an array for MD, of block names.

rowl

List a vector of characters, or an array for MD, of the line names in case type is equal to LSD (Latin Square Design).

coll

List of a vector of characters, or an array for MD, of the column names in case the type is equal to LSD (Latin Square Design).

fe

It is a numerical vector, or a matrix (MD). It's a list of the effect of a factor.

inte

It is a numerical vector, or a matrix for MD, of the effects of the interaction.

blke

It is a numerical vector, or a matrix for MD, of the effects of the blocks.

rowe

It is a numerical vector, or an array for MD, of the effects of the lines in case the type is equal to LSD (Latin Square Design).

cole

Is a numeric vector, or a matrix for MD, of the effects of the columns in case the type is equal to LSD (Latin Square Design).

contrasts

A list, whose entries are values (numeric matrices or character strings naming functions) to be used as replacement values for the contrasts function and whose names are the names of the columns. See "contrasts.arg" argument of the model.matrix function to more details. Required if the effect of at least one factor of the experiment is quantitative.

type

It is a vector of strings that contains the type of experiment to be used: Simple (SIMPLE), Factorial Experiment (FE) and Split-plot Experiment (SPE). SIMPLE is the default.

design

It is a vector of strings that contains the type of design to be used: Completely Randomized Design (CRD), Randomized Complete Block Design (RCBD), Latin Squares Design (LSD). CRD is the default.

round

This is a numeric scalar for rounding of the response variable.

...

Further arguments (required by generic).

Value

The method gexp returns the list of class gexp with the slots:

X

It is the incidence matrix of the design.

Z

It is the incidence matrix of the error of the main parcel in the case of type equal to SPLIT.

Y

It is a vector, or a matrix for MD, with the values of the random variable(s).

dfm

It is a data.frame with all experiment information: treatments, repetitions, and the random response variable.

References

Ferreira, Daniel Furtado. 2008. Estat<ed>stica Multivariada. 1 ed. Lavras: Ed. UFLA.

Aquino, Luiz Henrique. T<e9>cnica Experimental com Animais I. Apostila da disciplina “T<e9>cnica Experimental com Animais” da Universidade Federal de Lavras, 1992.

Rencher, Alvin C. and Schaalje, Bruce G. 2007. Linear Models in Statistics, second edition. Hoboken: John Wiley \& Sons.

Naes, T.; Aastveit, A.H.; Sahni, N.S. 2007. "Analysis of split-plot designs: An Overview and Comparison of Methods". Qual. Reliab. Engng. Int. 23, 801-820.

See Also

plot.gexp.simple_crd

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
#++++++++++++++++++++++++++++#
#    UNIVARIATE APPROACH     #
#++++++++++++++++++++++++++++#
#!____________________________
#! Qualitative Factor(s) (QL)
#!____________________________

#! Completely Randomized Design (CRD)
#! 1 factor - CRD - QLF
# Nonsense(experimental error = 0)
# Yi = mu + fe + e
r <- 2  # (repet. number)
fln <- 3  # (factor levels number)

crd00 <- gexp(mu = 0,
              r = r,
              fe = list(f1 = c(1, 2, 3)),
              err = matrix(0, 
                           nrow = r*fln),
              round = 0)
crd00$X
print(crd00)
summary(crd00)
str(crd00) 

#! 1 factor - CRD - QL
# Nonsense(error is 0)
# Yi = mu + fe + e
r <- 3  # (repet. number)
fln <- 5  # (factor levels number)

crd01 <- gexp(mu = 1,
              r = r,
              fe = list(f1 = c(0, 2, 4, 6, 8)),
              err = matrix(0,
                           nrow = r*fln),
              round = 2)
summary(crd01)

#! 1 factor - CRD - QL
# Default error: rmvnorm(sigma = diag(ncol(as.matrix([[fe]]))))
crd_1f <- gexp(mu = 1,
               r = 3,
               fe = list(f1 = c(1, 1, 5, 1, 1)),
               fl = list(Treat = LETTERS[1:5]),
               round = 2)

crd_1f$X
summary(crd_1f)

#! Binomial error - CRD - QL
e_binom <- as.matrix(rbinom(n = 15,
                            size = 5,
                            prob = 0.1))

crd_bin <- gexp(mu = 20,
                err = e_binom,
                r = 5,
                fe = list(f1 = c(1, 4, 1)))

summary(crd_bin)

mod <- aov(Y1 ~ X1,
           data = crd_bin$dfm)

shapiro.test(mod$res)

#! Factorial Experiment (FE) - CRD - QL
fe_crd00 <- gexp(mu = 0,
                 r = 2,
                 fe = list(f1 = c(1, 1, 5),
                           f2 = c(1, 1),
                           f3 = c(2, 2, 1)),
                 fl = list(A = paste('a',
                                     1:3,
                                     sep = ''),
                           B = paste('b',
                                     1:2,
                                     sep = ''),
                           C = paste('c',
                                     1:3,
                                     sep = '')),
                 round = 0,
                 type = 'FE')
fe_crd00$X
summary(fe_crd00)

#! Factorial Experiment (FE) - With interaction - CRD - QL
fe_crd01 <- gexp(mu = 30,
                 fe = list(f1 = c(1, 1, 3),
                           f2 = c(1, 1)),
                 fl = list(A = paste('a',
                                     1:3,
                                     sep = ''),
                           B = paste('b',
                                     1:2,
                                     sep = '')),
                 inte = c(3, 1, 1, 1, 1, 5), # (3*2)
                 round = 1,
                 type = 'FE')
summary(fe_crd01)

#! Split-plot Experiment (SPE) - CRD - QL
split_crd <- gexp(mu = 30,
                  fe = list(f1 = c(1, 1),
                            f2 = c(2, 3)),
                  fl = list(P = paste('p',
                                      1:2,
                                      sep = ''),
                            SP = paste('sp',
                                       1:2,
                                       sep = '')),
                  inte = c(1, 15, 1, 1), # (2*2)
                  round = 1,
                  type = 'SPE',
                  design = 'CRD')
split_crd$X
split_crd$Z
summary(split_crd)

split_crd01 <- gexp(mu = 30,
                    r = 3,
                    fe = list(f1 = c(1, 1),
                              f2 = c(2, 3),
                              f3 = c(1, 1, 1)),
                    fl = list(P = paste('p',
                                        1:2,
                                        sep = ''),
                              A = paste('a',
                                        1:2,
                                        sep = ''),
                              B = paste('b',
                                        1:3,
                                        sep = '')),
                    round = 1,
                    type = 'SPE',
                    design = 'CRD')
split_crd01$X
split_crd01$Z
summary(split_crd01)

#! Randomized Complete Block Design (RCBD) - QL
# 1 factor, 3 blocks
rcbd <- gexp(mu = 0,
             r = 2,
             fe = list(f1 = c(5, 1, 1)),
             fl = list(TR = LETTERS[1:3]),
             blke = c(1, 2, 3),
             blkl = list(BLK = paste('B',
                                     1:3,
                                     sep = '')),
             round = 1,
             design = 'RCBD')
rcbd$X             
summary(rcbd)

#! Factorial Experiment (FE) - RCBD - QL
fe_rcbd <- gexp(mu = 30,
                r  = 2,
                fe = list(f1 = c(1, 1, 1),
                          f2 = c(2, 3)),
                blke = c(1, 3),
                inte = c(1, 15, 1, 1, 5, 1), # (3*2)
                round = 1,
                type = 'FE',
                design = 'RCBD')
summary(fe_rcbd)

#! Multivariated - RCBD - QL
rcbd_m <- gexp(mu = c(0, 2),
               fe = list(f1 = matrix(c(1, 1,
                                       5, 1,
                                       1, 1),
                                     ncol = 2,
                                     byrow = TRUE)),
               blke = matrix(c(2, 1,
                               1, 2,
                               1, 1),
                             ncol = 2,
                             byrow = TRUE),
               round = 1,
               design = 'RCBD')
summary(rcbd_m)

#! Split-plot Experiment (SPE) - RCBD - QL
split_rcbd <- gexp(mu = 30,
                   r = 2,
                   fe = list(f1 = c(1, 1),
                             f2 = c(2, 3),
                             f3 = c(1, 1, 1)),
                   fl = list(P = paste('p',
                                       1:2,
                                       sep = ''),
                             B = paste('b',
                                       1:2,
                                       sep = ''),
                             C = paste('c',
                                       1:3,
                                       sep = '')),
                   blke = c(1, 2),
                   blkl = list(BLK = paste('B',
                                           1:2,
                                           sep = '')),
                   round = 1,
                   type = 'SPE',
                   design = 'RCBD')
split_rcbd$Z
summary(split_rcbd)

#! Latin Square Design (LSD) - QL
#!. Warning!!!! r = 5 by default
lsd00 <- gexp(design = 'LSD')

#Set r = 1 to omiting warning
lsd01 <- gexp(mu = 30,
              r = 1,
              fe = list(f1 = c(1, 1, 10)),
              rowe = c(1, 1, 1),
              cole = c(1, 1, 1),
              rowl = list(Row = paste('r',
                                      1:3,
                                      sep = '')),
              coll = list(Col = paste('c',
                                      1:3,
                                      sep = '')),
              round = 0,
              design = 'LSD')
summary(lsd01)

#! Factorial Experiment (FE) - LSD - QL
fe_lsd <- gexp(mu = 30,
               r = 1,
               fe = list(f1 = c(1, 1),
                         f2 = c(2, 3)),
               rowe = c(1, 3, 2, 1),
               cole = c(2, 2, 1, 1),
               rowl = list(Row = paste('r',
                                       1:4,
                                       sep = '')),
               coll = list(Col = paste('c',
                                       1:4,
                                       sep = '')),
               inte = c(1, 15, 1, 1), # (2*2)
               round = 1,
               type = 'FE',
               design = 'LSD')
summary(fe_lsd)

#! Split-plot Experiment (SPE) - LSD - QL
split_lsd <- gexp(mu = 30,
                  r = 1,
                  fe = list(f1 = c(1, 1, 2),
                            f2 = c(2, 3, 1)),
                  fl = list(P = paste('p',
                                      1:3,
                                      sep = ''),
                            SP = paste('sp',
                                       1:3,
                                       sep = '')),
                  inte = c(1, 15, 1, 1, 1, 1, 1, 1, 1), # (3*3)
                  rowe = c(1, 1, 1),
                  cole = c(1, 1, 1),
                  rowl = list(Row = paste('r',
                                          1:3,
                                          sep = '')),
                  coll = list(Col = paste('c',
                                          1:3,
                                          sep = '')),
                  round = 1,
                  type = 'SPE',
                  design = 'LSD')
summary(split_lsd)

#!_____________________________
#! Quantitative Factor(s) (QT)
#!_____________________________

#! CRD - Orthogonal polynomials
# Linear effect
# Nonsense(error is 0)
# Default contrasts: Orthogonal contrasts
r <- 4  # (repet. number)
fln <- 5  # (factor levels number)
level <- c(0, 10, 20, 30, 40) 

crd_lo <- gexp(mu = 1, #in this case, mu=beta0 (intercept)
               r = r,
               fe = list(f1 = c(2,  0,  0,  0)), #b1 #b2 #b3 #b4
               fl = list(Dose = level),
               err = matrix(0,
                            nrow = r*fln),
               round = 2)
crd_lo$X
summary(crd_lo)

plot(Y1 ~ Dose,
     crd_lo$dfm)

# Quadratic effect
crd_qo <- gexp(mu = 2,
               r = r,
               fe = list(f1 = c(0,  3,  0,  0)), #b1 #b2 #b3 #b4
               fl = list(Dose = level),
               err = matrix(0,
                            nrow = r*fln))
summary(crd_qo)
plot(Y1 ~ Dose,
     crd_qo$dfm)

# Cubic effect
crd_co <- gexp(mu = 2,
               r = r,
               fe = list(f1 = c(1,  1,  3,  0)), #b1 #b2 #b3 #b4
               fl = list(Dose = level),
               err = matrix(0,
                            nrow = r*fln))
summary(crd_co)
plot(Y1 ~ Dose,
     crd_co$dfm)

# Not orthogonal polynomials
# Linear
cont_crd <- matrix(c(level,
                     level^2,
                     level^3,
                     level^4),
                   ncol = 4)

crd_l <- gexp(mu = 2,
              r = 2,
              fe = list(f1 = c(10,  0,  0,  0)), #b1 #b2 #b3 #b4
              fl = list(Dose = level),
              contrasts = list(Dose = cont_crd))
crd_l$X
summary(crd_l)

plot(Y1 ~ Dose,
     crd_l$dfm)

reg <- lm(Y1 ~ Dose + I(Dose^2) + I(Dose^3) + I(Dose^4),
          data = crd_l$dfm)

summary(reg)

# Linear and quadratic
level1 <- seq(0,30,by = 10)
cont_crd1 <- matrix(c(level1,
                      level1^2,
                      level1^3),
                    ncol = 3)
level2 <- 1:4
cont_crd2 <- matrix(c(level2,
                      level2^2,
                      level2^3),
                    ncol = 3)

crd_lq <- gexp(mu = 1,
               r = 2,
               fe = list(f1 = c(10,  0,   0), #b1  #b2  #b3
                         f2 = c(1,   8,   0)),
               fl = list(P = level1,
                         N = level2),
               contrasts = list(N = cont_crd2,
                                P = cont_crd1))
crd_lq$X
summary(crd_lq)

with(crd_lq$dfm,
     plot(Y1 ~ P))

with(crd_lq$dfm,
     plot(Y1 ~ N))

# Multivariated
crd_m <- gexp(mu = c(2, 10),
              r = 4,
              fe = list(f1 = matrix(c(10,  0, #L   Q
                                       0, 10,
                                       0,  0),
                                    ncol = 2,
                                    byrow = TRUE)),
              fl = list(Dose = level1),
              contrasts = list(Dose = cont_crd1))

with(crd_m$dfm,
     plot(Y1 ~ Dose))

with(crd_m$dfm,
     plot(Y2 ~ Dose))

# RCBD - Orthogonal polynomios
level3 <- c(0, 2, 4, 6) 
rcbd <- gexp(mu = 1,
             fe = list(f1 = c(3,  0,  0)), #b1 #b2 #b3
             blke = c(1, 2, 3),
             r = 2,
             fl = list(Dose = level3),
             blkl = list(Blk = c('B1', 'B2', 'B3')),
             design = 'RCBD')
rcbd$X
summary(rcbd)

# Not orthogonal
cont_crd3 <- matrix(c(level3, level3^2, level3^3),
                    ncol = 3)

rcbd_01 <- gexp(mu = 1,
                fe = list(f1 = c(3,  0,  0)), #b1 #b2 #b3
                blke = c(1, 2, 3),
                r = 2,
                fl = list(Dose = level3),
                blkl = list(Blk = c('B1', 'B2', 'B3')),
                contrasts = list(Dose = cont_crd3),
                design = 'RCBD')
rcbd_01$X
summary(rcbd_01)

# Orthogonal polynomios - LSD
lsd  <- gexp(mu = 1,      
             r = 1,
             fe = list(f1 = c(3,  0,  0)), #b1 #b2 #b3
             rowe = rep(1, 4),
             cole = rep(1, 4),
             fl = list(Dose = level1),
             design = 'LSD')
lsd$X
summary(lsd)

lsd_01  <- gexp(mu = 1,      
                r = 1,
                fe = list(f1 = c(3,  0,  0)), #b1 #b2 #b3
                rowe = rep(1, 4),
                cole = rep(1, 4),
                rowl = list(row = paste('r',
                                        1:4,
                                        sep = '')), 
                fl = list(Dose = level1),
                design = 'LSD')
lsd_01$X
summary(lsd_01)

# Not orthogonal 
lsd_02 <- gexp(mu = 1,      
               r = 1,
               fe = list(f1 = c(3,  0,  0)), #b1 #b2 #b3
               rowe = rep(1, 4),
               cole = rep(1, 4), 
               fl = list(Dose = level3),
               contrasts = list(Dose = cont_crd3),
               design = 'LSD') 
lsd_02$X
str(lsd_02)

#!__________________________________________________________________________
#! Hibrid: qualitative and quantitative factors in the same experiment - HB
#!__________________________________________________________________________
#! CRD - HB
r   <- 2  # (repet. number)
fl1 <- 4# (first factor levels number)
fl2 <- 3# (second factor levels number)

crd_hb <- gexp(mu = 1, #in this case, mu=beta0 (intercept)
               r = r,
               fe = list(f1 = c(2,  0,  0), #b1 #b2 #b3
                         f2 = c(1,  1,  3)),
               fl = list(Dose = seq(0,30,
                                    by = 10),
                         Trat = LETTERS[1:3]),
               err = matrix(0,
                            nrow = r*fl1*fl2),
               round = 2)
crd_hb$X
summary(crd_hb)

#Only one contrasts!
crd_hb2 <- gexp(mu = 1, #in this case, mu=beta0 (intercept)
                r = r,
                fe = list(f1 = c(2,  0,  0), #b1 #b2 #b3
                          f2 = c(1,  1,  3)),
                fl = list(Dose = level1,
                          Trat = LETTERS[1:3]),
                err = matrix(0,
                             nrow = r*fl1*fl2),
                contrasts = list(Dose = cont_crd1),           
                round = 2)
crd_hb2$X
summary(crd_hb)

#! RCBD - HB
r <- 2
blke <- c(1, 2)
level <- c(0, 10, 20, 30)
(error <- matrix(rep(0,
                     4^1*3^1*r*length(blke)),
                 ncol=1))

rcbd_hb <- gexp(mu = 2,
                err = error,
                r = r,
                fe = list(f1 = c(0, 1, 0),  # Qualitative
                          f2 = c(1, 0, 0)), # Quantitative linear
                fl = list(Var = LETTERS[1:3],
                          Dose = level),
                blke = blke,
                blkl = list(Blk = c('B1', 'B2')),
                design = 'RCBD')
rcbd_hb$X                
summary(rcbd_hb)
str(rcbd_hb)

#! LSD - QT
set.seed(3)
lsd <- gexp(mu = 100,
            r = 1,
            fe = list(f1 = c(10,   # b1
                             20,   # b2
                             0,    # b3
                             0)),  # b4
            fl = list(tra = seq(0,
                                40,
                                by = 10)),
            rowe = c(1, 2, 3, 4, 5),
            rowl = list(row = paste('r',
                                    1:5,
                                    sep = '')),
            cole = c(5, 4, 3, 2, 1),
            coll = list(col = paste('c',
                                    1:5,
                                    sep = '')),
            design = 'LSD')
summary(lsd)
plot(Y1 ~ tra, lsd$dfm)

#! FE - LSD - QT
fe_lsd <- gexp(mu = 10,
               fe = list(f1 = c(2, 3),
                         f2 = c(5,   # b1*
                                0,   # b2
                                0,   # b3
                                0)), # b4
               rowe = rep(1, 10),
               cole = rep(1, 10),
               fl = list(var = paste('v',
                                     1:2,
                                     sep = ''),
                         tra = seq(0,
                                   40,
                                   by = 10)),
               coll = list(col = paste('c',
                                       1:10,
                                       sep = '')),
               rowl = list(row = paste('r',
                                       1:10,
                                       sep = '')),
               type = 'FE',
               design = 'LSD')
fe_lsd$X
str(fe_lsd)
summary(fe_lsd)
plot(Y1 ~ tra, 
     fe_lsd$dfm)

#! SPE - QL - QT
spe_lsd <- gexp(mu = 100,
                r = 1,
                fe = list(f1 = c(2, 3, 1),
                          f2 = c(1,   # b1
                                 5,   # b2*
                                 1)), # b3
                fl = list(p = paste('p',
                                    1:3,
                                    sep = ''),
                          sp = seq(0,
                                   30,
                                   by = 10)),
                rowe = c(1, 2, 3),
                cole = c(3, 2, 1),
                rowl = list(row = paste('r',
                                        1:3,
                                        sep = '')),
                coll = list(col = paste('c',
                                        1:3,
                                        sep = '')),
                round = 1,
                type = 'SPE',
                design = 'LSD')
summary(spe_lsd)
plot(spe_lsd)


#++++++++++++++++++++++++++++#
#   MULTIVARIATE APPROACH    #
#++++++++++++++++++++++++++++#
#! CRD - QL
# Error = 0 - Nonsense (you can easily undertand the effects) 
r <- 2  # (repet. number)
fln <- 3  # (factor levels number)

crd_m01 <- gexp(mu = c(0,10),
                r = r,
                fe = list(f1 = matrix(c(1, 0, #Y1 Y2
                                        2, 1,
                                        3, 3),
                                      ncol = 2,
                                      byrow = TRUE)),
                err = mvtnorm::rmvnorm(n = fln * r,
                                       sigma = matrix(c(0, 0,
                                                        0, 0),
                                                      ncol = 2)),    
                round = 0)
summary(crd_m01)

#! FE - CRD - QL
r <- 2
crd_m_fe01 <- gexp(mu = c(0, 0),
                   r = r,
                   err = mvtnorm::rmvnorm(n = 3^1 * 2^1 * r,
                                          sigma = matrix(c(0, 0,
                                                           0, 0),
                                                         ncol = 2)),
                   fe = list(f1 = matrix(c(0, 3,  #X1  X1
                                           1, 4,  #X2  X2
                                           2, 5), #X3  X3
                                         ncol = 2,
                                         byrow = TRUE),
                             f2 = matrix(c(0, 2,  #X1  X1
                                           1, 3), #X2  X2
                                         ncol = 2,
                                         byrow = TRUE)),
                   type = 'FE',
                   round = 1)
summary(crd_m_fe01)

#! FE - CRD - QL
# Using default error
set.seed(30)
crd_m_fe02 <- gexp(mu = c(0, 2),
                   r = 3,
                   fe = list(f1 = matrix(c(1, 1,
                                           5, 1,
                                           1, 1),
                                         ncol = 2,
                                         byrow = TRUE),
                             f2 = matrix(c(1, 3,
                                           2, 2),
                                         ncol = 2,
                                         byrow = TRUE)),
                   type = 'FE',
                   round = 1)
summary(crd_m_fe02)

#! SPE - CRD - QL
# Using default error
crd_m_spe01 <- gexp(mu = c(0, 2),
                    r = 3,
                    fe = list(f1 = matrix(c(1, 1,
                                            5, 1,
                                            1, 1),
                                          ncol = 2,
                                          byrow = TRUE),
                              f2 = matrix(c(1, 3,
                                            2, 2),
                                          ncol = 2,
                                          byrow = TRUE)),
                    type = 'SPE',
                    round = 1)
summary(crd_m_spe01)

#! RCBD - QL
r <- 2  # (repet. number)
fln <- 3  # (factor levels number)
bln <- 3  # (block levels number)

rcbd_m01 <- gexp(mu = c(0,10),
                 r = r,
                 fe = list(f1 = matrix(c(1, 0, #Y1 Y2
                                         2, 1,
                                         3, 3),
                                       ncol = 2,
                                       byrow = TRUE)),
                 blke = matrix(c(2, 1,
                                 4, 1,
                                 6, 1),
                               ncol = 2,
                               byrow = TRUE),
                 err = mvtnorm::rmvnorm(n = fln * r * bln,
                                        sigma = matrix(c(0, 0,
                                                         0, 0),
                                                       ncol = 2)),
                 design = 'RCBD',
                 round = 0)
summary(rcbd_m01)

#! FE - RCBD - QL
rcbd_m_fe01 <- gexp(mu = c(0, 0),
                    r = r,
                    err = mvtnorm::rmvnorm(n = 3^1 * 2^1 * r * bln,
                                           sigma = matrix(c(0, 0,
                                                            0, 0),
                                                          ncol = 2)),
                    fe = list(f1 = matrix(c(0, 3,  #X1  X1
                                            1, 4,  #X2  X2
                                            2, 5), #X3  X3
                                          ncol = 2,
                                          byrow = TRUE),
                              f2 = matrix(c(0, 2,  #X1  X1
                                            1, 3), #X2  X2
                                          ncol = 2,
                                          byrow = TRUE)),
                    blke = matrix(c(2, 1,
                                    4, 1,
                                    6, 1),
                                  ncol = 2,
                                  byrow = TRUE), 
                    type = 'FE',
                    design = 'RCBD',
                    round = 1)
summary(rcbd_m_fe01)

#! SPE - RCBD - QL
rcbd_m_spe01 <- gexp(mu = c(0, 2),
                     r = 2,
                     fe = list(f1 = matrix(c(1, 1,
                                             5, 1,
                                             1, 1),
                                           ncol = 2,
                                           byrow = TRUE),
                               f2 = matrix(c(1, 3,
                                             2, 2),
                                           ncol = 2,
                                           byrow = TRUE),
                               f3 = matrix(c(1, 3,
                                             2, 2),
                                           ncol = 2,
                                           byrow = TRUE)), 
                     blke = matrix(c(2, 1,
                                     4, 1,
                                     6, 1),
                                   ncol = 2,
                                   byrow = TRUE),  
                     type = 'SPE',
                     design = 'RCBD',
                     round = 1)
summary(rcbd_m_spe01)

#! LSD - QL
lsd_m01 <- gexp(mu = c(0,10),
                r = 1,
                fe = list(f1 = matrix(c(1, 0, 
                                        2, 1,
                                        3, 3),
                                      ncol = 2,
                                      byrow = TRUE)),
                rowe = matrix(rep(1, 6),
                              ncol = 2),
                cole = matrix(rep(1, 6),
                              ncol = 2),
                err = mvtnorm::rmvnorm(n = 3^2,
                                       sigma = matrix(c(0, 0,
                                                        0, 0),
                                                      ncol = 2)),
                design = 'LSD',
                round = 0)
summary(lsd_m01)

#! LSD/FE - QL
lsd_m_fe01 <- gexp(mu = c(0, 0),
                   r = 1,
                   err = mvtnorm::rmvnorm(n = 3^1 * 2^1 * 6,
                                          sigma = matrix(c(0, 0,
                                                           0, 0),
                                                         ncol = 2)),
                   #Y1 Y2
                   fe = list(f1 = matrix(c(0, 3,  #X1  X1
                                           1, 4,  #X2  X2
                                           2, 5), #X3  X3
                                         ncol = 2,
                                         byrow = TRUE),
                             #Y1 Y2
                             f2 = matrix(c(0, 2,  #X1  X1
                                           1, 3), #X2  X2
                                         ncol = 2,
                                         byrow = TRUE)),
                   rowe = matrix(rep(1, 12),
                                 ncol = 2),
                   cole = matrix(rep(1, 12),
                                 ncol = 2), 
                   type = 'FE',
                   design = 'LSD',
                   round = 1)
summary(lsd_m_fe01)

#! SPE - LSD - QL
# Using default error
lsd_m_spe01 <- gexp(mu = c(0, 2),
                    r = 1,
                    fe = list(f1 = matrix(c(1, 1,
                                            5, 1,
                                            1, 1),
                                          ncol = 2,
                                          byrow = TRUE),
                              f2 = matrix(c(1, 3,
                                            2, 2),
                                          ncol = 2,
                                          byrow = TRUE)),
                    rowe = matrix(rep(1, 6),
                                  ncol = 2),
                    cole = matrix(rep(1, 6),
                                  ncol = 2),  
                    type = 'SPE',
                    design = 'LSD',
                    round = 1)
summary(lsd_m_spe01)

#! FE - RCBD - QL
r = 1
bln = 3
fe_rcbd_m <- gexp(mu = c(0, 0),
                  r = 1, 
                  err = mvtnorm::rmvnorm(n = 3^1 * 2^1 * r * bln,
                                         sigma = matrix(c(0, 0,
                                                          0, 0),
                                                        ncol = 2)),
                  fe = list(f1 = matrix(c(0, 3,  #X1  X1
                                          1, 4,  #X2  X2
                                          2, 5), #X3  X3
                                        ncol = 2,
                                        byrow = TRUE),
                            f2 = matrix(c(0, 2,  #X1  X1
                                          1, 3), #X2  X2
                                        ncol = 2,
                                        byrow = TRUE)),
                  blke = matrix(c(2, 1,
                                  4, 1,
                                  6, 1),
                                ncol = 2,
                                byrow = TRUE),
                  type = 'FE',
                  design = 'RCBD')
str(fe_rcbd_m)
summary(fe_rcbd_m)

#! SPE - RCBD - QL
spe_rcbd_m <- gexp(mu = c(0, 2),
                   r = 3,
                   fe = list(f1 = matrix(c(1, 1,
                                           5, 1,
                                           1, 1),
                                         ncol = 2,
                                         byrow = TRUE),
                             f2 = matrix(c(1, 3,
                                           2, 2),
                                         ncol = 2,
                                         byrow = TRUE),
                             f3 = matrix(c(1, 3,
                                           2, 2),
                                         ncol = 2,
                                         byrow = TRUE)),
                   blke = matrix(c(2, 1,
                                   4, 1,
                                   6, 1),
                                 ncol = 2,
                                 byrow = TRUE),
                   type = 'SPE',
                   design = 'RCBD')
str(spe_rcbd_m)
summary(spe_rcbd_m)

gexp documentation built on April 2, 2020, 9:07 a.m.