마지막 관측값 전진 대치(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(___) +
___