compute_tangent | R Documentation |
modeler
objectComputes the slope and intercept of the tangent line(s) to a fitted curve at one or more specified x-values.
compute_tangent(object, x = NULL, id = NULL)
object |
A fitted object of class |
x |
A numeric vector of x-values at which to compute tangent lines. |
id |
Optional vector of |
A tibble with one row per tangent line and the following columns:
uid
: unique identifier of the group.
fn_name
: Name of the fitted function.
x
: x-value where the tangent line is evaluated.
y
: Fitted y-value at x.
slope
: First derivative (slope of tangent) at x.
intercept
: y-intercept of the tangent line.
library(flexFitR)
library(ggplot2)
data(dt_potato)
mod <- dt_potato |>
modeler(
x = DAP,
y = Canopy,
grp = Plot,
fn = "fn_logistic",
parameters = c(a = 4, t0 = 40, k = 100),
subset = 2
)
plot(mod)
tl <- compute_tangent(mod, x = c(48.35, 65))
print(tl)
plot(mod) +
geom_abline(
data = tl,
mapping = aes(slope = slope, intercept = intercept),
linetype = 2,
color = "blue"
) +
geom_point(
data = tl,
mapping = aes(x = x, y = y),
shape = 8,
color = "blue",
size = 2
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.