Skip to content
Prev 386998 / 398503 Next

How to predict/interpolate new Y given knwon Xs and Ys?

Hello,

You can predict y on x, not the other way around, like you are doing in 
the second call to predict.lm.

The 10 values you are getting are the predicted values on the original x 
values, just see that x=7.5 gives ypred=30, right in the middle of x=7 
and x=8 -> ypred=29 and ypred=31.

As for the inverse regression, how do you account for the errors? In 
linear regression the only rv is the errors vector, the inverse of

y = a + b*x + e

is not

x = (y - a)/b

though you can write a function that computes this value:

pred_x <- function(model, newdata){
   beta <- coef(model)
   y <- newdata[[1]]
   x <- (y - beta[1])/beta[2]
   unname(x)
}
pred_x(model, data.frame(y = 26))
#[1] 5.5


There is a CRAN package, investr that computes the standard errors:

investr::calibrate(model, y0 = 26)
#estimate    lower    upper
#     5.5      5.5      5.5


See the decumentation in [1]

[1] https://CRAN.R-project.org/package=investr


Hope this helps,

Rui Barradas

?s 09:11 de 26/01/21, Luigi Marongiu escreveu: