Libraries
library(fpp3)
library(GGally)
library(dplyr)
library(tidyr)
library(ggplot2)
theme_set(theme_minimal(base_size = 12))
employment_summary <- us_employment |>
filter(year(Month) >= 2000) |>
as_tibble() |>
group_by(Series_ID, Title) |>
summarise(
mean_Employed = mean(Employed, na.rm = TRUE),
sd_Employed = sd(Employed, na.rm = TRUE),
min_Employed = min(Employed, na.rm = TRUE),
max_Employed = max(Employed, na.rm = TRUE),
.groups = "drop"
) |>
arrange(desc(mean_Employed))
nrow(employment_summary)
## [1] 148
leisure_employment <- us_employment %>%
filter(year(Month) >= 2000, Title == "Leisure and Hospitality") %>%
select(-Series_ID)
leisure_employment
## # A tsibble: 237 x 3 [1M]
## Month Title Employed
## <mth> <chr> <dbl>
## 1 2000 Jan Leisure and Hospitality 11056
## 2 2000 Feb Leisure and Hospitality 11180
## 3 2000 Mar Leisure and Hospitality 11435
## 4 2000 Apr Leisure and Hospitality 11740
## 5 2000 May Leisure and Hospitality 12060
## 6 2000 Jun Leisure and Hospitality 12489
## 7 2000 Jul Leisure and Hospitality 12535
## 8 2000 Aug Leisure and Hospitality 12528
## 9 2000 Sep Leisure and Hospitality 12170
## 10 2000 Oct Leisure and Hospitality 11810
## # ℹ 227 more rows
leisure_employment %>%
autoplot(Employed, linewidth = 0.8) +
labs(title = "U.S. Retail Trade employment",
subtitle = "Monthly observations from 1990 onward",
x = NULL, y = "Persons employed (thousands)")
dcmp_leisure <- leisure_employment |>
model(stl = STL(Employed))
leisure_components <- components(dcmp_leisure)
leisure_components |>
autoplot() +
labs(title = "STL decomposition of U.S. Leisure and Hospitality employment")
leisure_components |>
as_tibble() |>
mutate(Year = year(Month)) |>
group_by(Year) |>
summarise(Trend_mean = mean(trend),
Seasonal_amplit = max(season_year) - min(season_year),
Remainder_SD = sd(remainder)) |>
knitr::kable(digits = 1)
| Year | Trend_mean | Seasonal_amplit | Remainder_SD |
|---|---|---|---|
| 2000 | 11857.7 | 1255.3 | 44.0 |
| 2001 | 12018.3 | 1254.5 | 49.0 |
| 2002 | 12004.1 | 1253.5 | 53.2 |
| 2003 | 12183.8 | 1247.3 | 46.3 |
| 2004 | 12492.4 | 1241.2 | 22.5 |
| 2005 | 12812.1 | 1247.7 | 33.2 |
| 2006 | 13109.7 | 1256.3 | 21.6 |
| 2007 | 13408.6 | 1279.4 | 24.7 |
| 2008 | 13408.9 | 1301.9 | 16.3 |
| 2009 | 13097.6 | 1316.0 | 28.0 |
| 2010 | 13067.6 | 1328.7 | 29.7 |
| 2011 | 13363.5 | 1344.0 | 20.7 |
| 2012 | 13772.1 | 1359.3 | 30.8 |
| 2013 | 14247.8 | 1379.5 | 10.3 |
| 2014 | 14696.6 | 1401.6 | 16.2 |
| 2015 | 15163.1 | 1424.4 | 21.9 |
| 2016 | 15651.4 | 1446.6 | 16.1 |
| 2017 | 16041.3 | 1453.3 | 39.8 |
| 2018 | 16362.1 | 1459.2 | 37.6 |
| 2019 | 16670.2 | 1463.9 | 32.3 |
leisure_acf <- leisure_employment |> ACF(Employed, lag_max = 36)
leisure_acf |>
autoplot() +
labs(title = "ACF of U.S. Leisure and Hospitality employment",
subtitle = "Monthly series - autocorrelation up to 36 lags")
leisure_acf |> filter(lag %in% c(1, 6, 12, 18, 24, 36))
## # A tsibble: 0 x 2 [?]
## # ℹ 2 variables: lag <cf_lag>, acf <dbl>
Trend: The time plot shows a clear upward trend. The STL trend rises from about 11 to 16 million (≈ +40%), with a decline between 2008 and 2010 (Great Recession).
Seasonality: The time plot shows a repeated yearly wave, and the STL seasonal component peaks in July and reaches its minimum in January (summer tourism).
Level changes: No sudden jumps or drops in the time plot.
Variance: In the STL seasonal component, the waves grow only slightly over time, so there is only mild heteroskedasticity.
ACF: The ACF decays slowly (trend) and shows peaks at lags 12, 24 and 36 (seasonality). The series is not white noise.
leisure_rds_file <- "us_leisure_hospitality_employment_tsibble.rds"
saveRDS(leisure_employment, leisure_rds_file)
head(PBS)
## # A tsibble: 6 x 9 [1M]
## # Key: Concession, Type, ATC1, ATC2 [1]
## Month Concession Type ATC1 ATC1_desc ATC2 ATC2_desc Scripts Cost
## <mth> <chr> <chr> <chr> <chr> <chr> <chr> <dbl> <dbl>
## 1 1991 Jul Concessional Co-paymen… A Alimenta… A01 STOMATOL… 18228 67877
## 2 1991 Aug Concessional Co-paymen… A Alimenta… A01 STOMATOL… 15327 57011
## 3 1991 Sep Concessional Co-paymen… A Alimenta… A01 STOMATOL… 14775 55020
## 4 1991 Oct Concessional Co-paymen… A Alimenta… A01 STOMATOL… 15380 57222
## 5 1991 Nov Concessional Co-paymen… A Alimenta… A01 STOMATOL… 14371 52120
## 6 1991 Dec Concessional Co-paymen… A Alimenta… A01 STOMATOL… 15028 54299
class(PBS)
## [1] "tbl_ts" "tbl_df" "tbl" "data.frame"
index_var(PBS)
## [1] "Month"
key_vars(PBS)
## [1] "Concession" "Type" "ATC1" "ATC2"
interval(PBS)
## <interval[1]>
## [1] 1M
is_regular(PBS)
## [1] TRUE
n_keys(PBS)
## [1] 336
has_gaps(PBS)
## # A tibble: 336 × 5
## Concession Type ATC1 ATC2 .gaps
## <chr> <chr> <chr> <chr> <lgl>
## 1 Concessional Co-payments A A01 FALSE
## 2 Concessional Co-payments A A02 FALSE
## 3 Concessional Co-payments A A03 FALSE
## 4 Concessional Co-payments A A04 FALSE
## 5 Concessional Co-payments A A05 FALSE
## 6 Concessional Co-payments A A06 FALSE
## 7 Concessional Co-payments A A07 FALSE
## 8 Concessional Co-payments A A09 FALSE
## 9 Concessional Co-payments A A10 FALSE
## 10 Concessional Co-payments A A11 FALSE
## # ℹ 326 more rows
range(PBS$Month)
## <yearmonth[2]>
## [1] "1991 Jul" "2008 Jun"
pbs_gaps <- has_gaps(PBS)
table(pbs_gaps$.gaps)
##
## FALSE
## 336
pbs_lengths <- PBS |> as_tibble() |> count(Concession, Type, ATC1, ATC2)
pbs_categories <- PBS %>% distinct(ATC2, ATC2_desc) %>%
drop_na(ATC2_desc) %>%
arrange(ATC2)
print(pbs_categories, n = Inf)
## # A tibble: 84 × 2
## ATC2 ATC2_desc
## <chr> <chr>
## 1 A01 STOMATOLOGICAL PREPARATIONS
## 2 A02 DRUGS FOR ACID RELATED DISORDERS
## 3 A03 DRUGS FOR FUNCTIONAL GASTROINTESTINAL DISORDERS
## 4 A04 ANTIEMETICS AND ANTINAUSEANTS
## 5 A05 BILE AND LIVER THERAPY
## 6 A06 LAXATIVES
## 7 A07 ANTIDIARR ,INTEST ANTIINFL /ANTIINFECT AGENTS
## 8 A09 DIGESTIVES, INCL ENZYMES
## 9 A10 ANTIDIABETIC THERAPY
## 10 A11 VITAMINS
## 11 A12 MINERAL SUPPLEMENTS
## 12 A14 ANABOLIC AGENTS FOR SYSTEMIC USE
## 13 A15 APPETITE STIMULANTS
## 14 B01 ANTITHROMBOTIC AGENTS
## 15 B02 ANTIHAEMORRHAGICS
## 16 B03 ANTIANAEMIC PREPARATIONS
## 17 B05 BLOOD SUBSTITUTES AND PERFUSION SOLUTIONS
## 18 C01 CARDIAC THERAPY
## 19 C02 ANTIHYPERTENSIVES
## 20 C03 DIURETICS
## 21 C04 PERIPHERAL VASODILATORS
## 22 C05 VASOPROTECTIVES
## 23 C07 BETA BLOCKING AGENTS
## 24 C08 CALCIUM CHANNEL BLOCKERS
## 25 C09 AGENTS ACTING ON RENIN-ANGIOTENSIN SYSTEM
## 26 C10 SERUMLIPIDREDUCING AGENTS
## 27 D D
## 28 D01 ANTIFUNGALS FOR DERMATOLOGICAL USE
## 29 D02 EMOLLIENTS AND PROTECTIVES
## 30 D04 ANTIPRURITICS,INCL ANTIHIST,ANESTHET,ETC
## 31 D05 ANTIPSORIATICS
## 32 D06 ANTIBIOTICS AND CHEMOTHER FOR DERMATOLOGICAL USE
## 33 D07 CORTICOSTEROIDS, DERMATOLOGICAL PREPARATIONS
## 34 D08 ANTISEPTICS AND DISINFECTANTS
## 35 D10 ANTI-ACNE PREPARATIONS
## 36 D11 OTHER DERMATOLOGICAL PREPARATIONS
## 37 G01 GYNAECOLOGICAL ANTIINFECTIVES AND ANTISEPTICS
## 38 G02 OTHER GYNAECOLOGICALS
## 39 G03 SEX HORMONES AND MODULATORS OF THE GENITAL SYSTEM
## 40 G04 UROLOGICALS
## 41 H01 PITUITARY, HYPOTHALAMIC HORMONES AND ANALOGUES
## 42 H02 CORTICOSTEROIDS FOR SYSTEMIC USE
## 43 H03 THYROID THERAPY
## 44 H04 PANCREATIC HORMONES
## 45 H05 CALCIUM HOMEOSTASIS
## 46 J01 ANTIBACTERIALS FOR SYSTEMIC USE
## 47 J02 ANTIMYCOTICS FOR SYSTEMIC USE
## 48 J04 ANTIMYCOBACTERIALS
## 49 J05 ANTIVIRALS FOR SYSTEMIC USE
## 50 J06 IMMUNE SERA AND IMMUNOGLOBULINS
## 51 J07 VACCINES
## 52 L01 ANTINEOPLASTIC AGENTS
## 53 L02 ENDOCRINE THERAPY
## 54 L03 IMMUNOSTIMULANTS
## 55 L04 IMMUNOSUPPRESSIVE AGENTS
## 56 M01 ANTIINFLAMMATORY AND ANTIRHEUMATIC PRODUCTS
## 57 M02 TOPICAL PRODUCTS FOR JOINT AND MUSCULAR PAIN
## 58 M03 MUSCLE RELAXANTS
## 59 M04 ANTIGOUT PREPARATIONS
## 60 M05 DRUGS FOR TREATMENT OF BONE DISEASES
## 61 N02 ANALGESICS
## 62 N03 ANTIEPILEPTICS
## 63 N04 ANTI-PARKINSON DRUGS
## 64 N05 PSYCHOLEPTICS
## 65 N06 PSYCHOANALEPTICS
## 66 N07 OTHER NERVOUS SYSTEM DRUGS
## 67 P01 ANTIPROTOZOALS
## 68 P02 ANTHELMINTICS
## 69 P03 ECTOPARASITICIDES, INCL SCABICIDES, INSECTICIDES AND REPELLANTS
## 70 R R
## 71 R01 NASAL PREPARATIONS
## 72 R03 DRUGS FOR OBSTRUCTIVE AIRWAY DISEASES
## 73 R05 COUGH AND COLD PREPARATIONS
## 74 R06 ANTIHISTAMINES FOR SYSTEMIC USE
## 75 S S
## 76 S01 OPHTHALMOLOGICALS
## 77 S02 OTOLOGICALS
## 78 S03 OPHTHALMOLOGICAL AND OTOLOGICAL PREPARATIONS
## 79 V01 ALLERGENS
## 80 V03 ALL OTHER THERAPEUTIC PRODUCTS
## 81 V04 DIAGNOSTIC AGENTS
## 82 V06 GENERAL NUTRIENTS
## 83 V07 ALL OTHER NON-THERAPEUTIC PRODUCTS
## 84 Z Z
Each row is one drug category: the first column is the code
(ATC2) and the second is its name (ATC2_desc).
The original output has 107 rows, because 23 codes appear twice (once
with a description and once with NA). After removing the missing
descriptions with drop_na(), the table has 84 rows, one per
drug category.
The code H02 means CORTICOSTEROIDS FOR SYSTEMIC USE. It belongs to the bigger group H (systemic hormonal preparations).
h02_filtered <- PBS %>%
filter(ATC2 == "H02") %>%
select(Month, Concession, Type, Cost)
h02 <- h02_filtered |> summarise(Cost = sum(Cost) / 1e6)
h02
## # A tsibble: 204 x 2 [1M]
## Month Cost
## <mth> <dbl>
## 1 1991 Jul 0.430
## 2 1991 Aug 0.401
## 3 1991 Sep 0.432
## 4 1991 Oct 0.493
## 5 1991 Nov 0.502
## 6 1991 Dec 0.603
## 7 1992 Jan 0.660
## 8 1992 Feb 0.336
## 9 1992 Mar 0.351
## 10 1992 Apr 0.380
## # ℹ 194 more rows
h02 %>%
autoplot()
## Plot variable not specified, automatically selected `.vars = Cost`
h02_components <- h02 %>%
model(stl = STL(Cost)) %>%
components()
h02_components %>%
autoplot()
h02_acf <- h02 |> ACF(Cost, lag_max = 36)
h02_acf |>
autoplot()
h02 %>%
as_tibble() %>%
mutate(Year = year(Month)) %>%
group_by(Year) %>%
summarise(Mean = mean(Cost), SD = sd(Cost), Range = max(Cost) - min(Cost))
## # A tibble: 18 × 4
## Year Mean SD Range
## <dbl> <dbl> <dbl> <dbl>
## 1 1991 0.477 0.0731 0.202
## 2 1992 0.494 0.137 0.435
## 3 1993 0.570 0.171 0.576
## 4 1994 0.620 0.133 0.382
## 5 1995 0.680 0.143 0.451
## 6 1996 0.712 0.145 0.442
## 7 1997 0.679 0.161 0.531
## 8 1998 0.686 0.150 0.487
## 9 1999 0.782 0.165 0.538
## 10 2000 0.802 0.156 0.440
## 11 2001 0.838 0.189 0.599
## 12 2002 0.880 0.190 0.570
## 13 2003 0.905 0.216 0.645
## 14 2004 0.977 0.208 0.589
## 15 2005 0.912 0.217 0.573
## 16 2006 0.925 0.217 0.644
## 17 2007 0.939 0.239 0.662
## 18 2008 0.840 0.197 0.571
Trend: The time plot shows a clear upward trend. The STL trend rises from about 0.4 to 1.0 million AUD(≈ +150%), with a decline between 1997 and 1998, and a little bit in 2004 and 2006.
Seasonality: The time plot shows a repeated yearly wave, and the STL seasonal component peaks in December-January and reaches its minimum in February.
Level changes: No sudden jumps or drops in the time plot.
Variance: In the STL seasonal component, the waves become larger over time (amplitude from about 0.42 to 0.55), and the remainder is also larger at the end. The seasonal fluctuations grow with the level which results in heteroskedasticity.
ACF: The ACF shows strong peaks at lags 12, 24 and 36 (≈ 0.84, 0.71, 0.61) and values close to zero around lags 6, 18 and 30 which means strong annual seasonality. The slow decline of the seasonal peaks reflects the trend. The series is not white noise.
h02_rds_file <- "h02_corticosteroid_drugs_tsibble.rds"
saveRDS(h02, h02_rds_file)
The us_change tsibble contains quarterly changes in Consumption, Income, Production, Savings and Unemployment. We explore their movements through time and pairwise associations.
head(us_change)
## # A tsibble: 6 x 6 [1Q]
## Quarter Consumption Income Production Savings Unemployment
## <qtr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1970 Q1 0.619 1.04 -2.45 5.30 0.9
## 2 1970 Q2 0.452 1.23 -0.551 7.79 0.5
## 3 1970 Q3 0.873 1.59 -0.359 7.40 0.5
## 4 1970 Q4 -0.272 -0.240 -2.19 1.17 0.700
## 5 1971 Q1 1.90 1.98 1.91 3.54 -0.1000
## 6 1971 Q2 0.915 1.45 0.902 5.87 -0.1000
# Select the five macroeconomic variables
us_macro <- us_change |>
as_tibble() |>
select(Consumption, Income, Production,
Savings, Unemployment)
# Create correlation and scatterplot matrix
ggpairs(us_macro)
us_change |>
pivot_longer(
cols = c(Consumption, Income, Production,
Savings, Unemployment),
names_to = "Variable",
values_to = "Change"
) |>
ggplot(aes(x = Quarter, y = Change)) +
geom_line(color = "red") +
facet_wrap(~ Variable, scales = "free_y") +
labs(
title = "U.S. Macroeconomic Changes",
x = "Quarter",
y = "Change"
) +
theme_minimal()
GGally::ggpairs(us_macro)
round(cor(us_macro, use = "pairwise.complete.obs"), 3)
## Consumption Income Production Savings Unemployment
## Consumption 1.000 0.384 0.529 -0.257 -0.527
## Income 0.384 1.000 0.269 0.720 -0.224
## Production 0.529 0.269 1.000 -0.059 -0.768
## Savings -0.257 0.720 -0.059 1.000 0.106
## Unemployment -0.527 -0.224 -0.768 0.106 1.000
The strongest positive association is between Income and Savings (r ≈ 0.720), consistent with households tending to save more when income increases. The strongest negative association is between Production and Unemployment (r ≈ −0.768). The corresponding scatterplot has a clear downward orientation, consistent with Okun’s Law: stronger economic activity is generally associated with falling unemployment. This is an association, not evidence of causality.
Consumption and Production have a moderate positive association (r ≈ 0.529), and Consumption and Unemployment have a moderate negative association (r ≈ −0.527). In contrast, Production and Savings have almost no linear association (r ≈ −0.059). Scatterplot dispersion is broadly consistent with these strengths. The diagonal density curves show concentrated distributions with some extreme observations, particularly for Savings.
The time plots provide complementary evidence: large declines in Production sometimes coincide with rises in Unemployment, notably around the 2008–2009 financial crisis. Consumption and Production also show some simultaneous downturns. Savings is much more volatile, with large spikes that do not consistently coincide with Production changes. Since these are time series, contemporaneous correlations do not establish causal effects or predictive accuracy.
europe_macro <- global_economy |>
filter(Country %in% c("Spain", "France", "Italy"),
Year >= 1995, Year <= 2017)
glimpse(europe_macro)
## Rows: 69
## Columns: 9
## Key: Country [3]
## $ Country <fct> "France", "France", "France", "France", "France", "France",…
## $ Code <fct> FRA, FRA, FRA, FRA, FRA, FRA, FRA, FRA, FRA, FRA, FRA, FRA,…
## $ Year <dbl> 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,…
## $ GDP <dbl> 1.601095e+12, 1.605675e+12, 1.452885e+12, 1.503109e+12, 1.4…
## $ Growth <dbl> 2.0850845, 1.3880040, 2.3373334, 3.5562013, 3.4070991, 3.87…
## $ CPI <dbl> 79.46911, 81.04489, 82.02062, 82.55468, 82.99812, 84.38913,…
## $ Imports <dbl> 21.02320, 21.27368, 22.51030, 23.38027, 23.68439, 27.26627,…
## $ Exports <dbl> 22.62293, 23.05556, 25.52320, 26.12649, 26.07654, 28.59497,…
## $ Population <dbl> 59541899, 59753100, 59964851, 60186288, 60496718, 60912500,…
europe_macro |> count(Country)
## # A tibble: 3 × 2
## Country n
## <fct> <int>
## 1 France 23
## 2 Italy 23
## 3 Spain 23
The filtered dataset has 69 annual observations (23 per country), with year as time index and country as key. Variables include GDP, Growth, CPI, Imports, Exports and Population. Imports and Exports are shares of GDP, not absolute monetary totals.
europe_long <- europe_macro |>
as_tibble() |>
pivot_longer(cols = c(GDP, Growth, CPI, Imports, Exports, Population),
names_to = "Variable", values_to = "Value")
ggplot(europe_long, aes(x = Year, y = Value, color = Country)) +
geom_line(linewidth = 0.85) +
facet_wrap(~Variable, scales = "free_y", ncol = 2) +
labs(title = "Macroeconomic Comparison: Spain, France and Italy",
subtitle = "Annual data, 1995–2017", x = "Year", y = "Value")
France has the highest GDP levels, followed by Italy and Spain. Spain generally experiences stronger growth before 2008, while Italy shows weaker growth and the sharpest GDP growth contraction around 2009. All three countries show a pronounced slowdown around the global financial crisis. CPI rises across the sample, though at different rates. Imports and Exports (as shares of GDP) drop around 2009, then recover; Spain’s export share rises particularly strongly after the crisis. France and Spain show population growth, while Italy grows more slowly and stabilises toward the end. The shared crisis response contrasts with differences in economic size, growth and trade exposure.
europe_pairs <- europe_macro |>
as_tibble() |>
select(Country, Growth, CPI, Imports, Exports, Population)
GGally::ggpairs(
europe_pairs,
columns = 2:6,
mapping = aes(color = Country, alpha = 0.6),
upper = list(continuous = "cor"),
lower = list(continuous = "points"),
diag = list(continuous = "densityDiag")
)
for (ctry in c("France", "Italy", "Spain")) {
cat("\n", ctry, "\n")
x <- europe_pairs |>
filter(Country == ctry) |>
select(-Country)
print(round(cor(x, use = "pairwise.complete.obs"), 3))
}
##
## France
## Growth CPI Imports Exports Population
## Growth 1.000 -0.470 -0.228 -0.019 -0.461
## CPI -0.470 1.000 0.924 0.763 0.997
## Imports -0.228 0.924 1.000 0.927 0.926
## Exports -0.019 0.763 0.927 1.000 0.772
## Population -0.461 0.997 0.926 0.772 1.000
##
## Italy
## Growth CPI Imports Exports Population
## Growth 1.000 -0.481 -0.182 -0.027 -0.413
## CPI -0.481 1.000 0.853 0.773 0.962
## Imports -0.182 0.853 1.000 0.759 0.756
## Exports -0.027 0.773 0.759 1.000 0.823
## Population -0.413 0.962 0.756 0.823 1.000
##
## Spain
## Growth CPI Imports Exports Population
## Growth 1.000 -0.551 0.253 -0.089 -0.619
## CPI -0.551 1.000 0.513 0.667 0.984
## Imports 0.253 0.513 1.000 0.617 0.424
## Exports -0.089 0.667 0.617 1.000 0.540
## Population -0.619 0.984 0.424 0.540 1.000
The strongest positive association within each country is CPI–Population: France r ≈ 0.997, Italy r ≈ 0.962, and Spain r ≈ 0.984. Both variables trend upward over time, so these very high level correlations may be spurious and should not be interpreted causally. Their scatterplots show clear upward patterns.
Imports–Exports is also positively related in all three countries: France r ≈ 0.927, Italy r ≈ 0.759 and Spain r ≈ 0.617. The upward scatterplot pattern is most pronounced in France. This is consistent with internationally integrated economies, in which imports may include intermediate inputs used in export production.
Among the negative associations within countries, Growth–Population is most negative in Spain (r ≈ −0.619), followed by France (≈ −0.461) and Italy (≈ −0.413). Growth–CPI is negative in Spain (≈ −0.551), Italy (≈ −0.481) and France (≈ −0.470). Such correlations can reflect common time trends, changing macroeconomic conditions and shocks rather than direct causal effects. Growth–Exports is near zero within each country, and its scatterplots show no clear linear pattern.
The diagonal panels compare the distributions of each variable. Growth includes negative observations in downturns; Imports and Exports differ in location and spread across countries. Scatterplots and correlation coefficients describe contemporaneous linear association, not causal direction.
Target: Exports (% of GDP). Candidate predictors: Imports (% of GDP) and CPI.
Imports is the more convincing candidate: its correlation with Exports is positive in all three countries, with a relatively clear upward pattern, and imports of intermediate inputs can support export production. CPI also has positive correlations with Exports (France ≈ 0.763; Italy ≈ 0.773; Spain ≈ 0.667), but the relationship may be driven by shared trends rather than meaningful predictive information. CPI is a domestic price index, not a direct measure of international price competitiveness.
To test actual predictive usefulness, we would need to account for trends and time dependence, consider lagged predictor values, and evaluate forecasts on held-out years. Contemporaneous correlations alone do not establish forecasting power.
External reference: World Bank, Trade Overview: https://www.worldbank.org/en/topic/trade/overview. This provides economic background on trade integration; it is not a source for the correlations calculated above. See also Hyndman & Athanasopoulos, Forecasting: Principles and Practice (3rd ed.), https://otexts.com/fpp3/, for time-series graphics and correlation concepts.
2×4-MA and 2×12-MA
2×4-MA. We first compute two 4-MAs, centred at \(t-\tfrac12\) and \(t+\tfrac12\):
\[\hat T_{t-1/2} = \tfrac14\left(y_{t-2}+y_{t-1}+y_t+y_{t+1}\right)\]
\[\hat T_{t+1/2} = \tfrac14\left(y_{t-1}+y_t+y_{t+1}+y_{t+2}\right)\]
Their average is centred at \(t\):
\[\hat T_t = \tfrac12\left(\hat T_{t-1/2}+\hat T_{t+1/2}\right) = \tfrac18 y_{t-2} + \tfrac14 y_{t-1} + \tfrac14 y_t + \tfrac14 y_{t+1} + \tfrac18 y_{t+2}\]
2×12-MA. Same idea with two 12-MAs:
\[\hat T_t = \tfrac{1}{24}y_{t-6} + \tfrac{1}{12}\left(y_{t-5}+\dots+y_{t+5}\right) + \tfrac{1}{24}y_{t+6}\]
Why they remove seasonality. An even-order MA is not centred, so a second 2-MA is applied to centre it. The two end points (\(t\pm2\) for quarterly data, \(t\pm6\) for monthly data) belong to the same season, so together they receive \(\tfrac18+\tfrac18=\tfrac14\) (or \(\tfrac1{24}+\tfrac1{24}=\tfrac1{12}\)). Every season gets the same weight \(1/m\), so the seasonal effects cancel out and only the trend-cycle remains.
\[\text{3×3-MA:}\quad \hat T_t = \tfrac19\left(y_{t-2}+2y_{t-1}+3y_t+2y_{t+1}+y_{t+2}\right)\]
\[\text{3×5-MA:}\quad \hat T_t = \tfrac1{15}\left(y_{t-3}+2y_{t-2}+3y_{t-1}+3y_t+3y_{t+1}+2y_{t+2}+y_{t+3}\right)\]
| Filter | Weights | Observations | Uniform MA, same length |
|---|---|---|---|
| 3×3-MA | \(\tfrac19(1,2,3,2,1)\) | 5 | 5-MA: 0.20 each |
| 3×5-MA | \(\tfrac1{15}(1,2,3,3,3,2,1)\) | 7 | 7-MA: 0.143 each |
The composite filters give more weight to the centre and less to the end points (tent/trapezoid shape), so they produce a smoother trend than the uniform MA. A 3×3-MA attenuates periodic variation of period 3; a 3×5-MA attenuates periods 3 and 5 (e.g. a 5-day working-week pattern in daily data).
An outlier of size \(A\) shifts the moving average by (weight of its position) \(\times A\).
| Outlier position | 5-MA | 2×4-MA | 3×3-MA |
|---|---|---|---|
| Centre | \(0.20A\) | \(0.25A\) | \(0.33A\) |
| End point | \(0.20A\) | \(0.125A\) | \(0.11A\) |
The uniform 5-MA reacts in the same way wherever the outlier is. The non-uniform filters are more sensitive to an outlier near the centre of the window (larger weight) and less sensitive near its end points (smaller weight). None of these filters is robust: the outlier always leaks into the trend estimate, which motivates robust methods such as