From d13f167247a096c7b7c226001061ef7bb9af6f72 Mon Sep 17 00:00:00 2001 From: jvivian Date: Sat, 9 Mar 2024 14:44:59 -0800 Subject: [PATCH] Update page to exclude code --- .../index/execute-results/html.json | 4 +- docs/index.html | 2 +- .../posts/dr-dfm-covid/presentation-post.html | 131 +----------------- docs/posts/kd-art/index.html | 2 +- docs/posts/kd-inked-into-creation/index.html | 12 +- docs/search.json | 10 +- docs/temp/kingdom-death/index.html | 20 +-- posts/dr-dfm-covid/index.qmd | 8 +- 8 files changed, 30 insertions(+), 159 deletions(-) diff --git a/_freeze/posts/dr-dfm-covid/index/execute-results/html.json b/_freeze/posts/dr-dfm-covid/index/execute-results/html.json index 234ed9a..c209620 100644 --- a/_freeze/posts/dr-dfm-covid/index/execute-results/html.json +++ b/_freeze/posts/dr-dfm-covid/index/execute-results/html.json @@ -1,7 +1,7 @@ { - "hash": "5e07d36d8ba2d1e674b491c3ddd35e12", + "hash": "acc512d489bd966243cee00587643bcd", "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\n\n
\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\n
\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
\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\n\n:::{.columns}\n::::{.column width=\"70%\"}\n
\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
\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 {.smaller}\n> Relationship between latent factors and observed variables via loading matrix\n\n::: {.cell execution_count=1}\n``` {.python .cell-code}\n# echo: false\nimport numpy as np\nimport matplotlib.pyplot as plt\n\n# Set seed for reproducibility\nnp.random.seed(42)\n\n# Generate dummy data\nnum_observed_variables = 4\nnum_time_points = 100\nloading_matrix = np.array([[0.5, 0.3, 0.8, 0.2],\n [0.7, 0.2, 0.5, 0.1]])\n\nlatent_factors = np.random.randn(num_time_points, 2)\nobserved_variables = np.dot(latent_factors, loading_matrix) + np.random.randn(num_time_points, num_observed_variables)\n\n# Plotting\nplt.figure(figsize=(10, 6))\n\n# Plot latent factors\nplt.subplot(2, 1, 1)\nplt.plot(latent_factors[:, 0], label='Latent Factor 1', linestyle='--')\nplt.plot(latent_factors[:, 1], label='Latent Factor 2', linestyle='--')\nplt.title('Latent Factors Over Time')\nplt.legend()\n\n# Plot observed variables\nplt.subplot(2, 1, 2)\nfor i in range(num_observed_variables):\n plt.plot(observed_variables[:, i], label=f'Observed Variable {i+1}')\nplt.title('Observed Variables Over Time')\nplt.legend()\n\nplt.tight_layout()\nplt.show()\n```\n\n::: {.cell-output .cell-output-display}\n![](index_files/figure-html/cell-2-output-1.png){width=950 height=565}\n:::\n:::\n\n\n## Extending the Model with Time Dynamics\n\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\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## Extending the Model with Time Dynamics {.smaller}\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
\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. . .\n\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\n## Extending the Model with Time Dynamics {.smaller}\n$$f_t = A f_{t-1} + \\eta_t$$\n\n$A$: Transition matrix
\n$\\eta_t$: Innovation term\n\n
\n\n:::{.incremental}\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\n## Interpreting Transition Matrices {.smaller}\n\nExamining the first transition matrix\n\n::: {.cell execution_count=2}\n``` {.python .cell-code}\n# echo: false\nimport numpy as np\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n\n# Set seed for reproducibility\nnp.random.seed(42)\n\n# Generate two different transition matrices\ntransition_matrix_1 = np.array([[0.8, 0.2],\n [0.3, 0.7]])\n\ntransition_matrix_2 = np.array([[0.5, 0.5],\n [0.6, 0.4]])\n\n# Create a figure with subplots\nfig, axs = plt.subplots(1, 2, figsize=(10, 4))\n\n# Plot heatmap for Transition Matrix 1\nsns.heatmap(transition_matrix_1, annot=True, cmap=\"Reds\", linewidths=.5, ax=axs[0])\naxs[0].set_title('Transition Matrix 1')\n\n# Plot heatmap for Transition Matrix 2\nsns.heatmap(transition_matrix_2, annot=True, cmap=\"Reds\", linewidths=.5, ax=axs[1])\naxs[1].set_title('Transition Matrix 2')\n\n# Adjust layout\nplt.tight_layout()\nplt.show()\n```\n\n::: {.cell-output .cell-output-display}\n![](index_files/figure-html/cell-3-output-1.png){width=936 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## Interpreting Transition Matrices {.smaller}\n\nExamining the second transition matrix\n\n::: {.cell execution_count=3}\n``` {.python .cell-code}\n# echo: false\nimport numpy as np\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n\n# Set seed for reproducibility\nnp.random.seed(42)\n\n# Generate two different transition matrices\ntransition_matrix_1 = np.array([[0.8, 0.2],\n [0.3, 0.7]])\n\ntransition_matrix_2 = np.array([[0.5, 0.5],\n [0.6, 0.4]])\n\n# Create a figure with subplots\nfig, axs = plt.subplots(1, 2, figsize=(10, 4))\n\n# Plot heatmap for Transition Matrix 1\nsns.heatmap(transition_matrix_1, annot=True, cmap=\"Reds\", linewidths=.5, ax=axs[0])\naxs[0].set_title('Transition Matrix 1')\n\n# Plot heatmap for Transition Matrix 2\nsns.heatmap(transition_matrix_2, annot=True, cmap=\"Reds\", linewidths=.5, ax=axs[1])\naxs[1].set_title('Transition Matrix 2')\n\n# Adjust layout\nplt.tight_layout()\nplt.show()\n```\n\n::: {.cell-output .cell-output-display}\n![](index_files/figure-html/cell-4-output-1.png){width=936 height=373}\n:::\n:::\n\n\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\n
\n\nBy applying constraints to the model parameters, we can improve interpretability and reduce complexity while incorporating prior domain knowledge about variable relationships.\n\n

\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\n## Factor Constraints {.smaller}\n> Factor loading constraint example\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 {.smaller}\n
\n\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
\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 {.smaller}\n
\nOur package contains a simplified interface for running parameterized DFM models\n\n:::{.column-page}\n![](runner.png)\n:::\n\n## Dashboard - Data Explorer {.smaller .scrollable}\n
\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 {.smaller}\n
\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 {.smaller .scrollable}\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
\n\nOur next steps involve incorporating the insights gained from DFMs into [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\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\n
\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\n
\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
\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\n\n:::{.columns}\n::::{.column width=\"70%\"}\n
\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
\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 {.smaller}\n> Relationship between latent factors and observed variables via 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=950 height=565}\n:::\n:::\n\n\n## Extending the Model with Time Dynamics\n\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\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## Extending the Model with Time Dynamics {.smaller}\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
\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. . .\n\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\n## Extending the Model with Time Dynamics {.smaller}\n$$f_t = A f_{t-1} + \\eta_t$$\n\n$A$: Transition matrix
\n$\\eta_t$: Innovation term\n\n
\n\n:::{.incremental}\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\n## Interpreting Transition Matrices {.smaller}\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=936 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## Interpreting Transition Matrices {.smaller}\n\nExamining the second transition matrix\n\n::: {.cell execution_count=3}\n\n::: {.cell-output .cell-output-display}\n![](index_files/figure-html/cell-4-output-1.png){width=936 height=373}\n:::\n:::\n\n\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\n
\n\nBy applying constraints to the model parameters, we can improve interpretability and reduce complexity while incorporating prior domain knowledge about variable relationships.\n\n

\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\n## Factor Constraints {.smaller}\nFactor constraint loadings example\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 {.smaller}\n
\n\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
\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 {.smaller}\n
\nOur package contains a simplified interface for running parameterized DFM models\n\n:::{.column-page}\n![](runner.png)\n:::\n\n## Dashboard - Data Explorer {.smaller .scrollable}\n
\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 {.smaller}\n
\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 {.smaller .scrollable}\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
\n\nOur next steps involve incorporating the insights gained from DFMs into [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\n", "supporting": [ "index_files/figure-html" ], diff --git a/docs/index.html b/docs/index.html index 6845908..6ac5b2f 100644 --- a/docs/index.html +++ b/docs/index.html @@ -183,7 +183,7 @@
Categories
-
+
diff --git a/docs/posts/dr-dfm-covid/presentation-post.html b/docs/posts/dr-dfm-covid/presentation-post.html index f8aabbf..36603ac 100644 --- a/docs/posts/dr-dfm-covid/presentation-post.html +++ b/docs/posts/dr-dfm-covid/presentation-post.html @@ -22,40 +22,6 @@ margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */ vertical-align: middle; } -/* CSS for syntax highlighting */ -pre > code.sourceCode { white-space: pre; position: relative; } -pre > code.sourceCode > span { display: inline-block; line-height: 1.25; } -pre > code.sourceCode > span:empty { height: 1.2em; } -.sourceCode { overflow: visible; } -code.sourceCode > span { color: inherit; text-decoration: inherit; } -div.sourceCode { margin: 1em 0; } -pre.sourceCode { margin: 0; } -@media screen { -div.sourceCode { overflow: auto; } -} -@media print { -pre > code.sourceCode { white-space: pre-wrap; } -pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; } -} -pre.numberSource code - { counter-reset: source-line 0; } -pre.numberSource code > span - { position: relative; left: -4em; counter-increment: source-line; } -pre.numberSource code > span > a:first-child::before - { content: counter(source-line); - position: relative; left: -1em; text-align: right; vertical-align: baseline; - border: none; display: inline-block; - -webkit-touch-callout: none; -webkit-user-select: none; - -khtml-user-select: none; -moz-user-select: none; - -ms-user-select: none; user-select: none; - padding: 0 4px; width: 4em; - } -pre.numberSource { margin-left: 3em; padding-left: 4px; } -div.sourceCode - { } -@media screen { -pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; } -} @@ -271,41 +237,6 @@

-
# echo: false
-import numpy as np
-import matplotlib.pyplot as plt
-
-# Set seed for reproducibility
-np.random.seed(42)
-
-# Generate dummy data
-num_observed_variables = 4
-num_time_points = 100
-loading_matrix = np.array([[0.5, 0.3, 0.8, 0.2],
-                           [0.7, 0.2, 0.5, 0.1]])
-
-latent_factors = np.random.randn(num_time_points, 2)
-observed_variables = np.dot(latent_factors, loading_matrix) + np.random.randn(num_time_points, num_observed_variables)
-
-# Plotting
-plt.figure(figsize=(10, 6))
-
-# Plot latent factors
-plt.subplot(2, 1, 1)
-plt.plot(latent_factors[:, 0], label='Latent Factor 1', linestyle='--')
-plt.plot(latent_factors[:, 1], label='Latent Factor 2', linestyle='--')
-plt.title('Latent Factors Over Time')
-plt.legend()
-
-# Plot observed variables
-plt.subplot(2, 1, 2)
-for i in range(num_observed_variables):
-    plt.plot(observed_variables[:, i], label=f'Observed Variable {i+1}')
-plt.title('Observed Variables Over Time')
-plt.legend()
-
-plt.tight_layout()
-plt.show()

@@ -357,35 +288,6 @@

Interpreting Transition Matrices

Examining the first transition matrix

-
# echo: false
-import numpy as np
-import seaborn as sns
-import matplotlib.pyplot as plt
-
-# Set seed for reproducibility
-np.random.seed(42)
-
-# Generate two different transition matrices
-transition_matrix_1 = np.array([[0.8, 0.2],
-                                [0.3, 0.7]])
-
-transition_matrix_2 = np.array([[0.5, 0.5],
-                                [0.6, 0.4]])
-
-# Create a figure with subplots
-fig, axs = plt.subplots(1, 2, figsize=(10, 4))
-
-# Plot heatmap for Transition Matrix 1
-sns.heatmap(transition_matrix_1, annot=True, cmap="Reds", linewidths=.5, ax=axs[0])
-axs[0].set_title('Transition Matrix 1')
-
-# Plot heatmap for Transition Matrix 2
-sns.heatmap(transition_matrix_2, annot=True, cmap="Reds", linewidths=.5, ax=axs[1])
-axs[1].set_title('Transition Matrix 2')
-
-# Adjust layout
-plt.tight_layout()
-plt.show()

@@ -400,35 +302,6 @@

I

Interpreting Transition Matrices

Examining the second transition matrix

-
# echo: false
-import numpy as np
-import seaborn as sns
-import matplotlib.pyplot as plt
-
-# Set seed for reproducibility
-np.random.seed(42)
-
-# Generate two different transition matrices
-transition_matrix_1 = np.array([[0.8, 0.2],
-                                [0.3, 0.7]])
-
-transition_matrix_2 = np.array([[0.5, 0.5],
-                                [0.6, 0.4]])
-
-# Create a figure with subplots
-fig, axs = plt.subplots(1, 2, figsize=(10, 4))
-
-# Plot heatmap for Transition Matrix 1
-sns.heatmap(transition_matrix_1, annot=True, cmap="Reds", linewidths=.5, ax=axs[0])
-axs[0].set_title('Transition Matrix 1')
-
-# Plot heatmap for Transition Matrix 2
-sns.heatmap(transition_matrix_2, annot=True, cmap="Reds", linewidths=.5, ax=axs[1])
-axs[1].set_title('Transition Matrix 2')
-
-# Adjust layout
-plt.tight_layout()
-plt.show()

@@ -448,9 +321,7 @@

Factor Constraints

-
-

Factor loading constraint example

-
+

Factor constraint loadings example

diff --git a/docs/posts/kd-art/index.html b/docs/posts/kd-art/index.html index 41b8f8c..adb6ce9 100644 --- a/docs/posts/kd-art/index.html +++ b/docs/posts/kd-art/index.html @@ -997,7 +997,7 @@

Tools & Versioning - + diff --git a/docs/posts/kd-inked-into-creation/index.html b/docs/posts/kd-inked-into-creation/index.html index 7e517f0..b73983e 100644 --- a/docs/posts/kd-inked-into-creation/index.html +++ b/docs/posts/kd-inked-into-creation/index.html @@ -261,7 +261,7 @@

Inked Into Creation

“Surely this must be the greatest game ever made! I must immediately find and play it!”

-

+

13 year old me: “What the fuck is this?”
@@ -270,7 +270,7 @@

Inked Into Creation

I ended up working on this, in some capacity, every day for almost three months (and am still working on it…). I got interested in Stable Diffusion and using Kingdom Death miniatures as the basis for some of the artwork.

-

+

And now for something, completely different
@@ -427,7 +427,7 @@

Year 7: Phoe
-

+

BONK! Gotcha 😏
@@ -668,7 +668,7 @@

Addendum

-

+

Figure 1: Settlement Intelligencia
@@ -676,7 +676,7 @@

Addendum

-

+

Figure 2: Dudes from Warforged and Alluvial
@@ -1095,7 +1095,7 @@

Addendum

});
- + diff --git a/docs/search.json b/docs/search.json index d59f2f9..d1c4846 100644 --- a/docs/search.json +++ b/docs/search.json @@ -424,7 +424,7 @@ "href": "temp/kingdom-death/index.html#summary-statistics", "title": "Kingdom Death", "section": "Summary Statistics", - "text": "Summary Statistics\n\nThere is a valid defence [sic] of using non-Bayesian methods, namely incompetence\n\n\n\n/tmp/ipykernel_2905/1245481724.py:9: DeprecationWarning:\n\n`apply` is deprecated. It has been renamed to `map_elements`.\n\n/tmp/ipykernel_2905/1245481724.py:10: DeprecationWarning:\n\n`cumsum` is deprecated. It has been renamed to `cum_sum`.\n\n\n\n\nCumulative Deaths Over Time\n\n\n\n \n\n\n\n\nMost Dangerous Foes\n\n\n/tmp/ipykernel_2905/510724665.py:2: DeprecationWarning:\n\n`groupby` is deprecated. It has been renamed to `group_by`.\n\n\n\n\n \n\n\n\n\nMost Hunted Quarries\n\n\n/tmp/ipykernel_2905/250231344.py:3: DeprecationWarning:\n\n`groupby` is deprecated. It has been renamed to `group_by`.\n\n/tmp/ipykernel_2905/250231344.py:4: DeprecationWarning:\n\n`count` is deprecated. It has been renamed to `len`.\n\n\n\n\n\n\n\n\n\n\ncount\n\n\nMonster\n\n\n\n\n\nWhite Lion\n10\n\n\nGigalion\n5\n\n\nAntelope\n4" + "text": "Summary Statistics\n\nThere is a valid defence [sic] of using non-Bayesian methods, namely incompetence\n\n\n\n/tmp/ipykernel_4035/1245481724.py:9: DeprecationWarning:\n\n`apply` is deprecated. It has been renamed to `map_elements`.\n\n/tmp/ipykernel_4035/1245481724.py:10: DeprecationWarning:\n\n`cumsum` is deprecated. It has been renamed to `cum_sum`.\n\n\n\n\nCumulative Deaths Over Time\n\n\n\n \n\n\n\n\nMost Dangerous Foes\n\n\n/tmp/ipykernel_4035/510724665.py:2: DeprecationWarning:\n\n`groupby` is deprecated. It has been renamed to `group_by`.\n\n\n\n\n \n\n\n\n\nMost Hunted Quarries\n\n\n/tmp/ipykernel_4035/250231344.py:3: DeprecationWarning:\n\n`groupby` is deprecated. It has been renamed to `group_by`.\n\n/tmp/ipykernel_4035/250231344.py:4: DeprecationWarning:\n\n`count` is deprecated. It has been renamed to `len`.\n\n\n\n\n\n\n\n\n\n\ncount\n\n\nMonster\n\n\n\n\n\nWhite Lion\n10\n\n\nGigalion\n5\n\n\nAntelope\n4" }, { "objectID": "temp/kingdom-death/index.html#acknowledgements", @@ -487,7 +487,7 @@ "href": "posts/dr-dfm-covid/presentation-post.html#latent-factors-and-observed-variables", "title": "Covid-19 Data-Rich Dynamic Factor Model", "section": "Latent Factors and Observed Variables", - "text": "Latent Factors and Observed Variables\n\nRelationship between latent factors and observed variables via loading matrix\n\n\n# echo: false\nimport numpy as np\nimport matplotlib.pyplot as plt\n\n# Set seed for reproducibility\nnp.random.seed(42)\n\n# Generate dummy data\nnum_observed_variables = 4\nnum_time_points = 100\nloading_matrix = np.array([[0.5, 0.3, 0.8, 0.2],\n [0.7, 0.2, 0.5, 0.1]])\n\nlatent_factors = np.random.randn(num_time_points, 2)\nobserved_variables = np.dot(latent_factors, loading_matrix) + np.random.randn(num_time_points, num_observed_variables)\n\n# Plotting\nplt.figure(figsize=(10, 6))\n\n# Plot latent factors\nplt.subplot(2, 1, 1)\nplt.plot(latent_factors[:, 0], label='Latent Factor 1', linestyle='--')\nplt.plot(latent_factors[:, 1], label='Latent Factor 2', linestyle='--')\nplt.title('Latent Factors Over Time')\nplt.legend()\n\n# Plot observed variables\nplt.subplot(2, 1, 2)\nfor i in range(num_observed_variables):\n plt.plot(observed_variables[:, i], label=f'Observed Variable {i+1}')\nplt.title('Observed Variables Over Time')\nplt.legend()\n\nplt.tight_layout()\nplt.show()" + "text": "Latent Factors and Observed Variables\n\nRelationship between latent factors and observed variables via loading matrix" }, { "objectID": "posts/dr-dfm-covid/presentation-post.html#extending-the-model-with-time-dynamics", @@ -515,14 +515,14 @@ "href": "posts/dr-dfm-covid/presentation-post.html#interpreting-transition-matrices", "title": "Covid-19 Data-Rich Dynamic Factor Model", "section": "Interpreting Transition Matrices", - "text": "Interpreting Transition Matrices\nExamining the first transition matrix\n\n# echo: false\nimport numpy as np\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n\n# Set seed for reproducibility\nnp.random.seed(42)\n\n# Generate two different transition matrices\ntransition_matrix_1 = np.array([[0.8, 0.2],\n [0.3, 0.7]])\n\ntransition_matrix_2 = np.array([[0.5, 0.5],\n [0.6, 0.4]])\n\n# Create a figure with subplots\nfig, axs = plt.subplots(1, 2, figsize=(10, 4))\n\n# Plot heatmap for Transition Matrix 1\nsns.heatmap(transition_matrix_1, annot=True, cmap=\"Reds\", linewidths=.5, ax=axs[0])\naxs[0].set_title('Transition Matrix 1')\n\n# Plot heatmap for Transition Matrix 2\nsns.heatmap(transition_matrix_2, annot=True, cmap=\"Reds\", linewidths=.5, ax=axs[1])\naxs[1].set_title('Transition Matrix 2')\n\n# Adjust layout\nplt.tight_layout()\nplt.show()\n\n\n\n\n\nThe diagonal elements (0.8 and 0.7) are relatively high, indicating a strong persistence of each latent factor over time.\nThe 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.\nSummary: latent factors have a tendency to persist, with some interdependence." + "text": "Interpreting Transition Matrices\nExamining the first transition matrix\n\n\n\n\n\n\nThe diagonal elements (0.8 and 0.7) are relatively high, indicating a strong persistence of each latent factor over time.\nThe 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.\nSummary: latent factors have a tendency to persist, with some interdependence." }, { "objectID": "posts/dr-dfm-covid/presentation-post.html#interpreting-transition-matrices-1", "href": "posts/dr-dfm-covid/presentation-post.html#interpreting-transition-matrices-1", "title": "Covid-19 Data-Rich Dynamic Factor Model", "section": "Interpreting Transition Matrices", - "text": "Interpreting Transition Matrices\nExamining the second transition matrix\n\n# echo: false\nimport numpy as np\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n\n# Set seed for reproducibility\nnp.random.seed(42)\n\n# Generate two different transition matrices\ntransition_matrix_1 = np.array([[0.8, 0.2],\n [0.3, 0.7]])\n\ntransition_matrix_2 = np.array([[0.5, 0.5],\n [0.6, 0.4]])\n\n# Create a figure with subplots\nfig, axs = plt.subplots(1, 2, figsize=(10, 4))\n\n# Plot heatmap for Transition Matrix 1\nsns.heatmap(transition_matrix_1, annot=True, cmap=\"Reds\", linewidths=.5, ax=axs[0])\naxs[0].set_title('Transition Matrix 1')\n\n# Plot heatmap for Transition Matrix 2\nsns.heatmap(transition_matrix_2, annot=True, cmap=\"Reds\", linewidths=.5, ax=axs[1])\naxs[1].set_title('Transition Matrix 2')\n\n# Adjust layout\nplt.tight_layout()\nplt.show()\n\n\n\n\n\nThe diagonal elements (0.5 and 0.4) are lower compared to Transition Matrix 1, suggesting less persistence of each latent factor over time.\nThe 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.\nSummary: latent factors are less likely to persist and may be influenced more by each other, allowing for a more dynamic and responsive behavior." + "text": "Interpreting Transition Matrices\nExamining the second transition matrix\n\n\n\n\n\n\nThe diagonal elements (0.5 and 0.4) are lower compared to Transition Matrix 1, suggesting less persistence of each latent factor over time.\nThe 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.\nSummary: latent factors are less likely to persist and may be influenced more by each other, allowing for a more dynamic and responsive behavior." }, { "objectID": "posts/dr-dfm-covid/presentation-post.html#factor-constraints-enhancing-model-interpretability", @@ -536,7 +536,7 @@ "href": "posts/dr-dfm-covid/presentation-post.html#factor-constraints", "title": "Covid-19 Data-Rich Dynamic Factor Model", "section": "Factor Constraints", - "text": "Factor Constraints\n\nFactor loading constraint example\n\n\n\n\n\n\n\n\n\n\n\n\nDep. variable\nGlobal.1\nPandemic\nEmployment\nConsumption\nInflation\n\n\n\n\nSupply_1\nX\n\n\n\n\n\n\nSupply_7\nX\n\n\n\n\n\n\nMonetary_5\nX\n\n\n\n\n\n\nMonetary_9\nX\n\n\n\n\n\n\nSupply_2\nX\n\nX\n\n\n\n\nSupply_3\nX\n\nX\n\n\n\n\nDemand_7\nX\n\nX\n\n\n\n\nDemand_3\nX\n\n\nX\n\n\n\nDemand_5\nX\n\n\nX\n\n\n\nMonetary_2\nX\n\n\n\nX\n\n\nMonetary_1\nX\n\n\n\nX\n\n\nPandemic_2\nX\nX\n\n\n\n\n\nPandemic_9\nX\nX" + "text": "Factor Constraints\nFactor constraint loadings example\n\n\n\n\n\n\n\n\n\n\n\nDep. variable\nGlobal.1\nPandemic\nEmployment\nConsumption\nInflation\n\n\n\n\nSupply_1\nX\n\n\n\n\n\n\nSupply_7\nX\n\n\n\n\n\n\nMonetary_5\nX\n\n\n\n\n\n\nMonetary_9\nX\n\n\n\n\n\n\nSupply_2\nX\n\nX\n\n\n\n\nSupply_3\nX\n\nX\n\n\n\n\nDemand_7\nX\n\nX\n\n\n\n\nDemand_3\nX\n\n\nX\n\n\n\nDemand_5\nX\n\n\nX\n\n\n\nMonetary_2\nX\n\n\n\nX\n\n\nMonetary_1\nX\n\n\n\nX\n\n\nPandemic_2\nX\nX\n\n\n\n\n\nPandemic_9\nX\nX" }, { "objectID": "posts/dr-dfm-covid/presentation-post.html#implementation", diff --git a/docs/temp/kingdom-death/index.html b/docs/temp/kingdom-death/index.html index b55344a..259531a 100644 --- a/docs/temp/kingdom-death/index.html +++ b/docs/temp/kingdom-death/index.html @@ -2186,11 +2186,11 @@

Summary Statistics

-
/tmp/ipykernel_2905/1245481724.py:9: DeprecationWarning:
+
/tmp/ipykernel_4035/1245481724.py:9: DeprecationWarning:
 
 `apply` is deprecated. It has been renamed to `map_elements`.
 
-/tmp/ipykernel_2905/1245481724.py:10: DeprecationWarning:
+/tmp/ipykernel_4035/1245481724.py:10: DeprecationWarning:
 
 `cumsum` is deprecated. It has been renamed to `cum_sum`.
 
@@ -2201,9 +2201,9 @@

Cumulative Dea
-
- + diff --git a/posts/dr-dfm-covid/index.qmd b/posts/dr-dfm-covid/index.qmd index 487b1c2..1bebf3e 100644 --- a/posts/dr-dfm-covid/index.qmd +++ b/posts/dr-dfm-covid/index.qmd @@ -68,7 +68,7 @@ The loading matrix is a bridge that connects the latent factors, which are unobs > Relationship between latent factors and observed variables via loading matrix ```{python} -# echo: false +#| echo: false import numpy as np import matplotlib.pyplot as plt @@ -162,7 +162,7 @@ $\eta_t$: Innovation term Examining the first transition matrix ```{python} -# echo: false +#| echo: false import numpy as np import seaborn as sns import matplotlib.pyplot as plt @@ -202,7 +202,7 @@ plt.show() Examining the second transition matrix ```{python} -# echo: false +#| echo: false import numpy as np import seaborn as sns import matplotlib.pyplot as plt @@ -247,7 +247,7 @@ By applying constraints to the model parameters, we can improve interpretability For example, setting certain elements of the loading matrix to zero might suggest that specific observed variables are not influenced by particular latent factors. ## Factor Constraints {.smaller} -> Factor loading constraint example +Factor constraint loadings example | Dep. variable | Global.1 | Pandemic | Employment | Consumption | Inflation | |-----------------|----------|----------|------------|-------------|-----------|