|
1545 | 1545 | "source": [
|
1546 | 1546 | "### Model Diagnostics and Assessment\n",
|
1547 | 1547 | "\n",
|
1548 |
| - "For each latent variable (satisfaction, well being, constructive, dysfunctional), we will plot a forest/ridge plot of the posterior distributions of their factor scores `eta` as drawn. Each panel will have a vertical reference line at 0 (since latent scores are typically centered/scaled).These panels visualize the distribution of estimated latent scores across individuals, separated by latent factor. Then we will summarizes posterior estimates of model parameters (factor loadings, regression coefficients, variances, etc.), providing a quick check against identification constraints (like fixed loadings) and effect directions. Finally we will plot the upper-triangle of the residual correlation matrix with a blue–white–red colormap (−1 to +1). This visualizes residual correlations among observed indicators after the SEM structure is accounted for — helping detect model misfit or unexplained associations." |
| 1548 | + "For each latent variable (satisfaction, well being, constructive, dysfunctional), we will plot a forest/ridge plot of the posterior distributions of their factor scores `eta` as drawn. Each panel will have a vertical reference line at 0 (since latent scores are typically centered/scaled).These panels visualize the distribution of estimated latent scores across individuals, separated by latent factor. Then we will summarizes posterior estimates of model parameters (factor loadings, regression coefficients, variances, etc.), providing a quick check against identification constraints (like fixed loadings) and effect directions. Finally we will plot the upper-triangle of the residual correlation matrix with a blue–white–red colormap (−1 to +1). This visualizes residual correlations among observed indicators after the SEM structure is accounted for — helping detect model misfit or unexplained associations.\n", |
| 1549 | + "\n", |
| 1550 | + "Below these model checks we will plot some diagnostics for the sampler. These plots are aimed at checking whether the sampler has sufficiently explored the parameter space. " |
1549 | 1551 | ]
|
1550 | 1552 | },
|
1551 | 1553 | {
|
|
1710 | 1712 | "plot_diagnostics(idata_cfa_model_v1, parameters);"
|
1711 | 1713 | ]
|
1712 | 1714 | },
|
| 1715 | + { |
| 1716 | + "cell_type": "markdown", |
| 1717 | + "id": "3b5c7ecb", |
| 1718 | + "metadata": {}, |
| 1719 | + "source": [ |
| 1720 | + "These plots indicate a fairly promising modelling strategy. The estimated factor Loadings are all close to 1 which implies a conformity in the magnitude and scale of the indicator metrics within each of the four factors.The indicator(s) are strongly reflective of the latent factor although `UF1` and `FOR` seem to be moving in opposite directions. We will want to address this later when we specify covariance structures for the residuals. \n", |
| 1721 | + "\n", |
| 1722 | + "The Posterior Predictive Residuals are close to 0 which suggests that model is well able to capture the latent covariance structure of the observed data. The latent factors move together in intuitive ways, with high Satisfaction ~~ high Well Being. The sampler diagnostics give no indication of trouble. This is a promising start. " |
| 1723 | + ] |
| 1724 | + }, |
1713 | 1725 | {
|
1714 | 1726 | "cell_type": "markdown",
|
1715 | 1727 | "id": "a5538546",
|
1716 | 1728 | "metadata": {},
|
1717 | 1729 | "source": [
|
1718 | 1730 | "## Structuring the Latent Relations\n",
|
1719 | 1731 | "\n",
|
| 1732 | + "The next expansionary move in SEM modelling is to consider the relations between the latent constructs. These are generally intended to have a causal interpretation. The constructs are hard to measure precisely, but collectively as a function of multiple indicator variables, we argue they are exhaustively characterised. \n", |
| 1733 | + "\n", |
| 1734 | + "> As I have just explained, we cannot isolate a dependent variable from all influences but a single explanatory variable, so it is impossible to make definitive statements about causes. We replace perfect isolation with pseudo-isolation by assuming that the disturbance (i.e., the composite of all omitted determinants) is uncorrelated with the exogenous variables of an equation. - Bollen in _Structural Equations with Latent Variables_ pg45\n", |
| 1735 | + "\n", |
| 1736 | + "This is a claim of conditional independence which licenses the causal interpretation of the the arrows in the below plot. The fact that the latent relations operate a higher level of abstraction makes it easier to postulate these \"clean\" direct paths between constructs. The model makes an argument - to have proprely measured the latent constructs, and isolated their variation to support a causal claim. Criticisms of the model proceed by assessing how compelling these postulates are in the context of the fitted model.\n", |
| 1737 | + "\n", |
1720 | 1738 | ""
|
1721 | 1739 | ]
|
1722 | 1740 | },
|
| 1741 | + { |
| 1742 | + "cell_type": "markdown", |
| 1743 | + "id": "544e9848", |
| 1744 | + "metadata": {}, |
| 1745 | + "source": [ |
| 1746 | + "The isolation or conditional independence of interest is encoded in the model with the sampling of the `gamma` variable. These are drawn from a process that is structuraly divorced from the influence of the exogenous variables. For instance if we have $\\gamma_{cts} \\perp\\!\\!\\!\\perp \\eta_{dtp}$ then the $\\beta_{cts -> dpt}$ coefficient is an unbiased estimate of the direct effect of `CTS` on `DTP` because the remaining variation in $\\eta_{dtp}$ is noise by construction. \n", |
| 1747 | + "\n", |
| 1748 | + "It is entirely optional how many arrows you want to add to your system. In our case we have structured the DAG following the discussion in {cite:p}`vehkalahti2019multivariate` which will allow us to unpick the direct and indirect effects below. " |
| 1749 | + ] |
| 1750 | + }, |
1723 | 1751 | {
|
1724 | 1752 | "cell_type": "code",
|
1725 |
| - "execution_count": 12, |
| 1753 | + "execution_count": null, |
1726 | 1754 | "id": "8b0738c0",
|
1727 | 1755 | "metadata": {},
|
1728 | 1756 | "outputs": [
|
|
2135 | 2163 | "\n",
|
2136 | 2164 | " B = make_B()\n",
|
2137 | 2165 | " I = pt.eye(latent_dim)\n",
|
| 2166 | + " ## Clean Causal Influence of Shocks\n", |
2138 | 2167 | " eta = pm.Deterministic(\n",
|
2139 | 2168 | " \"eta\", pt.slinalg.solve(I - B + 1e-8 * I, gamma.T).T, dims=(\"obs\", \"latent\")\n",
|
2140 | 2169 | " )\n",
|
2141 |
| - "\n", |
| 2170 | + " ## Influence of Exogenous indicator variables\n", |
2142 | 2171 | " mu = pt.dot(eta, Lambda.T)\n",
|
2143 | 2172 | "\n",
|
2144 | 2173 | " ## Error Terms\n",
|
|
2148 | 2177 | "pm.model_to_graphviz(sem_model_v1)"
|
2149 | 2178 | ]
|
2150 | 2179 | },
|
| 2180 | + { |
| 2181 | + "cell_type": "markdown", |
| 2182 | + "id": "19b49daf", |
| 2183 | + "metadata": {}, |
| 2184 | + "source": [ |
| 2185 | + "We have also added the covariance structure on the residuals by supplying a multivariate normal likelihood with a precise covariance structure to add a correlation among the `UF1` and `FOR` indicators metrics. " |
| 2186 | + ] |
| 2187 | + }, |
2151 | 2188 | {
|
2152 | 2189 | "cell_type": "code",
|
2153 | 2190 | "execution_count": 13,
|
|
2660 | 2697 | "id": "c469d2a9",
|
2661 | 2698 | "metadata": {},
|
2662 | 2699 | "source": [
|
2663 |
| - "### Model Diagnostics and Assessment" |
| 2700 | + "### Model Diagnostics and Assessment\n", |
| 2701 | + "\n", |
| 2702 | + "The modelling shows improvement in the posterior predictive checks on the model implied residuals. Additionally we now get insight into the implied paths and relationships between the latent constructs. These move in compelling ways. Dysfunctional thought processes have a probable negative impact on well being, and similarly for job satisfaction. Conversely constructive thought processes have a probable positive direct effect on well being and satisfaction. Although the latter appears slight. " |
2664 | 2703 | ]
|
2665 | 2704 | },
|
2666 | 2705 | {
|
|
2690 | 2729 | "plot_model_highlights(idata_sem_model_v1, \"SEM\", parameters, sem=True);"
|
2691 | 2730 | ]
|
2692 | 2731 | },
|
| 2732 | + { |
| 2733 | + "cell_type": "markdown", |
| 2734 | + "id": "f1b1795d", |
| 2735 | + "metadata": {}, |
| 2736 | + "source": [ |
| 2737 | + "However, the model diagnostics appear less robust. The sampler seemed to have difficulty with sampling the parameters for the path-coefficients `mu_betas`. " |
| 2738 | + ] |
| 2739 | + }, |
2693 | 2740 | {
|
2694 | 2741 | "cell_type": "code",
|
2695 | 2742 | "execution_count": 16,
|
|
0 commit comments