concept residual in category R

This is an excerpt from Manning's book Practical Data Science with R, Second Edition.
Figure 6.14 compares the actual data (points) to the model’s predictions (the line). The differences between the predictions of temperatureF and temp_pred are called the residuals or error of the model on the data. We will use the residuals to calculate some common performance metrics for scoring models.
Residuals: Min 1Q Median 3Q Max -1.5038 -0.1354 0.0187 0.1710 0.9741Recall that the residuals are the errors in prediction: log10(dtrain$PINCP) - predict (model,newdata=dtrain). In linear regression, the residuals are everything. Most of what you want to know about the quality of your model fit is in the residuals. You can calculate useful summaries of the residuals for both the training and test sets, as shown in the following listing.
Listing 7.6. Summarizing residuals
( resids_train <- summary(log10(dtrain$PINCP) - predict(model, newdata = dtrain)) ) ## Min. 1st Qu. Median Mean 3rd Qu. Max. ## -1.5038 -0.1354 0.0187 0.0000 0.1710 0.9741 ( resids_test <- summary(log10(dtest$PINCP) - predict(model, newdata = dtest)) ) ## Min. 1st Qu. Median Mean 3rd Qu. Max. ## -1.789150 -0.130733 0.027413 0.006359 0.175847 0.912646In linear regression, the coefficients are chosen to minimize the sum of squares of the residuals. This is why the method is also often called the least squares method. So for good models, you expect the residuals to be small.
In the residual summary, you’re given the Min. and Max., which are the smallest and largest residuals seen. You’re also given the quartiles of the residuals: 1st. Qu., or the value that upper bounds the first 25% of the data; the Median, or the value that upper bounds the first 50% of the data; and 3rd Qu., or the value that upper bounds the first 75% of the data (the Max is the 4th quartile: the value that upper bounds 100% of the data). The quartiles give you a rough idea of the data’s distribution.