Using optsize for Field Experiment Design

Introduction

The optsize package helps design field experiments by determining optimum plot size and shape, accounting for soil heterogeneity.

Example Dataset

A rice uniformity trial dataset is used to demonstrate functionality. Field size: 20 × 38 m, spacing 20 × 20 cm, 1 m border excluded (net area 18 × 36 m), yields recorded from 1 × 1 m plots.

library(optsize)
# Load field yield data
data <- system.file("extdata", "data.csv", package = "optsize")
mat <- read.csv(data, header = FALSE)
df_mat <- as.matrix(data)
df_mat <- apply(df_mat, 2, as.numeric)
#> Warning in apply(df_mat, 2, as.numeric): NAs introduced by coercion
mode(df_mat)  # should return "numeric"
#> [1] "numeric"
# Generate possible plot shapes
res <- generate_plot_shapes(mat)
res
#>    plot_size_units shape_h shape_w num_plots shape   V_between V_per_unit_area
#> 1                1       1       1       648   1x1    9031.382        9031.382
#> 2                2       1       2       324   1x2   31282.260        7820.565
#> 3                2       2       1       324   2x1   31259.970        7814.993
#> 4                3       1       3       216   1x3   65614.958        7290.551
#> 5                3       3       1       216   3x1   66012.856        7334.762
#> 6                4       4       1       162   4x1  112710.911        7044.432
#> 7                4       2       2       162   2x2  113692.096        7105.756
#> 8                6       1       6       108   1x6  231685.879        6435.719
#> 9                6       6       1       108   6x1  234563.120        6515.642
#> 10               6       2       3       108   2x3  243534.564        6764.849
#> 11               6       3       2       108   3x2  244669.416        6796.373
#> 12               8       4       2        81   4x2  422164.299        6596.317
#> 13               9       1       9        72   1x9  483485.623        5968.958
#> 14               9       9       1        72   9x1  505612.734        6242.133
#> 15               9       3       3        72   3x3  525254.345        6484.622
#> 16              12      12       1        54  12x1  827820.090        5748.751
#> 17              12       2       6        54   2x6  887072.645        6160.227
#> 18              12       6       2        54   6x2  891798.497        6193.045
#> 19              12       4       3        54   4x3  920952.719        6395.505
#> 20              18       1      18        36  1x18 1847745.799        5702.919
#> 21              18      18       1        36  18x1 1513452.076        4671.148
#> 22              18       2       9        36   2x9 1859865.854        5740.327
#> 23              18       9       2        36   9x2 1955124.299        6034.334
#> 24              18       3       6        36   3x6 1911145.854        5898.598
#> 25              18       6       3        36   6x3 1938331.632        5982.505
#> 26              24      12       2        27  12x2 3190006.469        5538.206
#> 27              24       4       6        27   4x6 3379330.914        5866.894
#> 28              27       3       9        24   3x9 4013336.859        5505.263
#> 29              27       9       3        24   9x3 4281305.609        5872.847
#>    CV_percent   p_value test_used
#> 1   12.962480        NA      <NA>
#> 2   12.062298 0.9948933    F-test
#> 3   12.058000 0.9948933    F-test
#> 4   11.646386 0.9646868    F-test
#> 5   11.681645 0.9646868    F-test
#> 6   11.448115 0.9562144    F-test
#> 7   11.497837 0.9562144    F-test
#> 8   10.942323 0.9896631  Bartlett
#> 9   11.010058 0.9896631  Bartlett
#> 10  11.218636 0.9896631  Bartlett
#> 11  11.244745 0.9896631  Bartlett
#> 12  11.078010        NA      <NA>
#> 13  10.538050 0.9411901  Bartlett
#> 14  10.776494 0.9411901  Bartlett
#> 15  10.983818 0.9411901  Bartlett
#> 16  10.341838 0.9841564  Bartlett
#> 17  10.705559 0.9841564  Bartlett
#> 18  10.734038 0.9841564  Bartlett
#> 19  10.908083 0.9841564  Bartlett
#> 20  10.300531 0.9795267  Bartlett
#> 21   9.322295 0.9795267  Bartlett
#> 22  10.334258 0.9795267  Bartlett
#> 23  10.595603 0.9795267  Bartlett
#> 24  10.475757 0.9795267  Bartlett
#> 25  10.550002 0.9795267  Bartlett
#> 26  10.150689 0.8842567    F-test
#> 27  10.447566 0.8842567    F-test
#> 28  10.120455 0.8781609    F-test
#> 29  10.452865 0.8781609    F-test

