See here: https://gist.github.com/pfistfl/6b190f0612535817bdd33fe8f8bd6548 This is needed if we want to fit on sub-populations etc.