---
title: "doubleLogis"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{doubleLogis}
  %\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 CIg data, date column is for the measuring date, 
id is for the cultivar id, and x is for the days after sowing.
The following CIg time-series data was generated by the computer simulation.

```{r}
riceCIg_eg
```

## 3. Estimate model parameters

```{r}
riceCIg_eg |>
  doubleLogis("x", "CIg")
```

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

```{r}
x_vec <- 1:max(riceCIg_eg$x)
y <- riceCIg_eg |>
  doubleLogis("x", "CIg") |>
  phenololine(x = x_vec, method = "doubleLogis")
plot(x_vec, y, type = "l", ylab = "rice CIg", 
     xlab = "Dayes after sowing", ylim = range(riceCIg_eg$CIg))
points(riceCIg_eg$x, riceCIg_eg$CIg)
```

## 5. Time-series model

Time-series model of `doubleLogis` for the rice CIg is as the following.

$$
\mathrm{CIg}=y_{max}\left( \frac{1}{1+\mathrm{exp}(r_2(d_2 - x))}-
\frac{1}{1+\mathrm{exp}(r_3(d_3 - x))}
\right)
$$

## 6. Reference

S. Taniguchi et al. (2025) Phenology analysis for trait prediction using UAVs
in a MAGIC rice population with different transplanting protocols. 
Frontiers in Artificial Intelligence, 7, 1477637.
