concept income in category R

This is an excerpt from Manning's book Practical Data Science with R, Second Edition.
As much as possible, try to use information that can be directly measured, rather than information that is inferred from another measurement. For example, you might be tempted to use income as a variable, reasoning that a lower income implies more difficulty paying off a loan. The ability to pay off a loan is more directly measured by considering the size of the loan payments relative to the borrower’s disposable income. This information is more useful than income alone; you have it in your data as the variable Installment_rate_in_percentage_of_disposable_income.
Suppose your goal is to build a model to predict which of your customers don’t have health insurance. You’ve collected a dataset of customers whose health insurance status you know. You’ve also identified some customer properties that you believe help predict the probability of insurance coverage: age, employment status, income, information about residence and vehicles, and so on.
Is there a relationship between the two inputs age and income in my data?
You’d expect there to be a relationship between age and health insurance, and also a relationship between income and health insurance. But what is the relationship between age and income? If they track each other perfectly, then you might not want to use both variables in a model for health insurance. The appropriate summary statistic is the correlation, which we compute on a safe subset of our data.
Listing 3.12. Examining the correlation between age and income
customer_data2 <- subset(customer_data, 0 < age & age < 100 & 0 < income & income < 200000) #1 cor(customer_data2$age, customer_data2$income) #2 ## [1] 0.005766697 #3The correlation is positive, as you might expect, but nearly zero, meaning there is apparently not much relation between age and income. A visualization gives you more insight into what’s going on than a single number can. Let’s try a scatter plot first (figure 3.12). Because our dataset has over 64,000 rows, which is too large for a legible scatterplot, we will sample the dataset down before plotting. You plot figure 3.12 with geom_point, as shown in listig 3.13.
Listing 3.13. Creating a scatterplot of age and income
set.seed(245566) #1 customer_data_samp <- dplyr::sample_frac(customer_data2, size=0.1, replace=FALSE) #2 ggplot(customer_data_samp, aes(x=age, y=income)) + #3 geom_point() + ggtitle("Income as a function of age")The relationship between age and income isn’t easy to see. You can try to make the relationship clearer by also plotting a smoothing curve through the data, as shown in figure 3.13.
The smoothing curve makes it easier to see that in this population, income tends to increase with age from a person’s twenties until their mid-thirties, after which income increases at a slower, almost flat, rate until about a person’s mid-fifties. Past the mid-fifties, income tends to decrease with age.