Installation
You can install the package from CRAN:
install.packages("ofemeantest")Also, you can install the development version of ofemeantest from GitHub with:
# install.packages("pak")
pak::pkg_install("PPaccioretti/ofemeantest")Example
The example dataset comprised a field trial of corn (Zea mays L.), where the impact of broadcast phosphorus fertilization was evaluated. The treatment strip received superphosphate at rates ranging from 250 to 500 [0-21-0], while the control strip received no P fertilizer (0 ). Each strip was 2.2 ha in area, totaling 100 ha. Raw grain yield monitor data for each each single strip were cleaned following the protocol proposed by Vega et al. (2019).
library(ofemeantest)
data("ofe_f2")The ofemt function first creates a regular artificial grid over the area, including the strips to be analyzed. The grid spacing (cellsize) was set to 9 m. This grid overlaid the point data from the yield map, assigning each georeferenced data point to a corresponding grid cell. Each grid cell contained a minimum of four data points (min_per_cell = 4). Empty cells or cells with less than four data points are removed. The median of the yield data is calculated for each cell. A one-way ANOVA is fitted to the cell medians to compare treatments. From the residuals of the fitted model, the magnitude of spatial autocorrelation is estimated using the approximate profile likelihood estimator of spatial dependence (Rho) and the Moran index (MI). An effective sample size (ESS) is then calculated. Second, ofemt randomly samples grid cells without replacement using the ESS. The yield data from both strips (treatment and control) are used to perform a permutational ANOVA with 2000 iterations per test (n_p). This procedure provides a p-value for the comparison of treatment means. The permutational ANOVA is repeated on 200 random samples of grid cells (n_s) using the same sampling procedure. The significance level for comparing means (alpha), is left at their default value (0.05). The resulting permutation p-values are collected to generate an empirical p-value distribution. Finally, the median p-value is calculated to compare the means.
ofemt(
data = ofe_f2,
y = "Yield_tn",
x = "Treatment",
cellsize = 9,
min_per_cell = 4,
n_p = 2000,
n_s = 200,
alpha = 0.05,
shift = 0,
p_adjust_method = "none",
crs = NULL
)
#> `grid` not provided: building one internally via `make_ofe_grid()`. Pass a pre-built `ofe_grid` to inspect or reuse the selection.
#>
#> === OFE permutation analysis ===
#> Cellsize: 9 x 9 | Total cells: 1840 | Selected cells: 554
#> Obs/cell (min/median/max): 4 / 5 / 7
#> n: 554 | ESS: 97 | Rho: 0.652 | Moran's I: 0.548
#>
#> --- Means comparison (sorted by decreasing mean) ---
#> Treatment Yield_tn_mean letters
#> Fertilized 5.280402 a
#> Control 4.760095 b
#>
#> --- Pairwise tests (median p across runs) ---
#> Comparison p_value p_adj
#> Fertilized vs. Control 0.0055 0.0055The results show that out of the total number of cells selected (554), the ESS was 97, with a magnitude of autocorrelation (Rho) of 0.65. The fertilization treatment showed significant differences compared to the control (p < 0.05).
The average yield of the fertilized strip was 5.28 , while that of the control was 4.76 .
References
Córdoba, M., Paccioretti, P., & Balzarini, M. (2025). A new method to compare treatments in unreplicated on-farm experimentation. Precision Agriculture, 26(1), 4. https://doi.org/10.1007/s11119-024-10206-0
Vega A., Córdoba M., Balzarini M. 2019. Protocol for automating error removal from yield maps. Precis. Agric. 20: 1030–1044. https://doi.org/10.1007/s11119-018-09632-8
Hacer funcion make_grid. La funcion va atener dentro dos funciones pricipales Una que hace la grilla. all_cells_grid Otra que selecciona las celdas de la grilla en funcion de las observaciones. select_grid