Пример #1
0
    def initialize(self):
        self.wexog = self.whiten(self.exog)
        self.wendog = self.whiten(self.endog)
        # overwrite nobs from class Model:
        self.nobs = float(self.wexog.shape[0])
        self.df_resid = self.nobs - rank(self.exog)
#       Below assumes that we have a constant
        self.df_model = float(rank(self.exog)-1)
 def initialize(self):
     """
     Initialize is called by
     scikits.statsmodels.model.LikelihoodModel.__init__
     and should contain any preprocessing that needs to be done for a model.
     """
     self.df_model = float(tools.rank(self.exog) - 1) # assumes constant
     self.df_resid = float(self.exog.shape[0] - tools.rank(self.exog))
Пример #3
0
 def initialize(self):
     """
     Initialize a generalized linear model.
     """
     # TODO: intended for public use?
     self.history = {"fittedvalues": [], "params": [np.inf], "deviance": [np.inf]}
     self.iteration = 0
     self.pinv_wexog = np.linalg.pinv(self.exog)
     self.normalized_cov_params = np.dot(self.pinv_wexog, np.transpose(self.pinv_wexog))
     self.df_model = tools.rank(self.exog) - 1
     self.df_resid = self.exog.shape[0] - tools.rank(self.exog)
Пример #4
0
    def _initialize(self):
        """
        Initializes the model for the IRLS fit.

        Resets the history and number of iterations.
        """
        self.history = {'deviance' : [np.inf], 'params' : [np.inf],
            'weights' : [np.inf], 'sresid' : [np.inf], 'scale' : []}
        self.iteration = 0
        self.pinv_wexog = np.linalg.pinv(self.exog)
        self.normalized_cov_params = np.dot(self.pinv_wexog,
                                        np.transpose(self.pinv_wexog))
        self.df_resid = np.float(self.exog.shape[0] - tools.rank(self.exog))
        self.df_model = np.float(tools.rank(self.exog)-1)
        self.nobs = float(self.endog.shape[0])
Пример #5
0
def contrastfromcols(L, D, pseudo=None):
    """
    From an n x p design matrix D and a matrix L, tries
    to determine a p x q contrast matrix C which
    determines a contrast of full rank, i.e. the
    n x q matrix

    dot(transpose(C), pinv(D))

    is full rank.

    L must satisfy either L.shape[0] == n or L.shape[1] == p.

    If L.shape[0] == n, then L is thought of as representing
    columns in the column space of D.

    If L.shape[1] == p, then L is thought of as what is known
    as a contrast matrix. In this case, this function returns an estimable
    contrast corresponding to the dot(D, L.T)

    Note that this always produces a meaningful contrast, not always
    with the intended properties because q is always non-zero unless
    L is identically 0. That is, it produces a contrast that spans
    the column space of L (after projection onto the column space of D).

    Parameters
    ----------
    L : array-like
    D : array-like
    """
    L = np.asarray(L)
    D = np.asarray(D)

    n, p = D.shape

    if L.shape[0] != n and L.shape[1] != p:
        raise ValueError, 'shape of L and D mismatched'

    if pseudo is None:
        pseudo = np.linalg.pinv(D)    # D^+ \approx= ((dot(D.T,D))^(-1),D.T)

    if L.shape[0] == n:
        C = np.dot(pseudo, L).T
    else:
        C = L
        C = np.dot(pseudo, np.dot(D, C.T)).T

    Lp = np.dot(D, C.T)

    if len(Lp.shape) == 1:
        Lp.shape = (n, 1)

    if tools.rank(Lp) != Lp.shape[1]:
        Lp = tools.fullrank(Lp)
        C = np.dot(pseudo, Lp).T

    return np.squeeze(C)