|
61 | 61 | " - Each step asks: Does this addition honor theory? Improve fit?\n", |
62 | 62 | " - Workflow = constant negotiation between parsimony and fidelity.\n", |
63 | 63 | "\n", |
64 | | - "These approaches complement one another. We'll see how the iterative and expansionary approach to model development are crucial for understanding the subtleties of these models. Understanding their implications and arriving at a decisions about what to with those implications. " |
| 64 | + "These approaches complement one another. We'll see how the iterative and expansionary approach to model development is crucial for understanding the subtleties of SEM models. How our understanding grows as we track their implications across increasingly expressive candidate structures." |
65 | 65 | ] |
66 | 66 | }, |
67 | 67 | { |
|
349 | 349 | "id": "b2a81043", |
350 | 350 | "metadata": {}, |
351 | 351 | "source": [ |
352 | | - "Conveniently, the process of the Bayesian workflow itself involves the constructive thought strategies. At each juncture in model development we must ask ourselves: do i believe this? What assumptions have I made? Is there any visual evidence that my model is well specified? What can i do to improve the model specification? So we might hope that the end result of the Bayesian workflow is a general sense of satisfaction with a job well done!" |
| 352 | + "Conveniently, the process of the Bayesian workflow itself involves the constructive thought strategies. At each juncture in model development we must ask ourselves: do i believe this? What assumptions have I made? Is there any visual evidence that my model is well specified? What can i do to improve the model specification? You will see that the end result of the Bayesian workflow is a robust, defensible array of findings. These findings have been derived with care and craft. The process, as the data suggests, leads to sense of satisfaction with a job well done! " |
353 | 353 | ] |
354 | 354 | }, |
355 | 355 | { |
|
359 | 359 | "source": [ |
360 | 360 | "## Mathematical Interlude\n", |
361 | 361 | "\n", |
362 | | - "In the general set up of a Structural Equation Model we have observed variables $y \\in R^{p}$, here (p=12) and $\\eta \\in R^{m}$ latent factors. The basic SEM consists of two parts - the measurement model and the structural regressions. _The Measurement Model_ is the factor-structure we seek to _confirm_ in our analysis. It is called a measurement model because we view the observable metrics as indicators of the thing we actually want to measure. The observable metrics are grouped under \"a factor\" or construct, based on the idea that each of the indicators are imprecise gauges of the latent factor. The hope is that collectively they provide a better gauge of this hard to measure quantity e.g. satisfaction and well-being. In this kind of factor analysis we posit a factor-structure and estimate how each latent factor determines the observed metrics. \n", |
| 362 | + "In our set up of a Structural Equation Model we have observed variables $y \\in R^{p}$, here (p=12) and $\\eta \\in R^{m}$ latent factors (m=4). The basic structural equation model (SEM) consists of two parts - the measurement model and the structural regressions. \n", |
| 363 | + "\n", |
| 364 | + "_The Measurement Model_ is the factor-structure we seek to _confirm_ in our analysis. It is called a measurement model because we view the observable metrics as indicators of the thing we actually want to measure. The observable metrics are grouped under a unifying \"factor\" or construct. The idea that each of the indicators are imprecise gauges of the latent factor. The hope is that collectively they provide a better gauge of this hard to measure quantity e.g. satisfaction and well-being. This can be thought of as a data-reduction technique, where we reduce the complex multivariate data set to a smaller collection of inferred features. However, in most SEM applications the factors themselves are of independent interest, not merely a modelling convenience.\n", |
| 365 | + "\n", |
| 366 | + "In factor analysis we posit a factor-structure and estimate how each latent factor determines the observed metrics. The assumed data generating structure says that the factors cause the observed metrics.The inferential task works backwards, we want to infer the shape of the latent factors conditional on the observed metrics.\n", |
363 | 367 | "\n", |
364 | 368 | "$$ \\overbrace{y_i}^{indicators} = \\overbrace{\\Lambda \\eta_i}^{factors} + \\varepsilon_i, \n", |
365 | 369 | "\\quad \\varepsilon_i \\sim \\mathcal N(0, \\Psi).\n", |
366 | 370 | "$$\n", |
367 | 371 | "\n", |
368 | 372 | "where $\\Lambda$ is a 12 x 4 matrix, and $\\eta$ is an $N$ x 4 matrix, for $N$ observations i.e. the matrix of latent scores on each of the four factors for all individual responses. In the measurement model we're aiming to ensure that the observed metrics are well grouped under a single factor. That they \"move\" well together and respond to changes in the factor. \n", |
369 | 373 | "\n", |
370 | | - "On the other hand _the Structural model_ encodes the regression paths between the latent constructs. Mathematically this is achieved within a 4 X 4 matrix B, where the latent factors are specified as predictors of other latent factors as theory dictates i.e no latent factor predicts itself, but some may bear on others. In our case we're aiming to see how constructive thought strategies predicts job satisfaction as mediated through the other factors. \n", |
| 374 | + "_The Structural model_ encodes the regression paths between the latent constructs. Mathematically this is achieved within a 4 X 4 matrix $B$, where the latent factors are specified as predictors of other latent factors as theory dictates i.e no latent factor predicts itself, but some may bear on others. In our case we're aiming to see how constructive thought strategies predicts job satisfaction. The influence paths of one factor on another can be direct and mediated through the other factors. \n", |
371 | 375 | "\n", |
372 | 376 | "$$\n", |
373 | 377 | "\\eta_i = B \\eta_i + \\zeta_i, \n", |
|
399 | 403 | "\n", |
400 | 404 | "$$\n", |
401 | 405 | "\n", |
402 | | - "so that \n", |
403 | | - "\n", |
404 | | - "$$ p(y_i, \\zeta_i) = \n", |
405 | | - "\\mathcal N\\!\\left(\\zeta_i; 0, \\Psi_{\\zeta}\\right) \\cdot\n", |
406 | | - "\\mathcal N\\!\\left(y_i;\\; \\Lambda (I-B)^{-1}\\zeta_i, \\; \\Psi\\right).\n", |
407 | | - "$$\n", |
408 | | - "\n", |
409 | 406 | "which is just to highlight that the conditional formulation samples the latent variables explicitly, which can be quite demanding for a sampler in the Bayesian setting. \n", |
410 | 407 | "\n", |
411 | 408 | "### Marginal Formulation\n", |
|
644 | 641 | "source": [ |
645 | 642 | "## Confirming Factor Structure\n", |
646 | 643 | "\n", |
647 | | - "First we'll highlight the broad structure of a confirmatory factor model and the types of relations the model encodes. The red dotted arrows here denote covariance relationships among the latent factors. The black arrows denote the effect of the latent constructs on the observable indicator metrics. We've highlighted with red [1] that the first \"factor loading\" is always fixed to (a) define the scale of the factor and (b) allow identification of the other factor loadings within that factor. \n", |
| 644 | + "First we'll highlight the broad structure of a confirmatory factor model and the types of relations the model encodes. The red dotted arrows here denote covariance relationships among the latent factors. The black arrows denote the effect of the latent constructs on the observable indicator metrics. We've highlighted with red [1] that the first \"factor loading\" is always fixed to 1, so to (a) define the scale of the factor and (b) allow identification of the other factor loadings within that factor. \n", |
648 | 645 | "\n", |
649 | 646 | "\n", |
650 | 647 | "\n", |
651 | | - "In the model below we sample draws from the latent factors `eta` and relate them to the observables by the matrix computation `pt.dot(eta, Lambda.T)`. This computation reults in a \"psuedo-observation\" matrix which we then feed through our likelihood to calibrate the latent structures against the observed dats. This is the general pattern we'll see in all models below. " |
| 648 | + "In the model below we sample draws from the latent factors `eta` and relate them to the observables by the matrix computation `pt.dot(eta, Lambda.T)`. This computation reults in a \"psuedo-observation\" matrix which we then feed through our likelihood to calibrate the latent structures against the observed dats. This is the general pattern we'll see in all models below. The covariances (i.e. red arrows) among the latent factors is determined with `chol`." |
652 | 649 | ] |
653 | 650 | }, |
654 | 651 | { |
|
975 | 972 | "source": [ |
976 | 973 | "The model diagram should emphasise how the sampling of the latent structure is fed-forward into the ultimate likelihood term. Note here how our likelihood term is specified as a independent Normals. This is a substantive assumption which is later revised. In a full SEM specification we will change the likelihood to use Multivariate normal distribution with specific covariance structures. \n", |
977 | 974 | "\n", |
978 | | - "In Lavaan notation this is the model we are aiming at: \n", |
| 975 | + "In Lavaan notation this is the model we are aiming at:\n", |
979 | 976 | "\n", |
980 | 977 | "```\n", |
981 | 978 | "# measurement part\n", |
|
985 | 982 | "JS =~ JW1 + JW2 + JW3\n", |
986 | 983 | "\n", |
987 | 984 | "```\n", |
988 | | - "Our first focus will be adding the measurment part i.e. the simple factor structure." |
| 985 | + "Where the `=~` symbol denotes the \"is measured by\" relation. Now we fit the model, to sample from the prior, condition on the likelihood and derive the posterior estimates for the model parameters. " |
989 | 986 | ] |
990 | 987 | }, |
991 | 988 | { |
|
1075 | 1072 | "source": [ |
1076 | 1073 | "#### A Sampled Lambda Matrix\n", |
1077 | 1074 | "\n", |
1078 | | - "Note how each factor records three positive parameters, while the first of each parameters is fixed to 1. This is to ensure that the scale of the latent factor is well defined, indexed as it were to one of the observed metrics." |
| 1075 | + "Let's inspect a sampled $\\Lambda$ parameter. Note how each factor (column index) records three positive parameters, while the first of each parameters is fixed to 1. This is to ensure that the scale of the latent factor is well defined - indexed in magnitude to one of the observed metrics." |
1079 | 1076 | ] |
1080 | 1077 | }, |
1081 | 1078 | { |
|
1528 | 1525 | "source": [ |
1529 | 1526 | "### Model Diagnostics and Assessment\n", |
1530 | 1527 | "\n", |
1531 | | - "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. The difference between the spread of the prior and tightness of the posterior says something of what the model has learned through the process of Bayesian updating. Here both the prior and posterior are centred on 0, and so the learnings can appear \"undramatic\", but it is often sensible to standardise and scale the the variables before fitting the model. This makes it easier to learn the factor-structure without having to worry about the mean structure since all variables are transformed to centre on 0. " |
| 1528 | + "The next series of plots are aimed at checking whether the sampler has sufficiently explored the parameter space. \n", |
| 1529 | + "The difference between the spread of the prior and tightness of the posterior says something of what the model has learned through the process of Bayesian updating. Here both the prior and posterior are centred on 0, and so the learnings can appear \"undramatic\", but it is often sensible to standardise and scale the the variables before fitting the model. This makes it easier to learn the factor-structure without having to worry about the mean structure since all variables are transformed to centre on 0. " |
1532 | 1530 | ] |
1533 | 1531 | }, |
1534 | 1532 | { |
|
1693 | 1691 | "source": [ |
1694 | 1692 | "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", |
1695 | 1693 | "\n", |
1696 | | - "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. " |
| 1694 | + "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. \n", |
| 1695 | + "\n", |
| 1696 | + "Below these model checks we will now plot some diagnostics for the sampler. The energy plots should show overlapping distributions and the effective sample size should hopefully be high across the slew of focal parameters." |
1697 | 1697 | ] |
1698 | 1698 | }, |
1699 | 1699 | { |
|
1737 | 1737 | "source": [ |
1738 | 1738 | "## Structuring the Latent Relations\n", |
1739 | 1739 | "\n", |
1740 | | - "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", |
| 1740 | + "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. This is key argument implict in SEM design. Bollen argues as follows:\n", |
1741 | 1741 | "\n", |
1742 | 1742 | "> 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", |
1743 | 1743 | "\n", |
|
1753 | 1753 | "source": [ |
1754 | 1754 | "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", |
1755 | 1755 | "\n", |
1756 | | - "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. In Lavaan syntax the model we want to specify is: \n", |
| 1756 | + "It is a substantive imposition of theory as you impose the various arrows you want to add to your system. You are making claims of causal influence. Arrows should be added in line with plausible theory, while parameter identification is well supported. 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. In Lavaan syntax the model we want to specify is: \n", |
1757 | 1757 | "\n", |
1758 | 1758 | "```\n", |
1759 | 1759 | "# measurement part\n", |
|
1767 | 1767 | "SWB ~ CTS + DTP\n", |
1768 | 1768 | "JS ~ CTS + DTP + SWB \n", |
1769 | 1769 | "\n", |
1770 | | - "```\n" |
| 1770 | + "```\n", |
| 1771 | + "\n", |
| 1772 | + "where the `~` denotes a regression relationship. " |
1771 | 1773 | ] |
1772 | 1774 | }, |
1773 | 1775 | { |
|
2155 | 2157 | "id": "19b49daf", |
2156 | 2158 | "metadata": {}, |
2157 | 2159 | "source": [ |
2158 | | - "We have also added the covariance structure on the residuals by supplying a multivariate normal likelihood with a diagonal covariance structure." |
| 2160 | + "We have also added the covariance structure on the residuals by supplying a multivariate normal likelihood with a diagonal covariance structure. This is akin to the independent normals we saw in the CFA model, but hints at the extra structure we can (and will) impose on the residuals." |
2159 | 2161 | ] |
2160 | 2162 | }, |
2161 | 2163 | { |
|
2246 | 2248 | "source": [ |
2247 | 2249 | "#### A Sampled B Matrix\n", |
2248 | 2250 | "\n", |
2249 | | - "Now we can sample the B matrix and observe is structure. It's best to see the matrix as encoding target variables in the columns and predictor variables inn the rows. Here we have the set up our matrix so that `satisfaction` is predicted by three variables, but not itself. The values in the first column are sampled coefficient values in the regression: \n", |
| 2251 | + "Now we can sample the B matrix and observe is structure. \n", |
| 2252 | + "\n", |
| 2253 | + "It's best to see the matrix as encoding target variables in the columns and predictor variables inn the rows. Here we have the set up our matrix so that `satisfaction` is predicted by three variables, but not itself. The values in the first column are sampled coefficient values in the regression: \n", |
2250 | 2254 | "\n", |
2251 | 2255 | "$$ \\eta_{sat} \\sim B_{1, 0}\\eta_{well} + B_{2, 0}\\eta_{dys} + B_{3, 0}\\eta_{con}$$\n", |
2252 | 2256 | "\n", |
|
2675 | 2679 | "id": "c69afd2c", |
2676 | 2680 | "metadata": {}, |
2677 | 2681 | "source": [ |
2678 | | - "This compact representation of three separate regressions equations is used to artificially sort out the mutual influences, interactions and distortion our habits have on our job satisfaction. The relationships between these latent constructs need not be simplistic just because we are using a regresssion framework. There may be messy non-linear relationships between satisfaction and well being, but we are a deliberately abstracting some of that away in favour of a tractable, quantifiable measure of effect. " |
| 2682 | + "This compact representation of three separate regressions equations is used to sort out the mutual influences, interactions and distortion our habits of thought have on our job satisfaction. It's true that the relationships between these latent constructs need not be linear and simplistic. There may be messy non-linear relationships between satisfaction and well being, but we are a deliberately abstracting some of that away in favour of a tractable, quantifiable measure of linear effect. This is often a simplification, but parsimony is also a goal of the modelling process. " |
2679 | 2683 | ] |
2680 | 2684 | }, |
2681 | 2685 | { |
|
2685 | 2689 | "source": [ |
2686 | 2690 | "### Model Diagnostics and Assessment\n", |
2687 | 2691 | "\n", |
2688 | | - "The posterior predictive distributions retain a healthy appearence, the prior allowed for a wide-realisation of values and the posterior has a shrunk the range considerable closer to the standardised 0-mean data. " |
| 2692 | + "Let's examine our model sense checks. The posterior predictive distributions retain a healthy appearence, the prior allowed for a wide-realisation of values and the posterior has a shrunk the range considerable closer to the standardised 0-mean data. " |
2689 | 2693 | ] |
2690 | 2694 | }, |
2691 | 2695 | { |
|
2719 | 2723 | "id": "65c01167", |
2720 | 2724 | "metadata": {}, |
2721 | 2725 | "source": [ |
2722 | | - "The modelling shows improvement 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. " |
| 2726 | + "The derived covariance structures show improvement 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. " |
2723 | 2727 | ] |
2724 | 2728 | }, |
2725 | 2729 | { |
|
0 commit comments