Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

locate missingness in fitted model in R

Tags:

r

na

Consider fitting a coxph model with, say, 100 data points. Only 95 are included in the analysis, while 5 are excluded due to being NA (i.e. missingness). I extract the residuals on the fitted data so I have a residual vector with 95 observations. I would like to include the residuals back into the original data frame, but I can't do this since the lengths are different.

How do I identify which observations from the original data frame were not included in the model, so I can exclude/delete them to make the two lengths the same?

(The original data is much larger so it's hard to locate where data are missing...)

like image 695
user2543095 Avatar asked Dec 02 '25 09:12

user2543095


1 Answers

Re-fit your model, setting the na.action argument to na.exclude. This pads the residuals and fitted values that are part of the fitted object with NAs. If your original model is zn50:

zn50_na <- update(zn50, na.action=na.exclude)

This should give you residuals(zn50_na) and fitted(zn50_na) of the appropriate length. See ?na.omit for more info.

like image 81
Hong Ooi Avatar answered Dec 03 '25 23:12

Hong Ooi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!