Share Brilliantly
davinci statistics corner
/*
Define the function to optimized. Here, the function takes four paremeters, the values for
the beta vector, and then runs the logLikelihood function in the poisson glm library.
*/
let f = function(b0, b1, b2, b3){
let logL = pl.logLikelihood(data, item=>item.num_awards, item=>{
let eta = b0+b1*item.progAcademic + b2*item.progVocational + b3*item.math;
let mu = Math.exp(eta);
return mu;
});
return logL;
}
//create an iterator from the newtons method library
let test = op.iterator(f, [0,0,0,0]);
//run several interations
for(let i=0;i<100;i++){
test.iterate();
}
Try it!