*! version 3.0.0, PR 22-Dec-93. STB-18: sg22 * Update of _glmwgt (sg16.3). * Calculates var functn, iterative weights and working dependent variable. program define _jprglwz version 3.1 local touse `1' local y `2' local fam `3' local link `4' local pow `5' local m `6' local disp `7' local k `8' local eta `9' local mu `10' local W `11' local z `12' if "`13'"!="" { local moffset "-`13'" } local small 1e-6 /* Calculate variance function, V, for each family */ tempvar V w if "`fam'"=="bin" { * gen `V' = `mu'*(1-`mu'/`m') gen `V' = abs(`mu'*(1-`mu'/`m')) } else if "`fam'"=="gam" { gen `V' = `mu'^2 } else if "`fam'"=="gau" { gen `V' = 1 } else if "`fam'"=="ivg" { gen `V' = `mu'^3 } else if "`fam'"=="nb" { gen `V' = (`mu'+`k'*`mu'^2) } else if "`fam'"=="poi" { gen `V' = `mu' } /* Calc w = 1/{d(eta)/d(mu)} and W = w^2/V for each link/family, where V = variance function, noting W = abs(w) for canonical links. */ if "`link'"=="pow" { if abs(`pow')<`small' { gen `w' = `mu' } else { gen `w' = `m'^`pow'/(`pow'*`mu'^(`pow'-1)) } } else { if "`fam'" == "bin" { if "`link'" == "l" { gen `w' = `V' } else if "`link'" == "p" { gen `w' = `m'/(sqrt(2*_pi)*exp(-`eta'^2/2)) /* */ if `touse' /* ??? */ } else if "`link'" == "c" { gen `w' = -`m'*(1-`mu'/`m')*log(1-`mu'/`m') } else if "`link'" == "opo" { gen `w' = cond( abs(`pow'-1)<`small', /* */ `m'*(1-`mu'/`m')^2, /* */ `m'*( (`mu'/`m')^(1-`pow') )* /* */ (1-`mu'/`m')^(`pow'+1) ) } } else if "`fam'" == "gam" { gen `w' = -`V' } else if "`fam'" == "ivg" { gen `w' = -.5*`V' } else if "`fam'" == "nb" { gen `w' = `V' } else if "`fam'" == "poi" { gen `w' = `V' } } replace `W' = `disp'*`w'^2/`V' /* `disp' could be in wrong place */ replace `z' = `eta'+(`y'-`mu')/`w' `moffset' end