Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CFA and SEM with PyMC #698

Merged
merged 17 commits into from
Sep 25, 2024
Merged

CFA and SEM with PyMC #698

merged 17 commits into from
Sep 25, 2024

Conversation

NathanielF
Copy link
Contributor

@NathanielF NathanielF commented Sep 1, 2024

CFA and SEM with PyMC

Related to this issue here I'm adding a PR to demonstrate the functionality of CFA and SEM models using PyMC
#695

Helpful links


📚 Documentation preview 📚: https://pymc-examples--698.org.readthedocs.build/en/698/

Signed-off-by: Nathaniel <[email protected]>
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@NathanielF NathanielF marked this pull request as ready for review September 8, 2024 16:21
@NathanielF
Copy link
Contributor Author

Think this is ready for review @drbenvincent , @cluhmann , @AlexAndorra . Any feedback/pushback welcome.

@NathanielF
Copy link
Contributor Author

Giving this another nudge!

Thanks!

@drbenvincent
Copy link
Contributor

FYI: I'm totally overloaded at the moment, so going to struggle with a review. Will see if things ease up a bit next week.

@NathanielF
Copy link
Contributor Author

No worries.

Copy link

review-notebook-app bot commented Sep 25, 2024

View / edit / reply to this conversation on ReviewNB

fonnesbeck commented on 2024-09-25T03:08:46Z
----------------------------------------------------------------

Perhaps add reference to psychometrics in the title to make it more specific, and aid in discoverability.


NathanielF commented on 2024-09-25T11:38:08Z
----------------------------------------------------------------

Good idea.

Copy link

review-notebook-app bot commented Sep 25, 2024

View / edit / reply to this conversation on ReviewNB

fonnesbeck commented on 2024-09-25T03:08:47Z
----------------------------------------------------------------

nitpick: data set should not have a hyphen; data set or dataset, no?


NathanielF commented on 2024-09-25T11:38:41Z
----------------------------------------------------------------

changed.

Copy link

review-notebook-app bot commented Sep 25, 2024

View / edit / reply to this conversation on ReviewNB

fonnesbeck commented on 2024-09-25T03:08:47Z
----------------------------------------------------------------

Maybe hyperlink SEM and CFA to some introductory materials on the topics (even a Wikipedia link would be good)


NathanielF commented on 2024-09-25T11:38:54Z
----------------------------------------------------------------

Added links to wikipedia.

Copy link

review-notebook-app bot commented Sep 25, 2024

View / edit / reply to this conversation on ReviewNB

fonnesbeck commented on 2024-09-25T03:08:48Z
----------------------------------------------------------------

There are lots of UserWarnings in the notebook. Consider filtering them out.


Copy link

review-notebook-app bot commented Sep 25, 2024

View / edit / reply to this conversation on ReviewNB

fonnesbeck commented on 2024-09-25T03:08:49Z
----------------------------------------------------------------

The last line of the equation set contains a typo -- should be \psi_n rather than \psi_3


NathanielF commented on 2024-09-25T11:39:29Z
----------------------------------------------------------------

Fixed. Thanks, good catch!

Copy link

review-notebook-app bot commented Sep 25, 2024

View / edit / reply to this conversation on ReviewNB

fonnesbeck commented on 2024-09-25T03:08:50Z
----------------------------------------------------------------

Line #29.        chol, _, _ = pm.LKJCholeskyCov("chol_cov", n=2, eta=2, sd_dist=sd_dist, compute_corr=True)

Why do you set compute_corr=True and discard the correlations?


NathanielF commented on 2024-09-25T11:40:37Z
----------------------------------------------------------------

It's not used here in this model, but useful to have computed for analysing the correlations between the constructs post model fit. I demonstrate this below for the full measurement model....

Copy link

review-notebook-app bot commented Sep 25, 2024

View / edit / reply to this conversation on ReviewNB

fonnesbeck commented on 2024-09-25T03:08:50Z
----------------------------------------------------------------

Cool plots!


NathanielF commented on 2024-09-25T11:45:43Z
----------------------------------------------------------------

Thanks!

Copy link

review-notebook-app bot commented Sep 25, 2024

View / edit / reply to this conversation on ReviewNB

