audrey-b / sims

An R package to simulate data from JAGS or R Code
https://poissonconsulting.github.io/sims/
Other
1 stars 2 forks source link

sims_simulate monitors latent variables by default but only data should be passed to analysis #16

Closed audrey-b closed 5 years ago

audrey-b commented 5 years ago

When monitor=".*" is set in sims_simulate, both the data and the latent variables are saved but only the data can be taken as input for an analysis.

Example:

sims_simulate("Y ~ dnorm(N, 1) N ~ dnorm(mu, 1) mu ~ dnorm(0, 1)")

$N [1] -0.1351718

$Y [1] -0.1492502

$mu [1] -0.1449531

an nlists object of 100 nlist objects each with 3 natomic elements

Here, only Y is data, so the output of sims_simulate cannot be analysed directly. Instead, one needs to specify monitor="Y" manually, which could get cumbersome with many data variables.

It seems that it would be better to change the default value of monitor in sims_simulate to only keep the data. Nodes that are data can be identified by the fact that they are never used on the right hand side of a ~ or <-

I suggest adding a function to sims that would take code as input and output a list of

  1. the nodes that are data,
  2. the nodes that are latent,
  3. the nodes that are parameters.

This way if for some reason someone is interested in the latent parameters, they can easily get the names of all such parameters and use them as monitor.

joethorley commented 5 years ago

How about we add an argument to sims called something like latent.

By default latent = FALSE and monitor only applies to data variables. If latent = TRUE then monitor only applies to latent variables and if latent = NA then monitor applies to both (the current behaviour)

What do you think?

audrey-b commented 5 years ago

Sounds great!

joethorley commented 5 years ago

done

joethorley commented 5 years ago

also I added stochastic = TRUE argument to control whether stochastic nodes monitored