cbreto / panelPomp

R package for statistical inference using panelPOMPs (panel Partially Observed Markov Processes)
11 stars 6 forks source link

Unit-specific random walk standard deviations #53

Open jeswheel opened 3 months ago

jeswheel commented 3 months ago

A potentially nice feature that could be added is functionality that facilitates unit-specific random walk standard deviations. It currently appears possible because the mif2 function can accepts lists as inputs to rw.sd, however this is hardly convenient. For instance, I think one could specify:

 mif2(
    ..., 
    rw.sd = list(
       rw_sd(tau = 0.02, kappa = 0.02), 
       rw_sd(tau = 0.02, kappa = 0.02), 
       rw_sd(tau = 0.01, kappa = 0.02, beta = 0.01)
   )

In this example, the random walk standard deviation is 0.02 for all parameters and units except for unit 3, which has specific standard deviations for tau and beta. While this is possible, it can be tedious if there are many units and a user would like additional control. More frequently, we just specify a single call to rw_sd and the mif2.internal function will convert it to a list on our behalf (if it isn't already a list).

It would be nice to have the option of doing something like this instead:

mif2(
   ..., 
   rw.sd = rw_sd(tau = 0.02, kappa = 0.02, `tau[unit3]` = 0.01, `beta[unit3]` = 0.01)
)

This would give the same rw-sd specification as before: if a parameter is mentioned without a corresponding unit, then this parameter becomes the value of all unit-specific parameters that share the same name. However, this can be over-written by being more explicit.

This change would likely be implemented in R/mif2.R, in the mif2.internal function. In the 5th line of code in this function, it takes the input rw.sd and turns it into a list (if it isn't already one), just replicating things. Prior to this line of code, some logic can be implemented that would check if there are any unit-specific parameters present (indicated by the brackets). It may not be too difficult to implement this, but I haven't had this need yet so I'm leaving this suggestion as an issue to work on later.

kingaa commented 3 months ago

Seems workable....