# Fit variance law to determine optimum plot size
out_var <- fit_variance_law(mat)
print(out_var$plots)
#> $original

#> 
#> $loglog

out_var
#> $df_shapes
#>    plot_size_units shape_h shape_w num_plots shape   V_between V_per_unit_area
#> 1                1       1       1       648   1x1    9031.382        9031.382
#> 2                2       1       2       324   1x2   31282.260        7820.565
#> 3                2       2       1       324   2x1   31259.970        7814.993
#> 4                3       1       3       216   1x3   65614.958        7290.551
#> 5                3       3       1       216   3x1   66012.856        7334.762
#> 6                4       4       1       162   4x1  112710.911        7044.432
#> 7                4       2       2       162   2x2  113692.096        7105.756
#> 8                6       1       6       108   1x6  231685.879        6435.719
#> 9                6       6       1       108   6x1  234563.120        6515.642
#> 10               6       2       3       108   2x3  243534.564        6764.849
#> 11               6       3       2       108   3x2  244669.416        6796.373
#> 12               8       4       2        81   4x2  422164.299        6596.317
#> 13               9       1       9        72   1x9  483485.623        5968.958
#> 14               9       9       1        72   9x1  505612.734        6242.133
#> 15               9       3       3        72   3x3  525254.345        6484.622
#> 16              12      12       1        54  12x1  827820.090        5748.751
#> 17              12       2       6        54   2x6  887072.645        6160.227
#> 18              12       6       2        54   6x2  891798.497        6193.045
#> 19              12       4       3        54   4x3  920952.719        6395.505
#> 20              18       1      18        36  1x18 1847745.799        5702.919
#> 21              18      18       1        36  18x1 1513452.076        4671.148
#> 22              18       2       9        36   2x9 1859865.854        5740.327
#> 23              18       9       2        36   9x2 1955124.299        6034.334
#> 24              18       3       6        36   3x6 1911145.854        5898.598
#> 25              18       6       3        36   6x3 1938331.632        5982.505
#> 26              24      12       2        27  12x2 3190006.469        5538.206
#> 27              24       4       6        27   4x6 3379330.914        5866.894
#> 28              27       3       9        24   3x9 4013336.859        5505.263
#> 29              27       9       3        24   9x3 4281305.609        5872.847
#>    CV_percent   p_value test_used
#> 1   12.962480        NA      <NA>
#> 2   12.062298 0.9948933    F-test
#> 3   12.058000 0.9948933    F-test
#> 4   11.646386 0.9646868    F-test
#> 5   11.681645 0.9646868    F-test
#> 6   11.448115 0.9562144    F-test
#> 7   11.497837 0.9562144    F-test
#> 8   10.942323 0.9896631  Bartlett
#> 9   11.010058 0.9896631  Bartlett
#> 10  11.218636 0.9896631  Bartlett
#> 11  11.244745 0.9896631  Bartlett
#> 12  11.078010        NA      <NA>
#> 13  10.538050 0.9411901  Bartlett
#> 14  10.776494 0.9411901  Bartlett
#> 15  10.983818 0.9411901  Bartlett
#> 16  10.341838 0.9841564  Bartlett
#> 17  10.705559 0.9841564  Bartlett
#> 18  10.734038 0.9841564  Bartlett
#> 19  10.908083 0.9841564  Bartlett
#> 20  10.300531 0.9795267  Bartlett
#> 21   9.322295 0.9795267  Bartlett
#> 22  10.334258 0.9795267  Bartlett
#> 23  10.595603 0.9795267  Bartlett
#> 24  10.475757 0.9795267  Bartlett
#> 25  10.550002 0.9795267  Bartlett
#> 26  10.150689 0.8842567    F-test
#> 27  10.447566 0.8842567    F-test
#> 28  10.120455 0.8781609    F-test
#> 29  10.452865 0.8781609    F-test
#> 
#> $V1
#> [1] 9031.382
#> 
#> $b_hat
#> [1] 0.1552106
#> 
#> $R2_log
#> [1] 0.9556521
#> 
#> $x_opt
#> [1] 27
#> 
#> $Vx_opt
#> [1] 5414.912
#> 
#> $best_shape
#>    plot_size_units shape_h shape_w num_plots shape V_between V_per_unit_area
#> 28              27       3       9        24   3x9   4013337        5505.263
#>    CV_percent   p_value test_used
#> 28   10.12046 0.8781609    F-test
#> 
#> $plots
#> $plots$original

