Home > Enterprise >  How to simply extract specific values of regression curve?
How to simply extract specific values of regression curve?

Time:10-26

I would like to extract several predicted y-values for the x-values given from this graph :

enter image description here

I know that it is possible to get the x and y coordinates of the curve by using the following function :

coordinate <- ggplot_build(curve)$data[[2]][,c("x","y")]
head(coordinate,n = 6L)

#          x         y
1 0.1810660 32845.225
2 0.4810660 27635.136
3 0.7553301 23904.792
4 1.3295942 18316.923
5 1.8288582 15092.595
6 5.0312446  8018.707

Is there a function that allows you to directly obtain the predicted value of y for a given x value that does not appear in coordinate such as for example 3.5?

CodePudding user response:

As Gregor mentions, you should fit a model aside of the plot. Best you can do to "simply" obtain a value otherwise is an interpolating spline

sfun = splinefun(coordinate)

sfun(3.5)
  • Related