コード例 #1
0
ファイル: model.py プロジェクト: mbentz80/jzigbeercp
    def Fcontrast(self, matrix, eff=True, t=True, sd=True, scale=None, invcov=None):
        """
        Compute an Fcontrast for a contrast matrix. 

        Here, matrix M is assumed to be non-singular. More precisely,

        M pX pX' M'

        is assumed invertible. Here, pX is the generalized inverse of the
        design matrix of the model. There can be problems in non-OLS models
        where the rank of the covariance of the noise is not full.

        See the contrast module to see how to specify contrasts.
        In particular, the matrices from these contrasts will always be
        non-singular in the sense above.

        """

        if self.normalized_cov_beta is None:
            raise ValueError, "need covariance of parameters for computing F statistics"

        cbeta = N.dot(matrix, self.beta)

        q = matrix.shape[0]
        if invcov is None:
            invcov = inv(self.cov_beta(matrix=matrix, scale=1.0))
        F = N.add.reduce(N.dot(invcov, cbeta) * cbeta, 0) * recipr((q * self.scale))
        return ContrastResults(F=F, df_denom=self.df_resid, df_num=invcov.shape[0])
コード例 #2
0
ファイル: regression.py プロジェクト: mbentz80/jzigbeercp
    def norm_resid(self):
        """
        Residuals, normalized to have unit length.

        Note: residuals are whitened residuals.
        """
        if not hasattr(self, 'resid'):
            raise ValueError, 'need normalized residuals to estimate standard deviation'

        sdd = utils.recipr(self.sd) / N.sqrt(self.df)
        return  self.resid * N.multiply.outer(N.ones(self.Y.shape[0]), sdd)
コード例 #3
0
ファイル: model.py プロジェクト: mbentz80/jzigbeercp
    def Tcontrast(self, matrix, t=True, sd=True, scale=None):
        """
        Compute a Tcontrast for a row vector matrix. To get the t-statistic
        for a single column, use the 't' method.
        """

        if self.normalized_cov_beta is None:
            raise ValueError, "need covariance of parameters for computing T statistics"

        _t = _sd = None

        _effect = N.dot(matrix, self.beta)
        if sd:
            _sd = N.sqrt(self.cov_beta(matrix=matrix))
        if t:
            _t = _effect * recipr(_sd)
        return ContrastResults(effect=_effect, t=_t, sd=_sd, df_denom=self.df_resid)
コード例 #4
0
ファイル: model.py プロジェクト: mbentz80/jzigbeercp
    def t(self, column=None):
        """
        Return the t-statistic for a given parameter estimate.

        Use Tcontrast for more complicated t-statistics.

        """

        if self.normalized_cov_beta is None:
            raise ValueError, "need covariance of parameters for computing T statistics"

        if column is None:
            column = range(self.beta.shape[0])

        column = N.asarray(column)
        _beta = self.beta[column]
        _cov = self.cov_beta(column=column)
        if _cov.ndim == 2:
            _cov = N.diag(_cov)
        _t = _beta * recipr(N.sqrt(_cov))
        return _t
コード例 #5
0
ファイル: test_utils.py プロジェクト: mbentz80/jzigbeercp
 def test_recipr(self):
     X = N.array([[2,1],[-1,0]])
     Y = utils.recipr(X)
     assert_almost_equal(Y, N.array([[0.5,1],[0,0]]))