---
title: "Getting Initial Parameters for Growth Models"
author: "Maks Necki"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Getting parameters}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

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


This vignette introduces two functions, *get_init_pars_logistic* and *get_init_pars_baranyi*, which help find reasonable initial parameter approximations for Logistic and Baranyi growth models. These initial approximations can be used as starting values for the subsequent optimization algorithm.

## The get_init_pars_logistic Function
### Introduction
The get_init_pars_logistic function aims to find reasonable initial approximations for parameters of the Logistic growth model, including K (carrying capacity), lag (lag phase duration), and gr_rate (growth rate). These initial values are based on the provided growth curve and some optional initial values.

### Usage
The function takes the following parameters:

- **data_this_curve**: Data from a specific growth curve with columns "time" and "biomass."
- **this_n0**: The initial biomass.
- **init_K**: Initial value for the carrying capacity parameter K.
- **init_lag**: Initial value for the lag parameter.
- **init_gr_rate**: Initial value for the growth rate.
- **min_b**: Minimum biomass threshold for the exponential phase (default is 0.2).
- **min_a**: Maximum biomass threshold for the exponential phase (default is 0.8).
The function returns a list of initial parameter approximations: init_K, init_lag, and init_gr_rate.

### Examples
``` {r eval = FALSE}
# Load required libraries
library(dplyr)

# Generate example growth curve data
set.seed(123)
time <- 1:10
biomass <- c(0.1, 0.3, 0.7, 1.5, 3.0, 5.0, 8.0, 12.0, 18.0, 25.0)
gr_curve <- data.frame(time = time, biomass = biomass)

# Get initial parameters for the Logistic model
initial_params <- get_init_pars_logistic(gr_curve, this_n0 = 0.1, init_K = 30, init_lag = 0.5, init_gr_rate = 0.5)

# Print the initial parameter approximations
initial_params
```

## The get_init_pars_baranyi Function
### Introduction
The get_init_pars_baranyi function is designed to find reasonable initial approximations for parameters of the Baranyi growth model, including init_mumax (maximum specific growth rate) and lag (lag phase duration). These initial values are based on the provided growth curve and some optional initial values.

### Usage
The function takes the following parameters:

- **data_this_curve**: Data from a specific growth curve with columns "time" and "biomass."
- **this_n0**: The initial biomass.
- **init_lag**: Initial value for the lag parameter.
- **init_gr_rate**: Initial value for the growth rate.
- **min_b**: Minimum biomass threshold for the exponential phase (default is 0.2).
- **min_a**: Maximum biomass threshold for the exponential phase (default is 0.8).
The function returns a list of initial parameter approximations: init_mumax and init_lag.

### Examples
``` {r eval = FALSE}
# Load required libraries
library(dplyr)

# Generate example growth curve data
set.seed(123)
time <- 1:10
biomass <- c(0.1, 0.3, 0.7, 1.5, 3.0, 5.0, 8.0, 12.0, 18.0, 25.0)
gr_curve <- data.frame(time = time, biomass = biomass)

# Get initial parameters for the Baranyi model
initial_params <- get_init_pars_baranyi(gr_curve, this_n0 = 0.1, init_lag = 0.5, init_gr_rate = 0.5)

# Print the initial parameter approximations
initial_params
```
### Conclusion
These functions are useful for obtaining initial parameter approximations for Logistic and Baranyi growth models. You can use these initial values as starting points for optimization algorithms to fit growth models to your data accurately.
