Skip to content

Instantly share code, notes, and snippets.

@jcquiroz
Created January 16, 2012 14:47
Show Gist options
  • Save jcquiroz/1621193 to your computer and use it in GitHub Desktop.
Save jcquiroz/1621193 to your computer and use it in GitHub Desktop.
simple_linear.tpl
GLOBALS_SECTION
#include <likelihoodStats.cxx>
DATA_SECTION
init_int nobs
init_matrix data(1,nobs,1,3)
PARAMETER_SECTION
init_bounded_number a(-0.5,0.5,1)
init_bounded_number b(0.1,3,1)
vector x(1,nobs)
vector y(1,nobs)
vector cv(1,nobs)
vector yfit(1,nobs)
vector rss(1,nobs)
objective_function_value f
LOCAL_CALCS
x=column(data,1);
y=column(data,2);
cv=column(data,3);
END_CALCS
PROCEDURE_SECTION
yfit = a+b*x;
// rss = nlikelihood(y,yfit,cv,2);
rss = elem_div(square(log(y)-log(yfit)), 2*square(cv));
f = sum(rss);
REPORT_SECTION
report << "fit: " << yfit << endl;
report << "rss: " << f << endl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment