直前値の保持(LOCF)
もう一つ重要な補完手法が「Last observation carried forward(LOCF)」です。この方法は、欠損値をその直前に現れた NA ではない最新の値で埋めることで機能します。
この演習では、学生の月次試験スコアの時系列 monthly_test_scores を補完します。データセットと、ggplot2 と zoo パッケージはあらかじめ利用可能です。
この演習はコースの一部です
Rで学ぶ時系列データ操作
演習の手順
last observation carried forward を用いて
monthly_test_scoresの欠損値を補完し、monthly_scores_locfとして保存します。最初の
autoplot()を完成させ、元のmonthly_test_scoresの時系列プロットを作成します。monthly_scores_locfを 'minimal' テーマで自動プロットし、y 軸ラベルを"Examination Score (LOCF)"にします。プロット間を切り替えて、
monthly_scores_locfのプロットとmonthly_test_scoresのプロットを比較します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# 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(___) +
___