0

I want to create a column of predicted values from a multiple regression using the lm function and the predict function without the lm function deleting rows where data to construct the multiple regression using the lm function is not present. Such data would be coded as NA in the dataset. I can't get it to work right now in R.

I can get this to work in SPSS because the predicted values that do not have full data comes out as #NULL! in a given cell.

Is it possible to do this in R? If so, please provide some guidance.

Thanks!

Mel
  • 510
  • 3
  • 10
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Have you tried the `predict()` function? What exactly did you try and how did it not work? – MrFlick Feb 12 '20 at 20:10

1 Answers1

1

When you call the lm() function set the option na.action to na.exclude.

mtcars <- mtcars

# create some NA values
mtcars[8, "hp"] = NA
mtcars[12, "hp"] = NA

mod <- lm(mpg ~ hp, data = mtcars, na.action = na.exclude) 
predict(mod)