knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.width=6, fig.height=4 )
This tutorial demonstrates the mitscherlich()
function for fitting a continuous response model and estimating a critical soil test value. This function fits a Mitscherlich-type exponential regression model that follows a diminishing growth curve, and is sometimes also referred to as exponential "rise-to-the-max". Cerrato and Blackmer (1990) expressed it as:
$$ y = a * (1-e^{-c(x + b)}) $$
where\
a
= asymptote,\
b
= model-fitting parameter ( $-b$ = X-intercept),\
c
= curvature parameter.
This exponential model is extensively used in agriculture to describe crops response to input since the biological meaning of its curved response. The mitscherlich()
function works automatically with self-starting initial values to facilitate the model's convergence. The mitscherlich()
function allows the user to control the number of parameters, effectively constraining the response curve if theoretically justified:
type = 1, "no restriction", or "free"
(DEFAULT): three parameter model; $y = a * (1-e^{-c(x + b)})$type = 2, "asymptote 100", or "100"
: two parameter model where asymptote = 100% RY; $y = 100 * (1-e^{-c(x + b)})$type = 3, "asymptote 100 from 0", or "fixed":
one parameter model in which only the curvature varies and asymptote = 100 and model goes through origin; $y = 100 * (1-e^{-cx})$.Disadvantages this model might include:
lacks a parameter that can be directly interpreted as the critical soil test value
the model cannot be evaluated at the asymptote as CSTV would go to Inf
a fixed RY target for CSTV may be a somewhat arbitrary choice, but 95% is commonly used
model may not reach 95%, for which NaN
results
there is no apparent confidence interval for the derived CSTV. For this latter purpose, we recommend the user to use the boot_mitscherlich()
function for a reliable confidence interval estimation of parameters and CSTV via bootstrapping (resampling with replacement).
mitscherlich()
:type
select the type of parameterization of the model (type = 1, 2, or 3; see above
)data
(optional)stv
(soil test value) and ry
(relative yield) columns or vectors,target
(default = 95) to calculate the STV at a specific ry
target.tidy
TRUE-default- (produces a data.frame with results) or FALSE (store results as list)plot
TRUE (produces a ggplot as main output) or FALSE (no plot, only results as data.frame)resid
TRUE (produces plots with residuals analysis) or FALSE (no plot)library(soiltestcorr)
Suggested packages
# Install if needed library(ggplot2) # Plots library(dplyr) # Data wrangling library(tidyr) # Data wrangling library(purrr) # Mapping
# Native fake dataset from soiltestcorr package corr_df <- soiltestcorr::data_test
mitscherlich()
type = #
# Type = 1, no restriction (3 parameters) mitscherlich(corr_df, STV, RY, type = 1) # Type = 2, fixed asymptote value at 100 (2 parameters) mitscherlich(corr_df, STV, RY, type = 2) # Type = 3, fixed origin at 0 and asymptote at 100 (1 parameters) mitscherlich(corr_df, STV, RY, type = 3)
tidy
= FALSEIt returns a LIST (may more efficient for multiple fits at once)
# Using dataframe argument, tidy = FALSE -> return a LIST mitscherlich(data = corr_df, STV, RY, target = 90, tidy = FALSE)
You can call stv
and ry
vectors using the $
. The tidy
argument still applies for controlling the output type.
fit_vectors_list <-mitscherlich(stv = corr_df$STV, ry = corr_df$RY, tidy = FALSE) fit_vectors_tidy <-mitscherlich(stv = corr_df$STV, ry = corr_df$RY, tidy = TRUE)
# Example 1. Fake dataset manually created data_1 <- data.frame("RY" = c(65,80,85,88,90,94,93,96,97,95,98,100,99,99,100), "STV" = c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)) # Example 2. Native fake dataset from soiltestcorr package data_2 <- soiltestcorr::data_test # Example 3. Native dataset from soiltestcorr package, Freitas et al. (1966), used by Cate & Nelson (1971) data_3 <- soiltestcorr::freitas1966 %>% rename(STV = STK) data.all <- bind_rows(data_1, data_2, data_3, .id = "id")
Note: the stv
column needs to have the same name for all datasets if binding rows.
map()
# Run multiple examples at once with map() data.all %>% nest(data = c("STV", "RY")) %>% mutate(model = map(data, ~ mitscherlich(stv = .$STV, ry = .$RY))) %>% unnest(model)
group_modify()
Alternatively, with group_modify()
, nested data is not required. However, it still requires a grouping variable (in this case, id
) to identify each dataset. group_map()
may also be used, though list_rbind()
is required to return a tidy data frame of the model results instead of a list.
data.all %>% group_by(id) %>% group_modify(~ soiltestcorr::mitscherlich(data = ., STV, RY))
A suitable alternative for obtaining confidence intervals for parameters or derived quantities is bootstrapping. Bootstrapping is a resampling technique (with replacement) that draws samples from the original data with the same size. If you have groups within your data, you can specify grouping variables as arguments in order to maintain, within each resample, the same proportion of observations than in the original dataset.
This function returns a table with as many rows as the resampling size (n) containing the results for each resample.
set.seed(123) boot_mits <- boot_mitscherlich(corr_df, STV, RY, target = 90, n = 200) boot_mits %>% head(n = 5) # CSTV Confidence Interval quantile(boot_mits$CSTV, probs = c(0.025, 0.5, 0.975), na.rm = TRUE) # Plot boot_mits %>% ggplot2::ggplot(aes(x = CSTV))+ geom_histogram(color = "grey25", fill = "#9de0bf", bins = 10)
We can generate a ggplot with the same mitscherlich()
function.
We just need to specify the argument plot = TRUE
.
data_3 <- soiltestcorr::freitas1966 plot_mit <- mitscherlich(data_3, STK, RY, plot = TRUE) plot_mit
As ggplot object, plots can be adjusted in several ways, such as modifying titles and axis scales.
plot_mit + # Main title ggtitle("My own plot title")+ # Axis titles labs(x = "Soil Test K (ppm)", y = "Cotton RY(%)") + # Axis scales scale_x_continuous(limits = c(20,220), breaks = seq(0,220, by = 10))
Set the argument resid = TRUE
.
# Residuals plot mitscherlich(data_3, STK, RY, resid = TRUE)
Cerrato, M. E., & Blackmer, A. M. (1990). Comparison of models for describing corn yield response to nitrogen fertilizer. Agronomy Journal, 82(1), 138--143. https://doi.org/10.2134/agronj1990.00021962008200010030x
Melsted, S.W. and Peck, T.R. (1977). The Mitscherlich-Bray Growth Function. In Soil Testing (eds T. Peck, J. Cope and D. Whitney). 10.2134/asaspecpub29.c1
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.