<div dir="ltr">Thanks for the replies.<div><br></div><div>Dave -- </div><div><br></div><div>We model the bearings using a von Mises distribution. We expect the animal to keep on goin' in the same direction it did for the last point in time, and then estimate the concentration parameter of the von Mises distribution, which tells us how much it likes to deviate from this. So the bearings go into the von Mises density function.</div>
<div><br></div><div>Johnoel -- Great, thanks!</div><div><br></div><div>Cheers,</div><div><br></div><div>Ben</div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On 17 October 2013 01:44, Johnoel Ancheta <span dir="ltr"><<a href="mailto:johnoel@hawaii.edu" target="_blank">johnoel@hawaii.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thank you Ben for spotting the error. It have been corrected in revision 1232 of the ADMB <div>subversion repository.</div>
<span class="HOEnZb"><font color="#888888"><div><br></div><div>Johnoel</div></font></span></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div class="h5">
On Wed, Oct 16, 2013 at 10:34 AM, Ben Stevenson <span dir="ltr"><<a href="mailto:bcs5@st-andrews.ac.uk" target="_blank">bcs5@st-andrews.ac.uk</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div class="h5">
<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:13px">Hi ADMBers,</span><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">A couple of points:</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">1)</div><div style="font-family:arial,sans-serif;font-size:13px">I have discovered that the function asin does not work with df1b2variables, despite appearing in src/df1b2separable/df1b2f26. I am not very familiar with the ADMB source code (or with C++ for that matter), but I added asin to df1b2fun.h, rebuilt the source and everything worked fine. Assuming I did the right thing, could someone with write access make the same change to the subversion repo? Note that atan does appear but acos does not.</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">2) </div><div style="font-family:arial,sans-serif;font-size:13px">My reason for using asin was to calculate a bearing between two locations, which are being treated as latent variables (and so modelled with a random_effects_matrix). The model is an animal movement model, and it is necessary to work out the direction the animal moved in from one time point to the next. The problem for me was that the range of the function asin is (-pi, pi) and obviously the range of the directions an animal can move is (0, 2*pi). So it was necessary to translate from the first to the second, but this depends on what quadrant the bearing belongs to (i.e., if the animal moved northeast, southeast, southwest, or northwest). This is because for each value returned in (-pi, pi) by asin, there are two possible bearings in (0, 2*pi) that this could correspond to.<br>
</div><div style="font-family:arial,sans-serif;font-size:13px"><div><br></div><div>"x_diff" and "y_diff" are the differences between the current and previous x and y-coordinates, and "dist" is the distance between the current and previous locations. I wanted to write something like:</div>
<div>bearing = asin(x_diff/dist)</div><div>if (southeast) bearing += M_PI - 2*bearing;</div><div>if (southwest) bearing += M_PI - 2*bearing;</div><div>if (northwest) bearing += 2*M_PI;</div><div><br></div><div>But this would break all sorts of ADMB rules with the if statements.</div>
<div><br></div><div>In the end, I got around the problem by first emulating the performance of R's sign() function (is there a way to do this in ADMB already??):</div><div>sign_x_diff = x_diff/fabs(x_diff);</div><div>
sign_y_diff = y_diff/fabs(y_diff);</div><div><br></div><div>And then creating some dummy variables that indicated the animal's direction:</div><div>se_dummy = (sign_x_diff - sign_y_diff)*(sign_x_diff + square(sign_y_diff))/4;<br>
</div><div>nw_dummy = (sign_y_diff - sign_x_diff)*(sign_y_diff + square(sign_x_diff))/4;</div><div>sw_dummy = (-sign_x_diff - sign_y_diff)*(square(sign_x_diff) - sign_y_diff)/4;<br></div><div><br></div><div>Before using these instead of the if statements above to make the correct adjustments to what was returned by asin:</div>
<div><div>bearing = asin(x_diff/dist);</div><div>bearing += se_dummy*M_PI - 2*bearing);</div><div>bearing += nw_dummy*2.0*M_PI;</div><div>bearing += sw_dummy*(M_PI - 2*bearing);</div></div><div><br></div><div>Everything worked fine once I did all this, but it was quite a big procedure to do something quite simple, and I was wondering if I was missing an obvious solution I could use in future instead of the mess that I've tried to explain above.</div>
<div><br></div><div>Thanks in advance,</div><div><br></div><div>Ben</div></div></div>
<br></div></div><div class="im">_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@admb-project.org" target="_blank">Users@admb-project.org</a><br>
<a href="http://lists.admb-project.org/mailman/listinfo/users" target="_blank">http://lists.admb-project.org/mailman/listinfo/users</a><br>
<br></div></blockquote></div><br></div>
</blockquote></div><br></div></div></div>