osofr / simcausal

Simulating Longitudinal and Network Data with Causal Inference Applications
64 stars 11 forks source link

Understanding Non-standard evaluation in 0.5.1 #10

Closed bsaul closed 8 years ago

bsaul commented 8 years ago

The updates in v0.5.1 break my code, and I trying to understand why. I'm simulating a space-time structure, so I have two indexes s and t. simcausal understands a single dimension, so I map s and t to a single dimension via the function tFUN.

For each node in the DAG, I have a dataset of parameters that I lookup for s, t.

Here's a short example:

for(t in t_start:TT ){ # Per month
    for(s in s_start:SS ){ # Per location

      tpos  <- tFUN(s, t, SS)
      ## Initial month values ##

      if(s == 1 & t == 0){
       D <- D + node('L1',
               distr = 'rnorm',
               mean  = .(lookup_parameter(pp, node = 'L1', s = s, t = t, variable = '(Intercept)') ),
               sd    = .(lookup_parameter(pp, node = 'L1', s = s, t = t, variable = 'mse') ),
               t     = tpos)
 }
}

lookup_parameter basically uses [ to pick off the correct element in the dataset.

With the new updates, the values for s and t getting passed to lookup_parameter are not what I expected, and I get a One of the distribution parameters evaluated to non-standard vector error. t is the value I'd expect from simcausal rather then the value from the loop. s is a mystery altogether. The other arguments (node and variable pass to lookup_parameter correctly).

I think for my purposes (I'm trying to wrap up this study), I should just roll back to v0.5.0. I figured I would bring this up, in case there is something obvious I'm missing.

Thanks!

osofr commented 8 years ago

Hi,

Indeed, I highly recommend rolling back to 0.5.0 if you need to finish this quickly. This is quite a complex issue, and I have been struggling with how to do NSE in the right way for some time now. In version 0.5.0, anything inside .() was evaluated immediately upon calling the node() function. However, this had some undesirable consequences and starting from 0.5.1, the .() calls are evaluated only when the data is actually being simulated (i.e., when calling set.DAG() or sim() functions). Clearly this leads to incorrect interpretation of s and t, which should not be happening. I am looking into it right now.

Is it possible to provide a fully working example, with tFUN and lookup_parameter function? It will help me a great deal. Thanks!

Oleg

osofr commented 8 years ago

Would you mind trying to run your code on the most recent github commit? I've rolled back the non-standard evaluation with .() to be essentially the same as before. Please let me know if your old code works and if I can close the issue. Thanks!

bsaul commented 8 years ago

Sure thing. Will do tomorrow afternoon.

Sent from my iPhone

On Jun 1, 2016, at 20:33, Oleg Sofrygin notifications@github.com wrote:

Would you mind trying to run your code on the most recent github commit? I've rolled back the non-standard evaluation with .() to be essentially the same as before. Please let me know if your old code works and if I can close the issue. Thanks!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

bsaul commented 8 years ago

I installed v0.5.1.99 from github and everything appears to run fine. Thanks!

Do you still want me to provide a working example of the issue with version 0.5.1? I can, but won't be able to get to that till next week.

osofr commented 8 years ago

No need. Thanks for running it!