#> 
#> $plots$loglog


# Fertility analysis
ferti <- ferti_analysis(mat)
print(ferti$heatmap)

ferti
#> $heatmap

#> 
#> $serial_correlation
#> $serial_correlation$vertical
#> [1] 0.7314371
#> 
#> $serial_correlation$horizontal
#> [1] 0.7439238
#> 
#> 
#> $moving_avg_values
#>           [,1]     [,2]     [,3]     [,4]     [,5]     [,6]     [,7]     [,8]
#>  [1,] 824.7778 846.5556 889.5556 923.0000 926.5556 900.2222 874.6667 882.6667
#>  [2,] 838.1111 864.8889 888.1111 888.2222 865.2222 847.0000 844.1111 857.2222
#>  [3,] 833.1111 832.3333 847.1111 841.8889 822.0000 819.7778 822.3333 844.4444
#>  [4,] 862.7778 843.2222 840.4444 810.7778 802.0000 793.8889 805.2222 802.0000
#>  [5,] 872.6667 860.1111 858.5556 841.4444 836.1111 819.8889 814.1111 821.2222
#>  [6,] 897.2222 891.8889 880.4444 853.3333 835.6667 807.6667 811.3333 826.4444
#>  [7,] 861.5556 875.1111 862.3333 849.6667 813.7778 796.7778 809.7778 836.3333
#>  [8,] 821.5556 829.4444 811.3333 801.4444 761.8889 753.3333 765.6667 788.8889
#>  [9,] 791.1111 805.3333 793.4444 781.6667 757.3333 741.3333 750.2222 745.5556
#> [10,] 806.3333 821.8889 806.2222 796.6667 779.4444 757.6667 755.4444 744.3333
#> [11,] 821.8889 822.3333 798.0000 787.7778 779.6667 762.1111 755.1111 731.5556
#> [12,] 840.2222 808.2222 763.0000 762.7778 766.8889 767.6667 752.5556 739.3333
#> [13,] 842.4444 785.2222 727.2222 722.2222 747.8889 759.7778 735.1111 725.3333
#> [14,] 847.0000 782.3333 726.6667 718.7778 747.5556 756.1111 732.1111 743.1111
#> [15,] 816.3333 786.1111 751.6667 753.8889 751.8889 754.7778 714.5556 730.7778
#> [16,] 801.5556 777.0000 758.0000 752.6667 741.5556 740.7778 703.1111 720.4444
#> [17,] 764.7778 753.1111 749.2222 745.8889 750.7778 740.4444 704.6667 704.8889
#> [18,] 766.1111 736.1111 726.4444 713.6667 738.5556 722.8889 714.7778 716.1111
#> [19,] 752.8889 726.1111 718.5556 711.2222 728.8889 703.0000 708.0000 699.8889
#> [20,] 757.2222 739.5556 726.4444 719.6667 717.5556 692.6667 701.0000 696.7778
#> [21,] 755.5556 741.7778 730.0000 715.6667 706.0000 679.7778 667.4444 664.4444
#> [22,] 748.4444 730.7778 720.2222 704.4444 698.1111 675.1111 659.8889 664.7778
#> [23,] 719.2222 700.7778 704.3333 688.1111 685.7778 669.0000 655.7778 668.0000
#> [24,] 694.4444 687.7778 699.5556 690.4444 681.0000 666.8889 663.5556 676.8889
#> [25,] 685.8889 696.5556 701.4444 688.8889 670.6667 659.0000 656.8889 664.1111
#> [26,] 701.2222 705.3333 703.0000 685.7778 652.0000 624.3333 611.4444 625.7778
#> [27,] 730.1111 697.0000 679.7778 662.5556 636.6667 612.2222 600.4444 607.2222
#> [28,] 726.2222 690.8889 677.8889 660.3333 622.7778 582.5556 576.7778 605.7778
#> [29,] 729.6667 698.3333 681.3333 660.8889 635.3333 609.5556 613.6667 634.5556
#> [30,] 694.3333 688.7778 661.5556 633.8889 612.5556 592.4444 594.6667 620.0000
#> [31,] 684.0000 688.8889 658.8889 632.6667 620.3333 613.1111 610.7778 619.6667
#> [32,] 669.4444 690.3333 646.3333 621.0000 603.1111 599.2222 587.5556 589.7778
#> [33,] 662.6667 689.0000 659.8889 636.5556 620.8889 609.1111 594.2222 591.3333
#> [34,] 648.1111 667.1111 648.4444 637.2222 630.1111 616.8889 593.0000 583.5556
#>           [,9]    [,10]    [,11]    [,12]    [,13]    [,14]    [,15]    [,16]
#>  [1,] 887.1111 887.1111 867.8889 840.8889 804.7778 814.5556 860.6667 911.6667
#>  [2,] 883.7778 888.7778 888.5556 836.6667 793.5556 780.1111 830.8889 897.3333
#>  [3,] 867.7778 872.2222 873.0000 815.0000 774.7778 744.1111 787.2222 853.0000
#>  [4,] 831.3333 860.7778 869.1111 821.2222 795.4444 753.6667 766.6667 812.4444
#>  [5,] 847.1111 864.6667 855.3333 810.8889 780.5556 733.3333 731.8889 780.7778
#>  [6,] 845.5556 846.4444 822.2222 795.6667 776.0000 750.1111 740.7778 774.4444
#>  [7,] 854.1111 842.4444 820.0000 809.4444 776.8889 742.3333 728.6667 761.5556
#>  [8,] 812.3333 808.7778 800.8889 801.1111 772.5556 749.4444 730.2222 751.8889
#>  [9,] 791.8889 796.0000 814.2222 803.2222 776.6667 735.0000 712.1111 729.0000
#> [10,] 783.0000 782.2222 785.7778 765.0000 757.6667 731.4444 722.0000 720.5556
#> [11,] 754.2222 756.1111 757.5556 731.6667 726.5556 704.1111 704.2222 701.2222
#> [12,] 740.5556 745.8889 732.3333 723.2222 707.3333 704.8889 696.0000 694.4444
#> [13,] 727.8889 745.1111 735.7778 733.1111 717.0000 714.8889 693.6667 698.8889
#> [14,] 750.4444 769.7778 740.8889 740.7778 721.4444 722.1111 719.7778 723.3333
#> [15,] 735.3333 767.2222 748.2222 736.0000 727.3333 725.3333 749.3333 743.3333
#> [16,] 729.0000 767.7778 752.5556 731.8889 724.2222 723.0000 751.2222 736.7778
#> [17,] 710.2222 750.1111 752.5556 728.0000 711.3333 704.2222 714.6667 697.8889
#> [18,] 735.0000 768.6667 770.7778 751.7778 728.0000 705.2222 691.8889 676.6667
#> [19,] 713.4444 731.1111 751.5556 748.0000 726.5556 692.4444 670.2222 660.6667
#> [20,] 723.5556 736.5556 753.6667 749.2222 739.4444 714.4444 689.8889 677.2222
#> [21,] 699.5556 716.6667 733.6667 722.2222 720.3333 705.6667 683.2222 667.0000
#> [22,] 706.3333 716.1111 717.0000 698.6667 699.1111 687.8889 668.6667 655.1111
#> [23,] 695.3333 703.1111 700.1111 693.5556 694.3333 682.0000 653.3333 639.1111
#> [24,] 694.4444 704.7778 696.8889 700.7778 688.5556 690.0000 667.2222 660.0000
#> [25,] 675.2222 697.0000 698.6667 702.4444 676.5556 680.0000 672.7778 667.3333
#> [26,] 646.2222 677.7778 671.3333 671.7778 639.5556 646.6667 655.0000 663.4444
#> [27,] 621.1111 636.8889 639.5556 641.6667 626.6667 630.1111 641.7778 653.8889
#> [28,] 627.2222 642.1111 631.2222 637.1111 629.5556 651.0000 648.7778 659.4444
#> [29,] 647.3333 653.1111 643.7778 653.7778 643.0000 669.2222 660.1111 680.6667
#> [30,] 639.7778 652.5556 635.8889 645.0000 629.3333 658.2222 642.5556 665.1111
#> [31,] 636.3333 649.8889 645.3333 648.1111 634.2222 655.6667 664.5556 683.6667
#> [32,] 615.4444 634.1111 645.8889 644.0000 644.0000 657.3333 659.4444 656.4444
#> [33,] 604.0000 624.7778 642.7778 656.2222 667.1111 685.7778 688.8889 673.0000
#> [34,] 581.8889 606.7778 624.7778 653.7778 666.3333 685.4444 673.3333 658.0000