
1 
// Copyright (c) 2008, 2009, 2010 Regents of the University of California.


2 
//


3 
// ADModelbuilder and associated libraries and documentations are


4 
// provided under the general terms of the "BSD" license.


5 
//


6 
// Redistribution and use in source and binary forms, with or without


7 
// modification, are permitted provided that the following conditions are


8 
// met:


9 
//


10 
// 1. Redistributions of source code must retain the above copyright


11 
// notice, this list of conditions and the following disclaimer.


12 
//


13 
// 2. Redistributions in binary form must reproduce the above copyright


14 
// notice, this list of conditions and the following disclaimer in the


15 
// documentation and/or other materials provided with the distribution.


16 
//


17 
// 3. Neither the name of the University of California, Otter Research,


18 
// nor the ADMB Foundation nor the names of its contributors may be used


19 
// to endorse or promote products derived from this software without


20 
// specific prior written permission.


21 
//


22 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS


23 
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT


24 
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR


25 
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT


26 
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,


27 
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT


28 
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,


29 
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY


30 
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT


31 
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE


32 
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


33 


34 
// This example demonstrates how to include the usercontributed functions


35 
// from the statsLib.h library into ADMB.


36 
// Add GLOBALS_SECTION


37 
// and include the header file #include <statsLib.h>


38 
// then replace the likelihood with the dnorm function.


39 


40 
DATA_SECTION


41 
init_int nobs


42 
init_vector Y(1,nobs)


43 
init_vector x(1,nobs)


44 
PARAMETER_SECTION


45 
init_number a


46 
init_number b


47 
vector pred_Y(1,nobs)


48 
objective_function_value f


49 
PROCEDURE_SECTION


50 
pred_Y=a*x+b;


51 
//f=(norm2(pred_YY));


52 
//f=nobs/2.*log(f); // make it a likelihood function so that


53 
// covariance matrix is correct


54 
f=dnorm(pred_YY);


55 


56 
GLOBALS_SECTION


57 
#include <statsLib.h>


58 
