Author: Deoclecio Amorim & João Novoletti

# Introduction to seinfitR

#### Deoclecio Amorim & João Novoletti

## Installation

You can install the development version of seinfitR from GitHub with:

    # install.packages("pak")
    pak::pak("dslabcena/seinfitR")

Alternatively, if you’d like to install the stable version of seinfitR from CRAN, run:

    install.packages("seinfitR")

## Overview

The seinfitR package is designed for fitting the Seinhorst equation to experimental data describing the relationship between preplant nematode densities and plant growth. The package provides nonlinear least squares fitting and useful methods for model evaluation and visualization.

## Example Analysis

### Load Sample Data

We will use the glasshouse dataset included in the package:

    library(seinfitR)

    data(glasshouse, package = "seinfitR")

### Fit the Seinhorst Model

We fit the model using the seinfitR() function, specifying initial parameter values and controlling iteration limits:

    model <- seinfitR(
      p_i = "p_i",
      y = "y",
      data = glasshouse,
      start = list(m = 6, t = 6),
      control = seinfitR_control(maxiter = 20),
      z_fixed = TRUE
    )
    #> The Z_fixed parameter is set to TRUE: using the default value for z^t from Seinhorst (1986).
    #> Model fitting completed successfully.

### Model Result Details

The result of the `seinfitR()` function returns a list containing several important elements related to the fitted model:

    - fit: The fitted model object, which can be further analyzed or extracted.
    - summary_seinfitR: A summary of the fitted model, providing details about parameter estimates and statistical significance.
    - cov: The covariance matrix of the parameter estimates, if available.
    - data: The original dataset used for fitting the model.
    - x: The name of the predictor variable (e.g., preplant nematode density).
    - y: The name of the response variable (e.g., plant growth).
    - z_fixed: A boolean indicating whether the `z` parameter was fixed during model fitting.
    If `TRUE`, the function uses the default value for ( z^t ), as described in
    Seinhorst, J. W. (1986). Effects of nematode attack on the growth and yield of crop plants. In Cyst nematodes (pp. 191-209). Springer US.

### Model Summary

    summary(model)
    #> Seinhorst Model - Parameter Estimates
    #> -----------------------------------------------------
    #>         Estimate  Std. Error   t value     Pr(>|t|)
    #> m      0.5951683 0.008177824  72.77832 4.096851e-16
    #> t      1.6829177 0.116059892  14.50042 1.627030e-08
    #> y_max 10.3675895 0.053752628 192.87596 9.127161e-21
    #> -----------------------------------------------------
    #> R2 - R squared (Coefficient of Determination):  0.9949782
    #> Adjusted_R2 - Adjusted R squared:               0.9940652
    #> -----------------------------------------------------

### Extract Model Coefficients

    coef(model)
    #>          m          t      y_max
    #>  0.5951683  1.6829177 10.3675895

    coef <- coef(model)

    m <- coef[1]
    t <- coef[2]
    y_max <- coef[3]

    cat("m:", m)
    #> m: 0.5951683
    cat("t:", t)
    #> t: 1.682918
    cat("y_max", y_max)
    #> y_max 10.36759

### Visualizing the Model Fit

The fitted model can be visualized using built-in plotting functions:

    plot(model, main = "Seinhorst Model Fit for Glasshouse Data")

For further details, refer to the official GitHub repository.