LoslegenKostenlos loslegen

Last observation carried forward (LOCF)

Another important imputation method is Last observation carried forward, or LOCF. This method works by filling in missing values with the most recent non-NA value that came before it.

In this exercise, you will impute a time series of a student's monthly examination scores, called monthly_test_scores. This dataset, along with the ggplot2 and zoo packages, are available to you.

Diese Übung ist Teil des Kurses

Manipulating Time Series Data in R

Kurs anzeigen

Anleitung zur Übung

  • Use last observation carried forward to impute missing values in monthly_test_scores; save this as monthly_scores_locf.

  • Complete the first autoplot() to generate a plot of the original monthly_test_scores time series.

  • Autoplot monthly_scores_locf with the 'minimal' theme, and the y-axis label "Examination Score (LOCF)".

  • Compare the plot of monthly_scores_locf with the plot of monthly_test_scores by switching between the plots.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Impute using last observation carried forward
___ <- ___

# Create a plot of the original time series 
autoplot(___) + 
  theme_minimal() + 
  labs(y = "Examination Score")

# Autoplot with theme and axis title and compare to the above plot
autoplot(___) + 
  ___
Code bearbeiten und ausführen