I think what JC is hinting at is, that the median optimizes an L1 loss function. So a variant of the code can work. For example:<br><br><a href="http://stats.stackexchange.com/questions/34613/l1-regression-estimates-median-whereas-l2-regression-estimates-mean">http://stats.stackexchange.com/questions/34613/l1-regression-estimates-median-whereas-l2-regression-estimates-mean</a><br>
<br><br>That means by optimising the sum of the absolute values of the observations minus a parameter which estimate is going to be the median you can obtain the median. This is is many situations computationally less intensive than sorting.<br>
<br>Best, Philipp<br><br><br><div class="gmail_quote">On Fri, Nov 30, 2012 at 4:21 AM, JC Quiroz <span dir="ltr"><<a href="mailto:juancarlos.quiroz@ifop.cl" target="_blank">juancarlos.quiroz@ifop.cl</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:10pt;font-family:Verdana"><font face="Verdana">Maybe this will help</font><div style="font-size:10pt;font-family:Verdana">
<br></div><div style="font-size:10pt;font-family:Verdana"># ******** dat file</div><div><div><font face="Verdana"># n</font></div><div><font face="Verdana">10</font></div><div><font face="Verdana"># y</font></div><div><font face="Verdana">1.4 4.7 5.1 8.3 9.0 14.5 14.0 13.4 19.2 18</font></div>
</div><div style="font-size:10pt;font-family:Verdana"><br></div><div style="font-size:10pt;font-family:Verdana"><br></div><div style="font-size:10pt;font-family:Verdana">// ******** tpl file</div><div><div><font face="Verdana">// Likelihood (short)</font></div>
<div><font face="Verdana">DATA_SECTION</font></div><div><font face="Verdana"> init_int n</font></div><div><font face="Verdana"> init_vector y(1,n)</font></div><div><font face="Verdana"><br></font></div><div><font face="Verdana">PARAMETER_SECTION</font></div>
<div><font face="Verdana"> init_number mu</font></div><div><font face="Verdana"> init_number logSigma</font></div><div><font face="Verdana"> objective_function_value f</font></div><div><font face="Verdana"><br></font></div>
<div><font face="Verdana">PROCEDURE_SECTION</font></div><div><font face="Verdana"> f=n*logSigma+sum(square(y-mu))/(2.0*square(exp(logSigma)));</font></div></div><div style="font-size:10pt;font-family:Verdana"><br></div><div style="font-size:10pt;font-family:Verdana">
<br></div><div style="font-size:10pt;font-family:Verdana">cheers</div><div style="font-size:10pt;font-family:Verdana">JC<br><br>><((((°> ><((((°> ><((((°> ><((((°> ><((((°><br>
JC Quiroz<br>División de Investigación Pesquera<br>Instituto de Fomento Pesquero (IFOP)<br>Blanco 839, Valparaíso<br>Chile<br>tel: 56-32-2151418<br>fax: 56-32-2151645<br>email: <a href="mailto:juancarlos.quiroz@ifop.cl" target="_blank">juancarlos.quiroz@ifop.cl</a> <br>
web: <a href="http://codemorecode.wordpress.com/" target="_blank">http://codemorecode.wordpress.com/</a> <br><div><div class="h5"><br><br><br>----- Original Message -----<br>From: "Melissa T Drake (DNR)" <<a href="mailto:melissa.drake@state.mn.us" target="_blank">melissa.drake@state.mn.us</a>><br>
To: <a href="mailto:users@admb-project.org" target="_blank">users@admb-project.org</a><br>Sent: Thursday, 29 November, 2012 19:03:29 (GMT-0400) Auto-Detected<br>Subject: [ADMB Users] calculating a median<br><br>
<div>
<p class="MsoNormal">Is there an easy way calculate the median value of a vector?</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Melissa T. Drake</p>
<p class="MsoNormal">Fisheries Research Supervisor</p>
<p class="MsoNormal">Minnesota Department of Natural Resources</p>
<p class="MsoNormal">500 Lafayette Road</p>
<p class="MsoNormal">St. Paul, MN 55155</p>
<p class="MsoNormal"><a href="tel:651-259-5245" value="+16512595245" target="_blank">651-259-5245</a></p>
<p class="MsoNormal"><a href="mailto:Melissa.drake@state.mn.us" target="_blank">Melissa.drake@state.mn.us</a></p>
<p class="MsoNormal"> </p>
</div>
<br></div></div><div class="im">_______________________________________________
Users mailing list
<a href="mailto:Users@admb-project.org" target="_blank">Users@admb-project.org</a>
<a href="http://lists.admb-project.org/mailman/listinfo/users" target="_blank">http://lists.admb-project.org/mailman/listinfo/users</a>
</div></div></div></div><br>_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@admb-project.org">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></blockquote></div><br>