equation.nls: Get a LaTeX equation from an nls or the summary of a nls...

View source: R/tabularise.nls.R

equation.nlsR Documentation

Get a LaTeX equation from an nls or the summary of a nls models

Description

Create the model equation of several self-starting nonlinear models available in the stats package.

Usage

## S3 method for class 'nls'
equation(
  object,
  ital_vars = FALSE,
  use_coefs = FALSE,
  coef_digits = 2L,
  fix_signs = TRUE,
  var_names = NULL,
  op_latex = c("\\cdot", "\\times"),
  ...
)

## S3 method for class 'summary.nls'
equation(
  object,
  ital_vars = FALSE,
  use_coefs = FALSE,
  coef_digits = 2L,
  fix_signs = TRUE,
  var_names = NULL,
  op_latex = c("\\cdot", "\\times"),
  ...
)

Arguments

object

An nls or summary.nls object.

ital_vars

Logical, defaults to FALSE. Should the variable names not be wrapped in the ⁠\operatorname⁠ command?

use_coefs

Logical, defaults to FALSE. Should the actual model estimates be included in the equation instead of math symbols? If TRUE, ⁠var_names=⁠ is ignored.

coef_digits

Integer, defaults to 2. The number of decimal places to round to when displaying model estimates with use_coefs = TRUE.

fix_signs

Logical, defaults to TRUE. If disabled, coefficient estimates that are negative are preceded with a + (e.g. 5(x) + -3(z)). If enabled, the ⁠+ -⁠ is replaced with a - (e.g. 5(x) - 3(z)).

var_names

A named character vector as c(old_var_name = "new name")

op_latex

The LaTeX product operator character to use in fancy scientific notation, either ⁠\\cdot⁠ (by default), or ⁠\\times⁠.

...

Additional arguments (not used yet).

Value

A character string with a LaTeX equation.

Examples

equation <- tabularise::equation
chick1 <- ChickWeight[ChickWeight$Chick == 1, ]
chick1_nls <- nls(data = chick1, weight ~ SSlogis(Time, Asym, xmid, scal))
summary(chick1_nls)

equation(chick1_nls)
equation(summary(chick1_nls))

chick1_nls2 <- nls(data = chick1,
  weight ~ SSlogis(Time, Asym = A, xmid = x, scal = scale))
summary(chick1_nls2)

equation(chick1_nls2)
equation(summary(chick1_nls2))

equation(summary(chick1_nls2), var_names = c(
  weight = "Body weight [gm]",
  Time = "Number of days"))

SciViews/modelit documentation built on Nov. 24, 2024, 10:23 a.m.