On 17/10/14 04:23, Kevin Aagaard wrote: > > I have an OpenBUGS model that uses observed data (y.values) over time > (x.values) to simulate many runs (~100000) with new estimates of > y-values (y.est) for each run. The observed data exhibit a pronounced > decline from a maximum value. > > I want to keep track of the length of time it takes for each run to > decline from the maximum abundance (T.max) to 10% of the maximum > abundance (T.10%). Because the maximum abundance value changes from > run to run, 10% of that maximum will also vary from run to run, and > thus T.10% will vary from run to run. > > Setting a parameter to store T.max is easy enough, that doesn't vary > from run to run because the maximum value is sufficiently greater than > any other value. > > What I can't figure out, is how to store the intersection of the y-est > values and T.10%. > > My first attempt was to determine whether each y-est value is above or > below T.10% using the |step()|function: > > |above.below[i] <- step(T.10% - y.est[i]) > | > > This generates a string of ones and zeros for each y.est value (e.g., > 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, > etc.) If each run simply declined continuously from a maximum to a > minimum, I could use the |rank()| function to determine how many > |above.below[i]| values occur above T.10%: > > |decline.length <- rank(above.below[1:N], 0) > | > > In this example, |decline.length| would be equal to the number of '0's > in the string above, which is 9. Unfortunately, the y-est values > occasionally display periods of growth following their decline below > T.10%. So, the vector of |above.below| values can look like this: 0, > 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, > 0, 1, 0, 0, 1, 1, 1, 1, etc. Thus, |decline.length| would equal 14 > rather than 9, given the subsequent 0s in the vector. > > What I want to do, is figure out how to store only the number of '0's > in |above.below| prior to the first '1'; |above.below[1:10]| rather > than |above.below[1:N]|. Unfortunately, it's not always the 10th time > step in which the first '1' occurs, so I need to make the maximum > extent of the range of |above.below| vary from run to run during the > simulation. > > I'm struggling to accomplish this in OpenBUGS since it's a > non-procedural language, but I think it can be done, I just don't know > the trick to do it. I'm hoping someone more familiar with the > |step()| and |rank()|functions can lend some expert advice. > > Any guidance is much appreciated! > I think there are a few ways of doing this, so here's one that's probably not the most efficient. In the i loop do this: Dummy[i] <- above.below*i + (1-above.below)*(N+5) So the dummy equals i if above.below =1 and N+5 if above.below =0. Then you simply need min(Dummy[]), which is ranked(Dummy[],1) Bob -- Bob O'Hara Biodiversity and Climate Research Centre Senckenberganlage 25 D-60325 Frankfurt am Main, Germany Tel: +49 69 7542 1863 Mobile: +49 1515 888 5440 WWW: http://www.bik-f.de/root/index.php?page_id=219 Blog: http://blogs.nature.com/boboh Journal of Negative Results - EEB: www.jnr-eeb.org ------------------------------------------------------------------- This list is for discussion of modelling issues and the BUGS software. For help with crashes and error messages, first mail [log in to unmask] To mail the BUGS list, mail to [log in to unmask] Before mailing, please check the archive at www.jiscmail.ac.uk/lists/bugs.html Please do not mail attachments to the list. To leave the BUGS list, send LEAVE BUGS to [log in to unmask] If this fails, mail [log in to unmask], NOT the whole list