Exemplo n.º 1
0
 def __init__(self, modelFile, var='X'):
     if isinstance(modelFile, basestring):
         x = loadMatVar(modelFile, var)
     else:
         x = modelFile
     x = concatenate((ones((1, shape(x)[1])), x))
     xHat = pinv(x)
     self.x = x
     self.xHat = xHat
Exemplo n.º 2
0
 def __init__(self, modelFile, var='X'):
     if isinstance(modelFile, basestring):
         x = loadMatVar(modelFile, var)
     else:
         x = modelFile
     x = concatenate((ones((1, shape(x)[1])), x))
     xHat = pinv(x)
     self.x = x
     self.xHat = xHat
Exemplo n.º 3
0
 def __init__(self, modelfile, var='X'):
     if type(modelfile) is str:
         x = loadmatvar(modelfile, var)
     else:
         x = modelfile
     x = concatenate((ones((1, shape(x)[1])), x))
     x_hat = pinv(x)
     self.x = x
     self.x_hat = x_hat
Exemplo n.º 4
0
 def __init__(self, modelfile, var='X'):
     if type(modelfile) is str:
         x = loadmatvar(modelfile, var)
     else:
         x = modelfile
     x = concatenate((ones((1, shape(x)[1])), x))
     x_hat = pinv(x)
     self.x = x
     self.x_hat = x_hat
Exemplo n.º 5
0
 def __init__(self, modelFile, var=('X1', 'X2')):
     if isinstance(modelFile, basestring):
         x1 = loadMatVar(modelFile[0], var[0])
         x2 = loadMatVar(modelFile[1], var[1])
     else:
         x1 = modelFile[0]
         x2 = modelFile[1]
     x1Hat = pinv(x1)
     self.x1 = x1
     self.x2 = x2
     self.x1Hat = x1Hat
Exemplo n.º 6
0
 def __init__(self, modelFile, var=('X1', 'X2')):
     if isinstance(modelFile, basestring):
         x1 = loadMatVar(modelFile[0], var[0])
         x2 = loadMatVar(modelFile[1], var[1])
     else:
         x1 = modelFile[0]
         x2 = modelFile[1]
     x1Hat = pinv(x1)
     self.x1 = x1
     self.x2 = x2
     self.x1Hat = x1Hat
Exemplo n.º 7
0
 def __init__(self, modelfile, var=('X1', 'X2')):
     if type(modelfile) is str:
         x1 = loadmatvar(modelfile[0], var[0])
         x2 = loadmatvar(modelfile[1], var[1])
     else:
         x1 = modelfile[0]
         x2 = modelfile[1]
     x1_hat = pinv(x1)
     self.x1 = x1
     self.x2 = x2
     self.x1_hat = x1_hat
Exemplo n.º 8
0
 def __init__(self, modelfile, var=('X1', 'X2')):
     if type(modelfile) is str:
         x1 = loadmatvar(modelfile[0], var[0])
         x2 = loadmatvar(modelfile[1], var[1])
     else:
         x1 = modelfile[0]
         x2 = modelfile[1]
     x1_hat = pinv(x1)
     self.x1 = x1
     self.x2 = x2
     self.x1_hat = x1_hat
Exemplo n.º 9
0
    def get(self, y):
        """Compute regression coefficients from the second design matrix,
        a single r2 statistic, and residuals for the full model"""

        b1 = dot(self.x1Hat, y)
        b1 = b1 - min(b1)
        b1Hat = dot(transpose(self.x1), b1)
        if sum(b1Hat) == 0:
            b1Hat += 1E-06
        x3 = self.x2 * b1Hat
        x3 = concatenate((ones((1, shape(x3)[1])), x3))
        x3Hat = pinv(x3)
        b2 = dot(x3Hat, y)
        predic = dot(b2, x3)
        resid = y - predic
        sse = sum((predic - y)**2)
        sst = sum((y - mean(y))**2)
        if sst == 0:
            r2 = 0
        else:
            r2 = 1 - sse / sst

        return asarray([b2[1:], r2, resid])
Exemplo n.º 10
0
    def get(self, y):
        """Compute regression coefficients from the second design matrix,
        a single r2 statistic, and residuals for the full model"""

        b1 = dot(self.x1Hat, y)
        b1 = b1 - min(b1)
        b1Hat = dot(transpose(self.x1), b1)
        if sum(b1Hat) == 0:
            b1Hat += 1E-06
        x3 = self.x2 * b1Hat
        x3 = concatenate((ones((1, shape(x3)[1])), x3))
        x3Hat = pinv(x3)
        b2 = dot(x3Hat, y)
        predic = dot(b2, x3)
        resid = y - predic
        sse = sum((predic - y) ** 2)
        sst = sum((y - mean(y)) ** 2)
        if sst == 0:
            r2 = 0
        else:
            r2 = 1 - sse / sst

        return asarray([b2[1:], r2, resid])