Fisheries and Oceans Canada / Pêches et Océans Canada - Government of Canada / Gouvernement du Canada Fisheries and Oceans Canada / Pêches et Océans Canada - Government of Canada / Gouvernement du Canada
 
Français Contact Us Help Search Canada Site
Home What's New DFO National Site Map Media

Fisheries & Oceans
 
 
Maritimes Region
Fishing Industry
General Public
Marine & Oceans Industry
Media
Students and Teachers
Scientists and Researchers
 
AconIconACON       Home/Topics   |   Commands   |   More Examples

NLLS


NLLS Output

//-----------------------------------------------------
// Generate and fit a Von B curve
//-----------------------------------------------------
Function AdjustData(y) {
// Adjust data points by up to 30%
$adjustedy = y * (1 + (0.66 * (rand(shape(len(y),1.0)) - 0.5)));
return($adjustedy);
};
Function DrawVonBCurve(linf,k,t0,xp,yp,title,type) {
// Generates the coordinates and draws the curve
x = seq(1,12.0,0.25);
y = linf * (1.0 - EXP(-1.0 * k * (x - t0)));
Line_Type(type); Data_Line(x,y);
Draw_Line(xp,yp,xp + mm(13),yp);
Draw_Text(xp + mm(16),yp - mm(2.0),title);
};
Function VonB_Curve_Fit(p,resid) {
// generates Von B curve residuals for a given set of LENGTHs and AGEs, to be called by NLLS
// p - an input vector containing the current estimates of the parameter values
// in this case the 3 elements of p contain Length at Infinity, K, and t0.
// resid - an ouptut vector of calculated residuals which NLLS uses to determine the optimal parameter values iteratively
resid = length - p[1] * (1.0 - exp(-1.0 * p[2] * (age - p[3])));
};
Data_Projection("NIL"); // no projection
Data_Window(0,12,0,175); // left, right, bottom, top
Data_Viewport(mm(20),mm(90),mm(200),mm(270)); // position on page of the axis border rectangle
Draw_Text(getview(1),getview(4)+mm(1),"Von B Curve using NLLS");
Line_Type(0);
Axis(1,50,0,10,1,0,1,0,0); // draw axis, 1 deg labels, 0.5 deg tics, left and bottom edges
// vonB: L inf., K, t0, x,y pos, Label, Line type
DrawVonBCurve(152.46,0.3374,1.4544, getview(1)+mm(2), getview(4)-mm(5), "Serchuk 1979 G.Bank",0);
age = x;
length = AdjustData(y); // generate data with error
Data_Points(age,length); // draw the randomized data points

//-----------------------------------------------------
// Estimate a Von B curve using NLLS
//-----------------------------------------------------
NLLS_Parameters("L inf","k","to");
prflag = 15; // print options - iteration q´s, termination condition, parameter summary, print bias
par = 180 0.5 1; // initial estimates
resid = shape(len(length),0.0); // storage for residuals
parout = seout = biasout = par; // storage for output
NLLS_Iteration_Limit(20); // iteration limit
NLLS("VonB_Curve_Fit", par, resid, parout, seout, nobiasout, prflag); // estimate the fit parameters
NLLS_Correlation("VonB_Curve_Fit", parout, resid, 0, seout, biasout, prflag);
Axis(1,50,0,10,1,0,1,0,0);
// vonB: L inf., K, t0, x,y pos, Label, Line type
DrawVonBCurve(parout[1], parout[2], parout[3], getview(1)+mm(2), getview(4)-mm(9), "NLLS estimated",1);
Character_Alignment(2);
Draw_Text(getview(2),getview(3)+mm(1),"these lines need not be aligned");
Character_Alignment(0);

AconIconACON       Home/Topics   |   Commands   |   More Examples



Last Modified : 2003-11-19