Quick Reference
Common tasks at a glance
A concise reference for common tasks when analyzing field trial data with the mandala package.
Basic Model Syntax
Simple RCBD
model <- mandala(
fixed = yield ~ genotype,
random = ~ block,
data = field_data
)Alpha-Lattice Design
model <- mandala(
fixed = yield ~ genotype,
random = ~ rep + rep:incomplete_block,
data = field_data
)Multi-Environment Trial
model <- mandala(
fixed = yield ~ genotype + env + genotype:env,
random = ~ env:block,
data = field_data
)Spatial Model
model <- mandala(
fixed = yield ~ genotype,
random = ~ block,
data = field_data,
R_formula = ~ ar1(row):ar1(col)
)Extracting Results
Variance Components
var_comps <- summary(model)$varcomp
print(var_comps)Heritability
h2 <- h2_estimates(
random_mod = model_random,
fixed_mod = model_fixed,
genotype = "genotype"
)BLUEs (Fixed Effects)
blues <- model$BLUEs
head(blues)BLUPs (Random Effects)
blups <- mandala_predict(model, classify_term = "genotype")
head(blups)Package Comparison
Mandala vs Sommer vs lme4
| Syntax | Mandala | Sommer | lme4 |
|---|---|---|---|
| Model fit | mandala() |
mmer() |
lmer() |
| Variance components | $varcomp |
summary()$varcomp |
VarCorr() |
| BLUPs | mandala_predict() |
randef() |
ranef() |
Common Experimental Designs
1. RCBD
| Effect | Type |
|---|---|
| Genotype | Fixed |
| Block | Random |
yield ~ genotype + (1|block)2. Alpha-Lattice
| Effect | Type |
|---|---|
| Genotype | Fixed |
| Rep | Random |
| Incomplete Block(Rep) | Random |
yield ~ genotype + (1|rep) + (1|rep:incomplete_block)3. Row-Column
| Effect | Type |
|---|---|
| Genotype | Fixed |
| Row | Random |
| Column | Random |
yield ~ genotype + (1|row) + (1|col)4. Multi-Environment Trial
| Effect | Type |
|---|---|
| Genotype | Fixed |
| Environment | Fixed |
| G×E | Fixed |
| Block(Env) | Random |
yield ~ genotype + env + genotype:env + (1|env:block)Heritability Formulas
Plot Basis
\[h^2 = \frac{\sigma^2_g}{\sigma^2_g + \sigma^2_e}\]
Entry-Mean Basis (Single Environment)
\[h^2 = \frac{\sigma^2_g}{\sigma^2_g + \sigma^2_e/r}\]
Where r = number of replications
Across Multiple Environments
\[h^2 = \frac{\sigma^2_g}{\sigma^2_g + \sigma^2_{g \times e}/e + \sigma^2_e/(e \times r)}\]
Where e = environments, r = reps per environment
Data Preparation Checklist
Model Checking
Check Convergence
summary(model)
# Look for warningsExamine Residuals
plot(fitted(model), residuals(model))
abline(h = 0, col = "red")Check Normality
qqnorm(residuals(model))
qqline(residuals(model))Common Issues
| Issue | Solution |
|---|---|
| Model doesn’t converge | Check for missing data, verify design |
| Negative variance estimates | Simplify model, check data structure |
| Very low heritability | Check data quality, model specification |
Visualization Templates
Genotype Performance
library(ggplot2)
blues %>%
ggplot(aes(x = reorder(genotype, estimate), y = estimate)) +
geom_point(size = 3) +
geom_errorbar(aes(ymin = lower_ci, ymax = upper_ci), width = 0.2) +
coord_flip() +
theme_minimal() +
labs(x = "Genotype", y = "Estimated Yield")G×E Interaction
gxe_data %>%
ggplot(aes(x = environment, y = mean_yield,
group = genotype, color = genotype)) +
geom_line() +
geom_point(size = 2) +
theme_minimal()Field Heatmap
field_data %>%
ggplot(aes(x = col, y = row, fill = yield)) +
geom_tile() +
scale_fill_viridis_c() +
theme_minimal()Resources
- Mandala: https://listoagriculture.com/products
- Sommer: https://cran.r-project.org/package=sommer
- lme4: https://cran.r-project.org/package=lme4
Key References
- Piepho et al. (2003) - BLUP in plant breeding
- Gilmour et al. (1997) - Spatial analysis
- Smith et al. (2005) - Variety trials