I apply a linear regression over a data set:
## Random set
set.seed(123)
i0=0
imax = 100
x = seq(0,imax,1)
y = c(i0)
for( i in 1:imax ){
i1 = rnorm( n = 1, mean = i0, sd = 1)
y = c( y, i1 )
i0 = i1
}
plot(x,y)
## Build a data frame out of it
d0 = data.frame( x, y )
## Apply a linear regression
f0 = lm( d0$y ~ d0$x )
## Plot the fitted function
abline(f0)
and now I want to use this fitted function to know the predicted value for
- Interpolated values (e.g. x=3.5)
- Extrapolated values (e.g. x=110)
I found only this answer through the web:
y2=predict(f0, data.frame(x=seq(0,100,1)))
But this is different from what I want. I could of course implement by hand these functions using their parameters, but I want to have it general.
Any hint welcome!