Source code for naginterfaces.​library.​examples.​correg.​glm_normal_ex

#!/usr/bin/env python
"``naginterface.library.correg.glm_normal`` Python Example."

# NAG Copyright 2017-2019.

# pylint: disable=invalid-name,too-many-locals

from naginterfaces.library import correg

[docs]def main(): """ Example for :func:`naginterfaces.library.correg.glm_normal`. Fits a generalized linear model with Normal errors. >>> main() naginterfaces.library.correg.glm_normal Python Example Results. Fits a generalized linear model with Normal errors. Fitted model summary: RSS is 3.872e-01 Degrees of freedom 3 Term Estimate Standard Error Variable: 0 -2.387e-02 2.779e-03 Variable: 1 6.381e-02 2.638e-03 """ print('naginterfaces.library.correg.glm_normal Python Example Results.') print('Fits a generalized linear model with Normal errors.') # The observations: x = [ [1.], [2.], [3.], [4.], [5.], ] # Other parameters for the fit: link = 'Reciprocal' isx = [1] y = [ 25., 10., 6., 4., 3., ] tol = 5.e-5 eps = 1.e-6 fit = correg.glm_normal( x, isx, y, link=link, tol=tol, eps=eps, ) print('Fitted model summary:') print('RSS is {:.3e}'.format(fit.rss)) print('Degrees of freedom {:d}'.format(fit.idf)) print('Term' + ' '*9 + 'Estimate' + ' '*3 + 'Standard Error') for i, b_i in enumerate(fit.b): print('Variable:' + ' '*2 + '{:d} {:.3e} {:.3e}'.format( i, b_i, fit.se[i] ))
if __name__ == '__main__': import doctest import sys sys.exit( doctest.testmod( None, verbose=True, report=False, optionflags=doctest.REPORT_NDIFF, ).failed )