Exercise

Hot-deck tricks & tips I: imputing within domains

One trick that may help when hot-deck imputation breaks the relations between the variables is imputing within domains. What this means is that if the variable to be imputed is correlated with another, categorical variable, one can simply run hot-deck separately for each of its categories.

For instance, you might expect air temperature to depend on time, as we are seeing the average temperatures rising due to global warming. The time indicator you have available in the tao data is a categorical variable, year. Let's first check if the average air temperature is different in each of the two studied years and then run hot-deck within year domains. Finally, you will draw the margin plot again to assess the imputation performance.

Instructions

100 XP
  • Calculate mean air_temp for each year, calling the result average_air_temp while excluding NAs from the mean calculation.
  • Impute the missing values in air_temp in the tao data within year domains using hot-deck imputation and assign the result to tao_imp.
  • Create a margin plot of air_temp vs sea_surface_temp; remember to include air_temp_imp in the variables you pass to the plotting function.