Learn R Programming

EmpiricalDynamics (version 0.1.2)

fit_specified_equation: Fit Specified Equation

Description

Fits a researcher-specified functional form, estimating only the parameters. Uses Levenberg-Marquardt algorithm for robustness.

Usage

fit_specified_equation(
  expression,
  data,
  response = NULL,
  derivative_col = NULL,
  start = NULL,
  method = c("LM", "nls", "optim"),
  weights = NULL,
  lower = -Inf,
  upper = Inf
)

Value

An object of class "symbolic_equation" containing the fitted model.

Arguments

expression

Character string specifying the equation (e.g., "a + b * Z").

data

Data frame with predictor variables.

response

Name of the response/target column.

derivative_col

Alias for response (for compatibility).

start

List of starting values for parameters (auto-estimated if NULL).

method

Optimization method: "LM" (Levenberg-Marquardt, recommended), "nls" (standard), or "optim" (general optimization).

weights

Optional weight vector.

lower

Lower bounds for parameters (for "optim" method).

upper

Upper bounds for parameters (for "optim" method).

Examples

Run this code
# \donttest{
# Toy example
data <- data.frame(Z = seq(1, 10, length.out = 20))
data$dZ <- 0.5 * data$Z * (1 - data$Z / 20) + rnorm(20, sd = 0.01)

# Fit logistic equation
eq <- fit_specified_equation(
  expression = "r * Z * (1 - Z/K)",
  data = data,
  response = "dZ",
  start = list(r = 0.5, K = 20)
)
print(eq)
# }

Run the code above in your browser using DataLab