# Kinetic Analysis (Beta)
Starting in *Labrador* v2.2.0, some metrics will be calculated for growth curves automatically. These values are calculated by fitting normalized data to this version of the [Richard's growth model](#growth-model). When the minimum datum is below 0, then the following formula is applied to normalize the data above 0 `normalized data set = data - minimum of dataset`. This normalization is crucial because, in subsequent calculations, the logarithm of the dataset is utilized. It's important to note that this logarithmic operation requires non-negative data to prevent undefined values from polluting calculations. The graph displayed in the **Analysis** tab shows the normalized data, so it may have slightly higher y values than the data presented in **Plate Results** and **Graph Results**.

| Number | Element | Description |
| ------ | --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 1 | **Metrics Table -- Group toggle** | Click the header checkbox to toggle visibility on and off for all groups. Click a group checkbox to toggle visibility on or off for that specific group. Group visibility also controls what groups will be affected by bounding changes made with the **re-calculate metrics** button. Clicking the header of other metrics will sort the table and graph to that metric. |
| 2 | **Bound Slider** | Slider that controls the start and end times of the data fed to the model when **re-calculate metrics** is clicked. See [bounding-model](#bounding-model) for more details. |
| 3 | **Re-calculate Metrics** | Click update the start and end times of data fed to the models for every group currently visible to the red dotted vertical lines. |
| 4 | **Graph Type Select** | Choose between **growth**, which is the typical kinetic graph results view, to bar charts comparing each metric in the table on the right. See [metric comparison](#metric-comparison) for an example. |
| 5 | **Trend Lines** | Toggle on the model for each group as a dotted line. Will also display **lag time estimate** and **point of max specific growth** as a circle and diamond, respectively |
| 6 | **Tangent Lines** | Updates growth chart to logarithmic y-axis. Toggles on visibility of tangent lines at the point of max specific growth. The slope of the tangent line is equal to *๐๐๐๐ฅ*. |
| 7 | **Temperature** | Toggle on temperature data in the growth chart |
| 8 | **Group Bounds** | Toggle the group bounds used to calculate metrics for each individual group. Note that these will be the extents of the graph unless a change to the **Bound Slider** is changed and **Re-calculate Metrics** is clicked |
| 9 | **Export Graph** | Export the graph as a `.png` or `.svg` file for lab meetings or presentations. `.png` export size can be selected prior to export. `.svg` images are vector-based so they scale automatically. |
:::{tip} At least one group with wells assigned to it must be present in the plate layout for labrador to analyze growth data
:::
## Growth Model
The growth model used within Labrador is a modified Richards Curve with the following form:
{w=250px}
| Parameter | Description |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| A > 0 | The lower (left) asymptote. Minimum value of 0. This helps keep the maximum specific growth rate reasonable, as a negative A will produce a vertical asymptote in the logarithmic space. |
| K | The upper (right) asymptote. Carrying capacity. **Optical Densitymax** |
| r > 0 | The intrinsic growth rate. Minimum value of 0, meaning that decay data -- rather than growth data -- will not yield accurate metrics. |
| ๐พ | The inflection point where logarithmic growth ends. |
| t | The time elapsed |
| ๐ > 0 | Asymmetry parameter - describes the transition between growth phases. |
| f(t) | Optical Density |
From this equation, the lag time, doubling time, and maximum optical density can be derived, which are displayed in the **analysis** tab of kinetic results.
The **max specific growth rate** (*๐๐๐๐ฅ*) is calculated by finding the max derivative of the natural logarithm of the model equation. We use the model equation instead of the raw data to avoid noise. See [Logarithmic Visualization](#logarithmic-visualization) for how to visualize *๐๐๐๐ฅ*.
{w=230px}
**Doubling time** (*Td*) is derived from the specific max growth rate with the following equation, which is true under constant continuous growth rate *r*:
{w=100px}
The **lag time** is calculated by finding the intersection of left asymptote *A* (the initial population size) with the max specific growth rate tangent line in logarithmic coordinates. If *A* is negative, then the initial optical density is used instead.
**Area under the curve** is calculated with a trapezoid approximation of the integral.
## Logarithmic Visualization

Since *๐๐๐๐ฅ*, doubling time, and lag time are derived from the natural logarithm of the OD, it can be useful to visualize the data with **ln(OD)**. Toggling on the tangent line at *๐๐๐๐ฅ* will convert the graph to **ln(OD)**.
:::{note} Since a negative OD value will result in a logarithm of -infinity, we normalize the data to be above 0 and enforce the model to make the lower-asymptote > 0. If the logarithmic graph approaches is -infinity to the left, then the *๐๐๐๐ฅ* will be erroneously very large and the doubling time very low.
:::
## Bounding Model
In some circumstances, it may be useful to bound the kinetic model's start and end time to improve accuracy of metrics. For instance, if inoculation occurs mid-experiment, you may want to fit the kinetic model after inoculation has occurred. Or, you may want to filter out the death phase of bacteria to improve the *R2* of the fit. This can be accomplished within Labrador on a per-group basis.

Use the slider to edit the start and end time of data fed to the model to be fit. The left-most handle controls the start time while the right-most handle controls the end time. The dotted vertical red lines in the graph view display the pending start and end times. Upon clicking **re-calculate metrics** the start and end times for ALL visible groups will be updated to the pending start and end times. The red dotted bounds only mark pending changes to model bounds. To view the current values for each visible group, use the **group bounds** toggle. The start and end times for each group will display as solid vertical lines of the same color as the group, as seen in number 1 below:

## Extrapolation detection
In some cases where data is linear or the experiment is started near saturation, the model can be highly-extrapolated which means that the metrics should not necessarily be trusted. When extrapolation is detected, an asterisk will appear next to the **R2** value.

Extrapolation detection works by analyzing the curvy section of the model and comparing that to the curvy section of the measured data. If the width of the measured curvy section is less than half of the curvy section of the model overall, the data will be marked as extrapolated.

## Metric Comparison
