Skip to content

Handle Missing Data

Mastering Missing Data Handling

Mastering the handling of missing data is fundamental for any data analyst or scientist. Understanding the types of missing data, their implications, and employing appropriate strategies such as data deletion, imputation, and domain-specific approaches are essential skills. By effectively managing missing data, you can ensure the integrity and reliability of their analyses, leading to more accurate insights and decision-making. Leverage Infoveave powerful features, such as calculated columns, SQL, and Python, for recognizing gaps within datasets and understand strategies for effectively managing and addressing missing elements.

What is a Missing Data?

Missing data simply means that some information or values are not available in a dataset where they should be. This could happen for different reasons like errors, not getting responses in surveys, or even purposeful exclusion. It is important to recognize and deal with missing data properly because it can affect the accuracy and reliability of any analysis or conclusions drawn from the data. Missing data is categorized as below:  

(Image: https://help.infoveave.com/wp-content/uploads/2024/01/Missing-Data.png)

  • Missing Completely at Random
    • Description: In MCAR, the missingness of data is entirely random and unrelated to any other variables in the dataset.
    • Example: In a classroom, if students forget to fill in a survey question at random, regardless of their grades or behavior, it is MCAR.
  • Missing at Random
    • Description: In MAR, the probability of data being missing depends on observed variables but not on the missing data itself.
    • Example: In a survey about favorite foods, if missing responses for “favorite dessert” are related to age, but once age is known, there’s no pattern in missingness, it is MAR.
  • Missing Not at Random
    • Description: In MNAR, the missingness is related to the unobserved data itself, which makes it dependent on the missing values.
    • Example: In a salary survey, if people with higher incomes are less likely to disclose their salary, creating a pattern in missing data, it would be considered MNAR.

Key steps in identifying missing data include:

  • Detection: Utilizing data exploration tools to identify the presence and locations of missing values within the dataset.
  • Quantification: Calculating the percentage or count of missing values in each variable to gauge the extent of the missing data issue.
  • Patterns and Trends: Analyzing the patterns and trends of missing data across variables to identify any systematic occurrences.
  • Causes: Investigating the reasons behind missing values, distinguishing between missing completely at random (MCAR), missing at random (MAR), and missing not at random (MNAR) scenarios.
  • Impact Assessment: Evaluating the potential impact of missing data on the reliability and validity of the analysis, considering whether it introduces bias or affects the overall findings.

Strategies for Dealing with Missing Data

Handling missing data is a critical aspect of data analysis to ensure accurate and reliable results. Several strategies can be employed to address missing data effectively:

  • Data Deletion: If there is a missing value in a row, we just remove that entire row from our dataset.
    • Example: If we have a survey dataset and one respondent didn’t answer any questions, we remove that respondent’s entire entry.

Example Let us consider a dataset with information about students, including their grades in two subjects: Math and English. Some students have missing values for either Math or English grades.

Student_IDMath_GradeEnglish_Grade
18590
27582
392
488
57895
68891

In this example, student3 and student4 have missing values for Math and English grades, respectively. Procedure for Listwise Deletion:

  1. Identify rows with missing values, i.e., rows 3 and 4.
  2. Remove entire rows with missing values.
  3. The new dataset after listwise deletion:
Student_IDMath_GradeEnglish_Grade
18590
27582
57895
68891

Note: While this method ensures that only complete cases are considered, it comes at the cost of losing information.

Deletion using SQL:

The following SQL query demonstrates the process of deleting rows with missing values from a database table. Assuming you have a table named grades in a SQL database: SQL command:

DELETE FROM grades
WHERE Math_Grade IS NULL OR English_Grade IS NULL;

This SQL query removes rows with missing values in either the Math_Grade or English_Grade column.

Deletion using Python:

The provided Python code showcases the utilization of the dropna function in the Pandas library to eliminate rows containing missing values from a DataFrame.

Python Code:

import pandas as pd
# Create a DataFrame
data = {
'Student_ID': [1, 2, 3, 4, 5, 6],
'Math_Grade': [85, 75, 92, None, 78, 88],
'English_Grade': [90, 82, None, 88, 95, 91]
}
df = pd.DataFrame(data)
# Drop rows with missing values
df_cleaned = df.dropna(subset=['Math_Grade', 'English_Grade'])
  • Data Imputation: Instead of removing missing values, we fill them in with something else.
    • Example: If a person’s age is missing in a dataset, we might fill it in with the average age of all other people in the dataset.

Example Let us consider a dataset with information about students, including their grades in two subjects: Math and English. Some students have missing values for either Math or English grades.

Student_IDMath_GradeEnglish_Grade
18590
27582
392
488
57895
68891

In this example, student3 and student4 have missing values for Math and English grades, respectively. Procedure for Mean Imputation:

  1. Calculate the mean for both the “Math_Grade” and “English_Grade” columns.

    • Mean_Math = (85 + 75 + 92 + 78 + 88) / 5 = 83.6
    • Mean_English = (90 + 82 + 88 + 95 + 91) / 5 = 89.2
  2. Substitute the mean values into the missing positions.

Student_IDMath_GradeEnglish_Grade
18590
27582
39289.2
483.688
57895
68891
  • Multiple Imputation: Instead of guessing one value to replace a missing one, we guess several different values multiple times to account for uncertainty.
    • Example: If we are missing data on household income in a survey, we might impute it multiple times with slightly different estimates.
  • Domain-Specific Imputation: We use our knowledge about the subject matter to make educated guesses about missing data.
    • Example: If we are analyzing a dataset on medical records and some patients’ weights are missing, we might impute those values based on typical weights for people of similar age, gender, and height.
  • Predictive Modeling: We use algorithms to predict what the missing values might be based on other information we have.
    • Example: If we are missing data on house prices in a real estate dataset, we might use a machine learning model that takes into account features like location, size, and amenities to predict the missing prices.
  • Improved Data Collection Practices: We focus on collecting better quality data in the first place to minimize missing values.
    • Example: If we are conducting a survey, we might offer to encourage people to respond fully and accurately.
  • Stratified Imputation: We impute missing values separately within different groups or categories to ensure that our estimates are more accurate.
    • Example: If we are analyzing a dataset on student performance and some students test scores are missing, we might impute those scores separately for different grade levels.

Conclusion

The chapter covers on the essential skills to manage missing data effectively, recognizing its impact and employing various techniques like data deletion, imputation, and advanced methods such as multiple imputation and predictive modeling. By recognizing missing data patterns and employing suitable strategies, you can navigate data challenges adeptly, making informed decisions and drawing reliable insights from their datasets.