---
title: "Using optsize for Field Experiment Design"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Using optsize for Field Experiment Design}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---
# 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.

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

```{r example}
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)
mode(df_mat)  # should return "numeric"
# Generate possible plot shapes
res <- generate_plot_shapes(mat)
res

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

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