Learn R Programming

flexFitR (version 1.2.2)

inverse_predict.modeler: 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 modeler
inverse_predict(
  object,
  y,
  id = NULL,
  interval = NULL,
  tol = 1e-06,
  resolution = 1000,
  ...
)

Value

A tibble with one row per group, containing:

  • uid – unique identifier of the group,

  • fn_name – the name of the fitted function,

  • lower and upper – the search interval used,

  • y – the predicted y-value (from the function at the root),

  • x – the x-value at which the function reaches y.

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.

See Also

predict.modeler, uniroot

Examples

Run this code
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))

Run the code above in your browser using DataLab