fonnesbeck commented on 2024-09-25T03:08:51Z
----------------------------------------------------------------

Line #81.            draws=10000,

Why so many draws? Bad autocorrelation?


NathanielF commented on 2024-09-25T11:42:40Z
----------------------------------------------------------------

Yes, it seemed to help generally boost the ESS. The model samples pretty fast so it was easy enough to just boost the samples.

Copy link

review-notebook-app bot commented Sep 25, 2024

View / edit / reply to this conversation on ReviewNB

fonnesbeck commented on 2024-09-25T03:08:52Z
----------------------------------------------------------------

typo: reflected


NathanielF commented on 2024-09-25T11:42:50Z
----------------------------------------------------------------

Fixed.

Copy link

review-notebook-app bot commented Sep 25, 2024

View / edit / reply to this conversation on ReviewNB

fonnesbeck commented on 2024-09-25T03:08:53Z
----------------------------------------------------------------

typo in first sentence: individual


NathanielF commented on 2024-09-25T11:42:59Z
----------------------------------------------------------------

Fixed.

Copy link

review-notebook-app bot commented Sep 25, 2024

View / edit / reply to this conversation on ReviewNB

fonnesbeck commented on 2024-09-25T03:08:53Z
----------------------------------------------------------------

Typo: each


NathanielF commented on 2024-09-25T11:43:11Z
----------------------------------------------------------------

Fixed

Copy link

review-notebook-app bot commented Sep 25, 2024

View / edit / reply to this conversation on ReviewNB

fonnesbeck commented on 2024-09-25T03:08:54Z
----------------------------------------------------------------

What about measures of relative fit among the models? What do the LOO/WAIC values look like, and are they helpful in selecting the appropriate level of complexity?


NathanielF commented on 2024-09-25T11:45:26Z
----------------------------------------------------------------

Added the global fit comparison for the SEM and full measurement models. The LOO metrics are quite close, but the full measurement model "wins" on this score. I added a note to say we need to consider the value of the trade-off between expressive power of the SEMs and the questions we can answer in the context of simple global fit comparisons.

Copy link
Contributor Author

Good idea.


View entire conversation on ReviewNB

Copy link
Contributor Author

changed.


View entire conversation on ReviewNB

Copy link
Contributor Author

Added links to wikipedia.


View entire conversation on ReviewNB

Copy link
Contributor Author

Fixed. Thanks, good catch!


View entire conversation on ReviewNB

Copy link
Contributor Author

It's not used here in this model, but useful to have computed for analysing the correlations between the constructs post model fit. I demonstrate this below for the full measurement model....


View entire conversation on ReviewNB

Copy link
Contributor Author

Yes, it seemed to help generally boost the ESS. The model samples pretty fast so it was easy enough to just boost the samples.


View entire conversation on ReviewNB

Copy link
Contributor Author

Fixed.


View entire conversation on ReviewNB

Copy link
Contributor Author

Fixed.


View entire conversation on ReviewNB

Copy link
Contributor Author

Fixed


View entire conversation on ReviewNB

Copy link
Contributor Author

Added the global fit comparison for the SEM and full measurement models. The LOO metrics are quite close, but the full measurement model "wins" on this score. I added a note to say we need to consider the value of the trade-off between expressive power of the SEMs and the questions we can answer in the context of simple global fit comparisons.


View entire conversation on ReviewNB

Copy link
Contributor Author

Thanks!


View entire conversation on ReviewNB

@NathanielF
Copy link
Contributor Author

Thanks @fonnesbeck I think i've addressed most of the points you raised. But let me know if you think I should add anything else.

Note I also re-parameterised the tau terms in the final SEM model which seemed to fix the divergences i was getting.

@fonnesbeck fonnesbeck self-requested a review September 25, 2024 13:40
Copy link
Member

@fonnesbeck fonnesbeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@NathanielF
Copy link
Contributor Author

Sweet!

@NathanielF
Copy link
Contributor Author

Think you'll have to merge that for me @fonnesbeck, i don't have that power.

@fonnesbeck fonnesbeck merged commit ba7a936 into pymc-devs:main Sep 25, 2024
2 checks passed
@NathanielF
Copy link
Contributor Author

Woo! Thanks @fonnesbeck

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants