Take the 2-minute tour ×

Say we have a linear model f1 that was fit to some x and y data points:

f1 <- lm(y ~ x,data=d)

How can I generate new y values at new x values (that are different from the old x values but are within the range of the old x values) using this f1 fit in R?

share|improve this question

migrated from stats.stackexchange.com Apr 8 '13 at 21:17


2 Answers 2

You can use predict for this:

x <- runif(20, 0, 100)
y <- 5*x + rnorm(20, 0, 10)
df <- data.frame(x, y)


x_new <- 1:100
pred <- predict(mod, newdata=data.frame(x = x_new))
points(x_new, pred)
share|improve this answer

Probably a better question for Stack Overflow, but look up predict.

share|improve this answer

Your Answer


