Beispiel #1
0
    def _run_family(self, family_name):

        family = self.families[family_name]

        glm_res = glm.fit_glm(self.input, self.exog, family)

        f = glm.f_test(glm_res.beta, self.contrast, glm_res.normalized_cov_params, glm_res.scale)
        f = np.reshape(f, (len(f),))

        smoothed_f = glm.f_test(glm_res.beta, self.contrast, glm_res.normalized_cov_params, glm_res.scale, smoothing=np.zeros(3))

        got = {
            'beta' : glm_res.beta,
            'mu'   : glm_res.mu,
            'weights' : glm_res.weights,
            'f_values' : f }

        for (name, values) in got.items():
            print("Doing " + name)
            filename = 'pade/test/glm/{0}_{1}.txt'.format(family_name, name)
            expected = np.genfromtxt(filename)
            np.testing.assert_almost_equal(expected, values)
            for i in range(3):
                np.testing.assert_almost_equal(expected, values)
            
        filename = 'pade/test/glm/{0}_{1}.txt'.format(family_name, 'f_values')
        expected = np.genfromtxt(filename)
        for i in range(3):
            np.testing.assert_almost_equal(expected, smoothed_f[i].reshape(len(smoothed_f[i])))
Beispiel #2
0
def new_glm(y, x, family, contrast):
    models = []
    fitteds = []
    fs = []

    f = None

    (params, mu, weights, cov_p, scale) = glm.fit_glm(y, x, family)
    f = glm.f_test(params, contrast, cov_p, scale, smoothing=np.arange(10))
Beispiel #3
0
def new_glm(y, x, family, contrast):
    models = []
    fitteds = []
    fs = []

    f = None

    (params, mu, weights, cov_p, scale) = glm.fit_glm(y, x, family)
    f = glm.f_test(params, contrast, cov_p, scale, smoothing=np.arange(10))
Beispiel #4
0
def new_glm(y, x, family, contrast):
    models = []
    fitteds = []
    fs = []

    f = None

    (params, mu, weights, cov_p, scale) = glm.fit_glm(y, x, family)
    f = glm.f_test(params, contrast, cov_p, scale)

    return GlmResults(y, x, family, contrast, 
                      params, mu, weights, f)
Beispiel #5
0
    def _run_family(self, family_name):

        family = self.families[family_name]

        glm_res = glm.fit_glm(self.input, self.exog, family)

        f = glm.f_test(glm_res.beta, self.contrast,
                       glm_res.normalized_cov_params, glm_res.scale)
        f = np.reshape(f, (len(f), ))

        smoothed_f = glm.f_test(glm_res.beta,
                                self.contrast,
                                glm_res.normalized_cov_params,
                                glm_res.scale,
                                smoothing=np.zeros(3))

        got = {
            'beta': glm_res.beta,
            'mu': glm_res.mu,
            'weights': glm_res.weights,
            'f_values': f
        }

        for (name, values) in got.items():
            print("Doing " + name)
            filename = 'pade/test/glm/{0}_{1}.txt'.format(family_name, name)
            expected = np.genfromtxt(filename)
            np.testing.assert_almost_equal(expected, values)
            for i in range(3):
                np.testing.assert_almost_equal(expected, values)

        filename = 'pade/test/glm/{0}_{1}.txt'.format(family_name, 'f_values')
        expected = np.genfromtxt(filename)
        for i in range(3):
            np.testing.assert_almost_equal(
                expected, smoothed_f[i].reshape(len(smoothed_f[i])))
Beispiel #6
0
    def __call__(self, data):

        num_regressors = len(self.layout_full)
        num_restrictions = num_regressors - 1

        x = self.x
        contrast = self.contrast

        y = data

        family = self.family

        if np.ndim(y) == 1:
            raise Exception("I only do 2d arrays")

        shrink = self.shrink

        if shrink:
            ctor = GLM_FAMILIES['negative_binomial']
            family = ctor()
            print(
                "Using shrinkage estimator of dispersal in negative binomial GLM."
            )
            raise Exception("yay!")

        m = len(y)
        alphas = self.alphas

        if alphas is None:
            res = np.zeros(m)
        else:
            res = np.zeros((len(alphas), m))

        glm_res = glm.fit_glm(y, x, family)
        kwargs = {}
        if self.alphas is not None:
            kwargs['smoothing'] = alphas

        res = glm.f_test(glm_res.beta, contrast, glm_res.normalized_cov_params,
                         glm_res.scale, **kwargs)
        # For some reason the f-test returns an array with two extra dims
        return res.reshape(res.shape[:-2])
Beispiel #7
0
    def __call__(self, data):

        num_regressors = len(self.layout_full)
        num_restrictions = num_regressors - 1

        x = self.x
        contrast = self.contrast

        y = data

        family = self.family

        if np.ndim(y) == 1:
            raise Exception("I only do 2d arrays")

        shrink = self.shrink

        if shrink:
            ctor = GLM_FAMILIES['negative_binomial']
            family = ctor()
            print("Using shrinkage estimator of dispersal in negative binomial GLM.")
            raise Exception("yay!")

        m = len(y)
        alphas = self.alphas

        if alphas is None:
            res = np.zeros(m)
        else:
            res = np.zeros((len(alphas), m))

        glm_res = glm.fit_glm(y, x, family)
        kwargs = {}
        if self.alphas is not None:
            kwargs['smoothing'] = alphas

        res = glm.f_test(glm_res.beta, contrast, glm_res.normalized_cov_params, glm_res.scale, **kwargs)
        # For some reason the f-test returns an array with two extra dims
        return res.reshape(res.shape[:-2])