FMenchetti / CausalMBSTS

16 stars 0 forks source link

'mbsts.mcmc' step 1 #8

Closed FMenchetti closed 4 years ago

FMenchetti commented 4 years ago

make it sample 'states', 'eta','eps' from the same seed

izahn commented 4 years ago

Maybe fix simulateSSM upstream in https://github.com/helske/KFAS/issues

vliublinska commented 4 years ago

I've cloned the KFAS repo (https://github.com/helske/KFAS) and investigated the simulateSSM() function for a bit. Sadly, it uses a Fortran routine to actually perform simulations and that routine itself only accepts one "type" of object to simulate ("states", "signals", "disturbances", "observations", "epsilon", "eta"), so the authors would have to modify it to make it helpful for us.

That said, the Fortran routine returns an "out" object, which is a list of many things, including the simulated output. I was able to makes sure that, if we set the same seed, the components of the "out" object are identical (except, of course, for the actual simulated values for the corresponding object type). This still may not guarantee that that joint distribution between states, eta, and epsilon are preserved, but it is reassuring.

@FMenchetti, is there a mathematical connection between states, eta, and epsilon (and, perhaps, other components of SModel) that we can check after all three are simulated to make sure that the necessary relationships are preserved?

FMenchetti commented 4 years ago

Thanks Victoria! Yes, there is a connection...the states at time 't' + eta at time 't' should be equal to the states at time 't+1'. Instead, the epsilon are independent from the other two objects.

vliublinska commented 4 years ago

@FMenchetti I went back and checked this dependence. It definitely holds when we set the same seed for every step (and doesn't hold otherwise), so I think we are ok to assume that the workaround with seeds is a good option while we wait for a more permanent solution if implemented by KFAS authors in the future. I'll push the update to the repo and close the issue.

vliublinska commented 4 years ago

Fixed with the set.seed() workaround in 9a327f93a49889a1558fed5411fb85a3e1f5587c

FMenchetti commented 4 years ago

Great! Thanks Victoria!