Is there an R package that easily identifies an observation that best "represents" the model?"

Say I have a dataset full of observations and I run a regression model. Is there a package that can help me identify the observation that best "fits" the model?

Hi, and welcome!

A reproducible example, called a reprex always helps clarify questions. I'll have to assume that you mean an ordinary least squares regression using lm(). A reprex would look like

fit <- lm(mpg ~ wt, data = mtcars)
abs_fit <- abs(fit$residuals)
sort(abs_fit)[1]
#> Merc 450SL 
#>  0.0502472

Created on 2020-01-15 by the reprex package (v0.3.0)

This interprets the best fit as meaning has the smallest absolute residual, meaning lies closest to the trend line..

3 Likes

Do you mean the observation with the smallest residual?

Yes. @technocrat's response was perfect. Thank you!

1 Like

Great. Please mark the solution for the benefit of those to follow. Do this even for your own solution, no false modesty. And, so far as I know,

a penny a point, ain't no one keeping score

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.