pymc-devs / pymc-examples

Examples of PyMC models, including a library of Jupyter notebooks.
https://www.pymc.io/projects/examples/en/latest/
MIT License
288 stars 248 forks source link

Conditional Autoregressive (CAR) Models for Spatial Data #405

Open conorhassan opened 2 years ago

conorhassan commented 2 years ago

Notebook proposal

Title: Conditional Autoregressive (CAR) Models for Spatial Data

Why should this notebook be added to pymc-examples?

The CAR distribution is within the multivariate distributions that PyMC supports, but there are no notebooks that offer an example.

Suggested categories:

Related notebooks

Junpeng wrote this great notebook on CAR priors, but this was pre the CAR distribution being a part of PyMC and for version 3.

OriolAbril commented 2 years ago

Is the goal to write a new notebook from scratch or to update https://www.pymc.io/projects/examples/en/latest/case_studies/conditional-autoregressive-model.html to v4?

conorhassan commented 2 years ago

Hi Oriol, I've written the notebook already. I would say it's somewhere between the two. The models and datasets used are very near similar (updated to v4). However, I would say the level is more introductory and focused on instances when you would add the random effect term within the model building process.

conorhassan commented 2 years ago

I'm trying to commit the changes locally to a branch before creating a pull request for this issue.

The pre-commit tests all pass

image

But when trying to commit the changes, I get the following error:

image

If I try and commit a second time, I get an error saying:

image

I proceed to git reset, git add, and then git checkout the myst.md file, but the error remains.

bwengals commented 2 years ago

I think when pre-commit or black or whatever else makes changes, you just need to git add and git commit the changed files it changed. git checkout I think will undo the changes pre-commit made, so if you do that and then commit again, pre-commit makes the same changes it had, putting you in a bit of a loop. Not 100% sure that's what's going on though.

After you add and commit, and pre-commit runs, take a look at git status. If anything is green, probably that myst file thing, git add and commit it again.

OriolAbril commented 2 years ago

From the codespell image, it looks like there is a typo. There is an instance of ther which is failing pre-commit and therefore preventing you to commit. Note that you can still commit by using --no-verify as shown in https://docs.pymc.io/en/latest/contributing/python_style.html#pre-commit-checks to get the PR started already before fixing this (which is not needed to open a PR, it is needed for the PR to be merged only).

Opening the PR might also help us see what is going on, otherwise it is hard to know only from the pre-commit messages posted above, we can only guess. Still, in case it helps, here is my guess:

  1. pre-commit passes. You run pre-commit on the notebook file, and both myst and ipynb files are synced so pre-commit passes. However, it only passes because you run it on the ipynb file only. I think codespell checks the myst file only, so this check is skipped.
  2. You try to commit. Now you try to commit both ipynb (passes pre-commit) and myst (has a spellcheck typo and does not) which results in a failed commit.
  3. the spellcheck pre-commit is probably making changes to the myst file too, so now the ipynb and myst files are no longer in sync. The check that used to pass no longer passed.
  4. You can run pre-commit ad eternum and it won't pass. IMPORTANT: only some of the checks are able to auto fix the files so the next time you run pre-commit after adding the modified files everything works. There are checks like the execution order one, the sphinx-cross references one or the spellcheck one in some cases that only fail pre-commit but do not (and can not) fix the issues for you.