Skip to main content

Section 2.5 Categorical vs Numerical Variables

What are categorical and numerical variables? In statistical analysis, we use these two types of variables to handle different kinds of data. Categorical variables deal with qualitative data, meaning they sort observations into specific groups or categories. Think of things like gender, race, marital status, education level, and car type. On the other hand, numerical variables handle quantitative data. These are numbers that show amounts or quantities, like age, height, income, or temperature. Examples of numerical variables include age, height, weight, income, and temperature.
Our summary statistics from the summary function suggest that some issues arise with the way our variables are coded. For instance, the RACE variable has been given summary statistics like “Min.”, “1st Qu.”, “Median”, “Mean”, “3rd Qu.”, “Max.”, and “NA’s”. This is incorrect because RACE is being treated as a numerical variable instead of a categorical one.
There is no average for the categorical variable of race. Calculating the mean of race categories (e.g., “WHITE”, “BLACK”, “OTHER”) would imply a numeric relationship between these categories. However, race categories are qualitative and do not have inherent numeric values. Treating them as numeric would lead to misinterpretation and potentially incorrect conclusions. On the other hand, calculating the average age, which is 48.19 years, makes perfect sense. However, it’s illogical to apply the mean to categorical variables like race. Race categories (e.g., White, Black, Asian) don’t have a numerical order or value that can be averaged as numerical values do.
We need to recode RACE and SEX, so that they are classified as categorical variables instead of numerical variables. Even POLHITOK and POLABUSE are categorical because the responses “yes” and “no” represent distinct categories rather than numerical values with inherent order or magnitude. While the coded values 1 and 2 for POLHITOK and POLABUSE may appear to be numerical, they are used here to represent categories rather than quantities. So, these variables also need to be transformed properly.