# 시계열 분석 — 공식 stl() 예제의 월별 기온 분해
# 적용 범위: stl() 공식 예제의 nottem 주기 고정 분해를 실행했습니다. periodic을 완전한 문자열로 쓰고 출력 검증과 한국어 패널 이름을 추가했습니다.
# 출처: https://stat.ethz.ch/R-manual/R-patched/library/stats/html/stl.html
# 출처: https://stat.ethz.ch/R-manual/R-patched/library/datasets/html/nottem.html
# 실행 확인 환경: R version 4.6.2 (2026-10-29)
# 아래 코드를 실행하면 출력과 그림을 확인할 수 있습니다.

# 재현 설정: 같은 난수 방식과 출력 자릿수를 사용합니다.
RNGkind("Mersenne-Twister", "Inversion", "Rejection")
set.seed(2026)
options(width = 90, digits = 7, scipen = 7)

# stl() 공식 예제의 주기 고정 분해입니다.
decomposed <- stl(nottem, s.window = "periodic")
c(관측수 = length(nottem), 연간빈도 = frequency(nottem))
round(head(decomposed$time.series, 3), 3)
round(max(abs(nottem - rowSums(decomposed$time.series))), 10)
plot(decomposed, labels = c("관측", "계절", "추세", "나머지"),
     main = "노팅엄 월평균 기온 분해(화씨)",
     set.pars = list(mar = c(0, 8, 0, 6), oma = c(6, 0, 4, 0),
                     tck = -0.01, mfrow = c(4, 1)))
