inverse_predict.modeler {flexFitR}R Documentation

Inverse prediction from a modeler object

Description

Computes the x-value at which a fitted model reaches a user-specified response value (y-value).

Usage

## S3 method for class 'modeler'
inverse_predict(
  object,
  y,
  id = NULL,
  interval = NULL,
  tol = 1e-06,
  resolution = 1000,
  ...
)

Arguments

object

A fitted object of class modeler.

y

A numeric scalar giving the target y-value for which to compute the corresponding x.

id

Optional vector of uids for which to perform inverse prediction. If NULL, all groups are used.

interval

Optional numeric vector of length 2 specifying the interval in which to search for the root. If NULL, the interval is inferred from the range of the observed x-values.

tol

Numerical tolerance passed to uniroot for root-finding accuracy.

resolution

Integer. Number of grid points used to scan the interval.

...

Additional parameters for future functionality.

Details

The function uses numeric root-finding to solve f(t, ...params) = y. If no root is found in the interval, NA is returned.

Value

A tibble with one row per group, containing:

See Also

predict.modeler, uniroot

Examples

library(flexFitR)
data(dt_potato)
mod_1 <- dt_potato |>
  modeler(
    x = DAP,
    y = Canopy,
    grp = Plot,
    fn = "fn_lin_plat",
    parameters = c(t1 = 45, t2 = 80, k = 0.9),
    subset = c(15, 2, 45)
  )
print(mod_1)
inverse_predict(mod_1, y = 50)
inverse_predict(mod_1, y = 75, interval = c(20, 80))

[Package flexFitR version 1.2.0 Index]