| Title: | Markov Chain Analysis for Structural Behaviour and Stability |
|---|---|
| Description: | Analyses the stability and structural behaviour of export and import patterns across multiple countries using a Markov chain modelling framework. Constructs transition probability matrices to quantify changes in trade shares between successive periods, thereby capturing persistence, structural shifts, and inter-country interdependence in trade performance. By iteratively generating expected trade distributions over time, the approach facilitates assessment of stability, long-run equilibrium tendencies, and comparative dynamics in longitudinal trade data, providing a rigorous tool for empirical analysis of export–import behaviour. Methodological foundations follow standard Markov chain theory as described in Gagniuc (2017) <Doi:10.1002/9781119387596>. |
| Authors: | Dr. Pramit Pandit [aut, cre], Mr. Ankit Kumar Singh [aut], Ms. Anita Sarkar [aut], Ms. Moumita Paul [aut], Dr. Bikramjeet Ghose [aut] |
| Maintainer: | Dr. Pramit Pandit <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.0 |
| Built: | 2026-05-24 10:17:27 UTC |
| Source: | https://github.com/cran/mcanalysis |
Calculate Expected Values using a Transition Matrix
calculate_expected(df, tm)calculate_expected(df, tm)
df |
A data frame where the first column is a time indicator (e.g., Year) and subsequent columns contain numeric values for different entities. |
tm |
A square transition probability matrix (TPM) where dimensions match
the number of entities in |
A data frame containing the original time indicator and the calculated expected values, rounded to 2 decimal places.
data <- data.frame( Year = 2009:2019, Country1 = c(136282.02, 182810.3, 252665.95, 170179.0, 227754.5, 183355.08, 173966.0, 185902.24, 218786.72, 203095.96, 213821.57), Country2 = c(1204.78, 2977.8, 241496.85, 139362.9, 40466.0, 183771.04, 18418.0, 158388.14, 50780.6, 38225.01, 140453.68), Country3 = c(61619.92, 46009.64, 54823.95, 57906.1, 60384.0, 66320.51, 50699.0, 50737.0, 44180.35, 47064.0, 47672.62), Country4 = c(63837.63, 71175.86, 76595.18, 70274.68, 59258.64, 68927.62, 72211.32, 62783.33, 34565.08, 29965.35, 35145.76), Country5 = c(8512.95, 11496.78, 32888.2, 22765.61, 23116.0, 34457.4, 63048.0, 44125.08, 10829.03, 25439.9, 30022.83), Country6 = c(3400.56, 19675.75, 38339.7, 4721.01, 2686.8, 33677.3, 15791.0, 22382.0, 627.0, 895.0, 34082.0), Country7 = c(65388.45, 99607.1, 135807.1, 70428.06, 95998.9, 137877.31, 148593.09, 201386.55, 144250.42, 144501.89, 163244.46) ) transition_matrix <- create_tpm(data) expected_results <- calculate_expected(data, transition_matrix) expected_resultsdata <- data.frame( Year = 2009:2019, Country1 = c(136282.02, 182810.3, 252665.95, 170179.0, 227754.5, 183355.08, 173966.0, 185902.24, 218786.72, 203095.96, 213821.57), Country2 = c(1204.78, 2977.8, 241496.85, 139362.9, 40466.0, 183771.04, 18418.0, 158388.14, 50780.6, 38225.01, 140453.68), Country3 = c(61619.92, 46009.64, 54823.95, 57906.1, 60384.0, 66320.51, 50699.0, 50737.0, 44180.35, 47064.0, 47672.62), Country4 = c(63837.63, 71175.86, 76595.18, 70274.68, 59258.64, 68927.62, 72211.32, 62783.33, 34565.08, 29965.35, 35145.76), Country5 = c(8512.95, 11496.78, 32888.2, 22765.61, 23116.0, 34457.4, 63048.0, 44125.08, 10829.03, 25439.9, 30022.83), Country6 = c(3400.56, 19675.75, 38339.7, 4721.01, 2686.8, 33677.3, 15791.0, 22382.0, 627.0, 895.0, 34082.0), Country7 = c(65388.45, 99607.1, 135807.1, 70428.06, 95998.9, 137877.31, 148593.09, 201386.55, 144250.42, 144501.89, 163244.46) ) transition_matrix <- create_tpm(data) expected_results <- calculate_expected(data, transition_matrix) expected_results
Create a Transition Probability Matrix (TPM)
create_tpm(df)create_tpm(df)
df |
A data frame where the first column is a time indicator (e.g., Year) and subsequent columns contain numeric values for different entities (e.g., countries). |
A square matrix representing the transition probabilities between entities, rounded to 4 decimal places.
data <- data.frame( Year = 2009:2019, Country1 = c(136282.02, 182810.3, 252665.95, 170179.0, 227754.5, 183355.08, 173966.0, 185902.24, 218786.72, 203095.96, 213821.57), Country2 = c(1204.78, 2977.8, 241496.85, 139362.9, 40466.0, 183771.04, 18418.0, 158388.14, 50780.6, 38225.01, 140453.68), Country3 = c(61619.92, 46009.64, 54823.95, 57906.1, 60384.0, 66320.51, 50699.0, 50737.0, 44180.35, 47064.0, 47672.62), Country4 = c(63837.63, 71175.86, 76595.18, 70274.68, 59258.64, 68927.62, 72211.32, 62783.33, 34565.08, 29965.35, 35145.76), Country5 = c(8512.95, 11496.78, 32888.2, 22765.61, 23116.0, 34457.4, 63048.0, 44125.08, 10829.03, 25439.9, 30022.83), Country6 = c(3400.56, 19675.75, 38339.7, 4721.01, 2686.8, 33677.3, 15791.0, 22382.0, 627.0, 895.0, 34082.0), Country7 = c(65388.45, 99607.1, 135807.1, 70428.06, 95998.9, 137877.31, 148593.09, 201386.55, 144250.42, 144501.89, 163244.46) ) transition_matrix <- create_tpm(data) transition_matrixdata <- data.frame( Year = 2009:2019, Country1 = c(136282.02, 182810.3, 252665.95, 170179.0, 227754.5, 183355.08, 173966.0, 185902.24, 218786.72, 203095.96, 213821.57), Country2 = c(1204.78, 2977.8, 241496.85, 139362.9, 40466.0, 183771.04, 18418.0, 158388.14, 50780.6, 38225.01, 140453.68), Country3 = c(61619.92, 46009.64, 54823.95, 57906.1, 60384.0, 66320.51, 50699.0, 50737.0, 44180.35, 47064.0, 47672.62), Country4 = c(63837.63, 71175.86, 76595.18, 70274.68, 59258.64, 68927.62, 72211.32, 62783.33, 34565.08, 29965.35, 35145.76), Country5 = c(8512.95, 11496.78, 32888.2, 22765.61, 23116.0, 34457.4, 63048.0, 44125.08, 10829.03, 25439.9, 30022.83), Country6 = c(3400.56, 19675.75, 38339.7, 4721.01, 2686.8, 33677.3, 15791.0, 22382.0, 627.0, 895.0, 34082.0), Country7 = c(65388.45, 99607.1, 135807.1, 70428.06, 95998.9, 137877.31, 148593.09, 201386.55, 144250.42, 144501.89, 163244.46) ) transition_matrix <- create_tpm(data) transition_matrix