---
title: "logisLateDicr"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{logisLateDicr}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

## 1. Package loading

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

```{r setup}
library(phenolocrop)
```

## 2. Data

The data frame should include the columns of the objective trait and time point.
In the example rice CH data, date column is for the measuring date, height is for CH (m),
id is for the cultivar id, and x is for the days after sowing.
The following CH time-series data was generated by the computer simulation.

```{r}
riceCH_eg
```

## 3. Estimate model parameters

```{r}
riceCH_eg |>
  logisLateDicr("x", "height")
```

## 4. Plot time-series model and measured CH data

```{r}
x_vec <- 1:max(riceCH_eg$x)
y <- riceCH_eg |>
  logisLateDicr("x", "height") |>
  phenololine(x = x_vec, method = "logisLateDicr")
plot(x_vec, y, type = "l", ylab = "rice CH", xlab = "Dayes after sowing")
points(riceCH_eg$x, riceCH_eg$height)
```

## 5. Time-series model

Time-series model of `logisLateDicr` for the rice CH is as the following.

$$
\mathrm{CH}=
\begin{cases}
\frac{K}{1+\mathrm{exp}(r(d_0-x))} & (x\le d_1)\\
\frac{K}{1+\mathrm{exp}(r(d_0-x))}-a(x-d_1)^2 & (x>d_1)
\end{cases}
$$

## 6. Reference

S. Taniguchi et al., (2022) Prediction of heading date, culm length, and
biomass from canopy-height-related parameters derived from time-series UAV observations of rice.
Frontiers in Plant Science, 13:998803.
