Skip to content

Commit

Permalink
Update blog quote
Browse files Browse the repository at this point in the history
  • Loading branch information
jvivian committed Mar 10, 2024
1 parent 8160a03 commit 7000057
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
4 changes: 2 additions & 2 deletions _freeze/posts/dr-dfm-covid/index/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"hash": "c61eca44297b50e08bfff6c36dada6cf",
"hash": "614675d3c140ff3ad4e581d5b64c5b14",
"result": {
"markdown": "---\ntitle: \"Covid-19 Data-Rich Dynamic Factor Model\"\nsubtitle: \"Overview, Python Package, and Interactive Analysis\"\nauthor: \"John Vivian, Aaron Cooke, Josh Fitzgerald\"\ndate: \"2024-03-09\"\ncategories: ['Math', 'Modeling', 'Python']\nimage: \"jv_dfm.jpg\"\nformat:\n html:\n toc: true\n output-file: presentation-post.html\neditor:\n render-on-save: true\ncode:\n echo: false\n---\n\n## Understanding the Economic Impact of COVID-19 Through Data\nAs the world grapples with the ongoing effects of the COVID-19 pandemic, it is necessary to leverage advanced analytical tools to understand its economic impacts. Our project leverages Dynamic Factor Models (DFMs) to uncover hidden patterns and relationships in large amounts of economic data generated during this period. This presentation will introduce you to the core concepts of DFMs, the specific challenges posed by COVID-19 data, and the Python package we designed to address these challenges.\n\n\n# Dynamic Factor Models\n\n## Dynamic Factor Models: A Primer\n\nDynamic Factor Models are powerful statistical tools that help us make sense of complex, interconnected data. By identifying latent factors that influence observed variables over time, DFMs can reveal the underlying trends and dynamics of economic systems. This approach is particularly valuable in the context of COVID-19, where traditional models may struggle to account for rapidly changing conditions.\n\n## The Model at a Glance\n\nConsider the basic Dynamic Factor Model equation:\n\n$$y_t = \\Lambda f_t + \\epsilon_t$$\n\n<br>\n\nHere's what each symbol represents:\n\n- $y_t$: The observed variables at time $t$.\n- $\\Lambda$: The loading matrix, showing how each latent factor influences observed variables.\n- $f_t$: The latent factors, representing underlying trends.\n- $\\epsilon_t$: The error term, accounting for discrepancies between model predictions and observed data.\n\n\n## Visualizing the Model\n:::{.columns}\n::::{.column width=\"60%\"}\n<br><br><br>\n\nThe latent factors ($f_t$) influence the observed variables ($y_t$) through the loading matrix ($\\Lambda$), and the error term ($\\epsilon_t$) is associated with the observed variables.\n\n<br>\n\nThe loading matrix is a bridge that connects the latent factors, which are unobservable, to the observed variables, providing a mathematical representation of how the latent factors influence the observed data\n::::\n::::{.column width=\"30%\"}\n![](./model-viz.png)\n::::\n:::\n\n## Latent Factors and Observed Variables\nAn example of how the observed variables are mapped to latent factors through the loading matrix\n\n::: {.cell execution_count=1}\n\n::: {.cell-output .cell-output-display}\n![](index_files/figure-html/cell-2-output-1.png){width=758 height=373}\n:::\n:::\n\n\n## Extending the Model with Time Dynamics\nBy incorporating autoregressive components, we can capture the evolving nature of economic relationships during the pandemic. This advanced model formulation allows for a more accurate representation of the data, enabling better forecasts and insights.\n\n$$\n\\begin{split}\\begin{align}\ny_t & = \\Lambda f_t + B x_t + u_t \\\\\nf_t & = A_1 f_{t-1} + \\dots + A_p f_{t-p} + \\eta_t \\qquad \\eta_t \\sim N(0, I)\\\\\nu_t & = C_1 u_{t-1} + \\dots + C_q u_{t-q} + \\varepsilon_t \\qquad \\varepsilon_t \\sim N(0, \\Sigma)\n\\end{align}\\end{split}\n$$\n\n\nWhere $y_t$ is observed, $f_t$ are unobserved latent factors, $x_t$ are optional (unused for our case) exogenous variables, and the dynamic evolution of latent factors is expressed using the transition matrix $A$ with $\\eta_t$ representing new information or random shocks. $u_t$ is the error or \"idiosyncratic\" process\n\n\nThis model is then cast into state space form and the unobserved factors estimated via the Kalman filter. The likelihood can be evaluated as a byproduct of the filtering recursions with maximum likelihood estimation used to estimate the parameters.\n\n<br>\n$$f_t = A f_{t-1} + \\eta_t$$\n\n$A$: Transition matrix<br>\n$\\eta_t$: Innovation term\n\n<br>\n\n- The transition matrix, often denoted as $A$, is a square matrix that governs the temporal evolution of the latent factors\n- Each element of the matrix represents the influence of one latent factor at the current time on the corresponding latent factor at the next time point\n- The elements of the transition matrix $A$ determine how each latent factor at the previous time point contributes to the latent factors at the current time point\n- Values in the diagonal of $A$ represent the persistence of each latent factor over time\n- Off-diagonal elements indicate the influence of one latent factor on another\n\n## Interpreting Transition Matrices \n\nExamining the first transition matrix\n\n::: {.cell execution_count=2}\n\n::: {.cell-output .cell-output-display}\n![](index_files/figure-html/cell-3-output-1.png){width=750 height=373}\n:::\n:::\n\n\n- The diagonal elements (0.8 and 0.7) are relatively high, indicating a strong persistence of each latent factor over time.\n- The off-diagonal elements (0.2 and 0.3) suggest moderate influence of one latent factor on the other, allowing for some interaction between the two factors.\n- Summary: latent factors have a tendency to persist, with some interdependence.\n\n\n### Examining the second transition matrix\n- The diagonal elements (0.5 and 0.4) are lower compared to Transition Matrix 1, suggesting less persistence of each latent factor over time.\n- The off-diagonal elements (0.5 and 0.6) indicate a relatively stronger influence of one latent factor on the other compared to Transition Matrix 1.\n- Summary: latent factors are less likely to persist and may be influenced more by each other, allowing for a more dynamic and responsive behavior.\n\n## Factor Constraints: Enhancing Model Interpretability\nBy applying constraints to the model parameters, we can improve interpretability and reduce complexity while incorporating prior domain knowledge about variable relationships.\n\nFor example, setting certain elements of the loading matrix to zero might suggest that specific observed variables are not influenced by particular latent factors.\n\nBelow is an example of a boolean loading matrix with constraints\n\n| Dep. variable | Global.1 | Pandemic | Employment | Consumption | Inflation |\n|-----------------|----------|----------|------------|-------------|-----------|\n| Supply_1 | X | | | | |\n| Supply_7 | X | | | | |\n| Monetary_5 | X | | | | |\n| Monetary_9 | X | | | | |\n| Supply_2 | X | | X | | |\n| Supply_3 | X | | X | | |\n| Demand_7 | X | | X | | |\n| Demand_3 | X | | | X | |\n| Demand_5 | X | | | X | |\n| Monetary_2 | X | | | | X |\n| Monetary_1 | X | | | | X |\n| Pandemic_2 | X | X | | | |\n| Pandemic_9 | X | X | | | |\n\n\n# Our Python Package: Modeling and Analysis\n\n## Implementation\nWe are developing a Python package that simplifies the process of applying DFMs to COVID-19 economic data. The package includes features such as:\n\n<br>\n\n- Poetry for dependency management\n- CI with GitHub Actions\n- Pre-commit hooks with pre-commit\n- Code quality with black & ruff\n- Testing and coverage with pytest and codecov\n- Documentation with MkDocs\n- Compatibility testing for multiple versions of Python with Tox\n- Containerization with Docker\n\n## Dashboard \n<br>\nOur package contains a simplified interface for running parameterized DFM models\n\n:::{.column-page}\n![](runner.png)\n:::\n\n## Dashboard - Data Explorer \n<br>\nOur package includes a comprehensive dashboard with features for data exploration, factor analysis, and comparative model testing. Here's a sneak peek at what you can do:\n\n\n:::{.column-page}\n![](data_explorer.png)\n:::\n\n## Dashboard - Factor Analysis\n<br>\nDive deep into the relationships between latent factors and observed variables. Understand how economic trends evolve over time.\n\n:::{.column-page}\n![](factor_analysis.png)\n:::\n\n## Dashboard - Comparative Analysis \nTest and compare different model configurations to identify the most accurate representations of the data.\n\n:::{.column-page}\n![](comparative_analysis.png)\n:::\n\n\n# Future Work\n\n<br>\n\nOur next steps involve incorporating the insights gained from DFMs into a [Synthetic Control Model](https://github.com/OscarEngelbrektson/SyntheticControlMethods) to further refine our understanding of COVID-19's economic impact by exploring counter-factual statements. We are garnering feedback on our work and are hoping to submit for publication within the year!\n\nThank you for reading.\n\n",
"markdown": "---\ntitle: \"Covid-19 Data-Rich Dynamic Factor Model\"\nsubtitle: \"Overview, Python Package, and Interactive Analysis\"\nauthor: \"John Vivian, Aaron Cooke, Josh Fitzgerald\"\ndate: \"2024-03-09\"\ncategories: ['Math', 'Modeling', 'Python']\nimage: \"jv_dfm.jpg\"\nformat:\n html:\n toc: true\n output-file: presentation-post.html\neditor:\n render-on-save: true\ncode:\n echo: false\n---\n\n## Understanding the Economic Impact of COVID-19 Through Data\n> The only function of economic forecasting is to make astrology look respectable [^1]\n\n[^1]: John Kenneth Galbraith\n\nAs the world grapples with the ongoing effects of the COVID-19 pandemic, it is necessary to leverage advanced analytical tools to understand its economic impacts. Our project leverages Dynamic Factor Models (DFMs) to uncover hidden patterns and relationships in large amounts of economic data generated during this period. This presentation will introduce you to the core concepts of DFMs, the specific challenges posed by COVID-19 data, and the Python package we designed to address these challenges.\n\n\n# Dynamic Factor Models\n\n## Dynamic Factor Models: A Primer\n\nDynamic Factor Models are powerful statistical tools that help us make sense of complex, interconnected data. By identifying latent factors that influence observed variables over time, DFMs can reveal the underlying trends and dynamics of economic systems. This approach is particularly valuable in the context of COVID-19, where traditional models may struggle to account for rapidly changing conditions.\n\n## The Model at a Glance\n\nConsider the basic Dynamic Factor Model equation:\n\n$$y_t = \\Lambda f_t + \\epsilon_t$$\n\n<br>\n\nHere's what each symbol represents:\n\n- $y_t$: The observed variables at time $t$.\n- $\\Lambda$: The loading matrix, showing how each latent factor influences observed variables.\n- $f_t$: The latent factors, representing underlying trends.\n- $\\epsilon_t$: The error term, accounting for discrepancies between model predictions and observed data.\n\n\n## Visualizing the Model\n:::{.columns}\n::::{.column width=\"60%\"}\n<br><br><br>\n\nThe latent factors ($f_t$) influence the observed variables ($y_t$) through the loading matrix ($\\Lambda$), and the error term ($\\epsilon_t$) is associated with the observed variables.\n\n<br>\n\nThe loading matrix is a bridge that connects the latent factors, which are unobservable, to the observed variables, providing a mathematical representation of how the latent factors influence the observed data\n::::\n::::{.column width=\"30%\"}\n![](./model-viz.png)\n::::\n:::\n\n## Latent Factors and Observed Variables\nAn example of how the observed variables are mapped to latent factors through the loading matrix\n\n::: {.cell execution_count=1}\n\n::: {.cell-output .cell-output-display}\n![](index_files/figure-html/cell-2-output-1.png){width=758 height=373}\n:::\n:::\n\n\n## Extending the Model with Time Dynamics\nBy incorporating autoregressive components, we can capture the evolving nature of economic relationships during the pandemic. This advanced model formulation allows for a more accurate representation of the data, enabling better forecasts and insights.\n\n$$\n\\begin{split}\\begin{align}\ny_t & = \\Lambda f_t + B x_t + u_t \\\\\nf_t & = A_1 f_{t-1} + \\dots + A_p f_{t-p} + \\eta_t \\qquad \\eta_t \\sim N(0, I)\\\\\nu_t & = C_1 u_{t-1} + \\dots + C_q u_{t-q} + \\varepsilon_t \\qquad \\varepsilon_t \\sim N(0, \\Sigma)\n\\end{align}\\end{split}\n$$\n\n\nWhere $y_t$ is observed, $f_t$ are unobserved latent factors, $x_t$ are optional (unused for our case) exogenous variables, and the dynamic evolution of latent factors is expressed using the transition matrix $A$ with $\\eta_t$ representing new information or random shocks. $u_t$ is the error or \"idiosyncratic\" process\n\n\nThis model is then cast into state space form and the unobserved factors estimated via the Kalman filter. The likelihood can be evaluated as a byproduct of the filtering recursions with maximum likelihood estimation used to estimate the parameters.\n\n<br>\n$$f_t = A f_{t-1} + \\eta_t$$\n\n$A$: Transition matrix<br>\n$\\eta_t$: Innovation term\n\n<br>\n\n- The transition matrix, often denoted as $A$, is a square matrix that governs the temporal evolution of the latent factors\n- Each element of the matrix represents the influence of one latent factor at the current time on the corresponding latent factor at the next time point\n- The elements of the transition matrix $A$ determine how each latent factor at the previous time point contributes to the latent factors at the current time point\n- Values in the diagonal of $A$ represent the persistence of each latent factor over time\n- Off-diagonal elements indicate the influence of one latent factor on another\n\n## Interpreting Transition Matrices \n\nExamining the first transition matrix\n\n::: {.cell execution_count=2}\n\n::: {.cell-output .cell-output-display}\n![](index_files/figure-html/cell-3-output-1.png){width=750 height=373}\n:::\n:::\n\n\n- The diagonal elements (0.8 and 0.7) are relatively high, indicating a strong persistence of each latent factor over time.\n- The off-diagonal elements (0.2 and 0.3) suggest moderate influence of one latent factor on the other, allowing for some interaction between the two factors.\n- Summary: latent factors have a tendency to persist, with some interdependence.\n\n\n### Examining the second transition matrix\n- The diagonal elements (0.5 and 0.4) are lower compared to Transition Matrix 1, suggesting less persistence of each latent factor over time.\n- The off-diagonal elements (0.5 and 0.6) indicate a relatively stronger influence of one latent factor on the other compared to Transition Matrix 1.\n- Summary: latent factors are less likely to persist and may be influenced more by each other, allowing for a more dynamic and responsive behavior.\n\n## Factor Constraints: Enhancing Model Interpretability\nBy applying constraints to the model parameters, we can improve interpretability and reduce complexity while incorporating prior domain knowledge about variable relationships.\n\nFor example, setting certain elements of the loading matrix to zero might suggest that specific observed variables are not influenced by particular latent factors.\n\nBelow is an example of a boolean loading matrix with constraints\n\n| Dep. variable | Global.1 | Pandemic | Employment | Consumption | Inflation |\n|-----------------|----------|----------|------------|-------------|-----------|\n| Supply_1 | X | | | | |\n| Supply_7 | X | | | | |\n| Monetary_5 | X | | | | |\n| Monetary_9 | X | | | | |\n| Supply_2 | X | | X | | |\n| Supply_3 | X | | X | | |\n| Demand_7 | X | | X | | |\n| Demand_3 | X | | | X | |\n| Demand_5 | X | | | X | |\n| Monetary_2 | X | | | | X |\n| Monetary_1 | X | | | | X |\n| Pandemic_2 | X | X | | | |\n| Pandemic_9 | X | X | | | |\n\n\n# Our Python Package: Modeling and Analysis\n\n## Implementation\nWe are developing a Python package that simplifies the process of applying DFMs to COVID-19 economic data. The package includes features such as:\n\n<br>\n\n- Poetry for dependency management\n- CI with GitHub Actions\n- Pre-commit hooks with pre-commit\n- Code quality with black & ruff\n- Testing and coverage with pytest and codecov\n- Documentation with MkDocs\n- Compatibility testing for multiple versions of Python with Tox\n- Containerization with Docker\n\n## Dashboard \n<br>\nOur package contains a simplified interface for running parameterized DFM models\n\n:::{.column-page}\n![](runner.png)\n:::\n\n## Dashboard - Data Explorer \n<br>\nOur package includes a comprehensive dashboard with features for data exploration, factor analysis, and comparative model testing. Here's a sneak peek at what you can do:\n\n\n:::{.column-page}\n![](data_explorer.png)\n:::\n\n## Dashboard - Factor Analysis\n<br>\nDive deep into the relationships between latent factors and observed variables. Understand how economic trends evolve over time.\n\n:::{.column-page}\n![](factor_analysis.png)\n:::\n\n## Dashboard - Comparative Analysis \nTest and compare different model configurations to identify the most accurate representations of the data.\n\n:::{.column-page}\n![](comparative_analysis.png)\n:::\n\n\n# Future Work\n\n<br>\n\nOur next steps involve incorporating the insights gained from DFMs into a [Synthetic Control Model](https://github.com/OscarEngelbrektson/SyntheticControlMethods) to further refine our understanding of COVID-19's economic impact by exploring counter-factual statements. We are garnering feedback on our work and are hoping to submit for publication within the year!\n\nThank you for reading.\n\n",
"supporting": [
"index_files/figure-html"
],
Expand Down
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ <h5 class="quarto-listing-category-title">Categories</h5><div class="quarto-list

<div class="quarto-listing quarto-listing-container-default" id="listing-listing">
<div class="list quarto-listing-default">
<div class="quarto-post image-right" data-index="0" data-categories="Math,Modeling,Python" data-listing-date-sort="1709971200000" data-listing-file-modified-sort="1710054356996" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="11">
<div class="quarto-post image-right" data-index="0" data-categories="Math,Modeling,Python" data-listing-date-sort="1709971200000" data-listing-file-modified-sort="1710054763452" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="11">
<div class="thumbnail">
<p><a href="./posts/dr-dfm-covid/presentation-post.html"> <img src="./posts/dr-dfm-covid/jv_dfm.jpg" class="thumbnail-image"> </a></p>
</div>
Expand All @@ -209,7 +209,7 @@ <h3 class="no-anchor listing-title">
</div>
<a href="./posts/dr-dfm-covid/presentation-post.html">
<div class="listing-description">
As the world grapples with the ongoing effects of the COVID-19 pandemic, it is necessary to leverage advanced analytical tools to understand its economic impacts. Our…
The only function of economic forecasting is to make astrology look respectable <sup>1</sup>
</div>
</a>
</div>
Expand Down
Loading

0 comments on commit 7000057

Please sign in to comment.