How to apply the results of linear regression on a training set of data to a testing set of data?

3.6k Views Asked by At

I have two non-empty dataframes: training and testing. Each of these dataframes has two columns: Y and X, in this order. I have applied linear regression analysis to training as follows:

m <- lm(Y ~ X, data = training)

I would like to apply the coefficients resulting from this fitting to the data in testing to obtain the same types of information available in the object m for purposes of further analysis and data visualization. How can I do this?

1

There are 1 best solutions below

0
On BEST ANSWER

See the predict.lm function:

Y_pred = predict(m, newdata = testing)