从样条函数中的给定x
中找到y
的正确方法是什么?
library(cobs)
library(tidyverse)
# data
dat <- tibble(
x = c(seq(80, 360, 40),373.3),
y = c(1.07, .85, .84, .97, 1.11, 2.02, 4.01, 7.99, 10.4)
)
# interpolation
dat_interpolated <- approx(x = dat$x, y = dat$y, xout = seq(min(dat$x), max(dat$x), 1)) %>%
as.tibble()
# spline
myspline <- cobs(x = dat_interpolated$x, y = dat_interpolated$y)
# data for plotting
dat2 <- predict(myspline) %>%
as.tibble()
dat %>%
ggplot(aes(x, y))+
geom_point(shape = 21,
size = 4,
fill = "white")+
geom_line(data = dat2, aes(z, fit), size = 1, color = "red")+
theme_bw()
情节:
预期结果:
我的目标是在以下情况下正确找到x
y == 2
y == 3
y == 4