ivanmp
ivanmp

Reputation: 529

Get the predicted value with Linear Regression

Say I have a have a plot with the following information:

scatterplot

Based on this R code:

concentration <- c(1,10,20,30,40,50)
signal <- c(4, 22, 44, 244, 643, 1102)
plot(concentration, signal)
res <- lm(signal ~ concentration)
abline(res)

How do I get the value of signal for concentration 45 in R, for example? I mean, how can I obtain the value that abline used to plot the line in this particular point?

I suppose I could get the β1 and β2 and do the math by myself, but I'm interested in understanding how this could be done automatically in R.

Upvotes: 0

Views: 177

Answers (1)

James
James

Reputation: 66864

You should use predict. The trick is that you have to put your predictors into a new data.frame with appropriate names so it knows what to predict on:

predict(res,data.frame(concentration=45))
       1 
779.5875 

Upvotes: 2

Related Questions