Exemplo n.º 1
0
def dtest(pos_nodes=0,
          effect=0.0,
          dist="euclidean",
          n=100,
          nodes=400,
          nperms=4999,
          iters=100):
    import mkl
    mkl.set_num_threads(2)

    print "Start"

    #print "Categorical Effect"
    grp = np.repeat([0, 1], n / 2)
    np.random.shuffle(grp)

    #print "Design Matrix"
    design = np.vstack((np.ones(n), grp)).T
    cols = [1]

    #print "Distance Matrices"
    dmats = np.zeros((iters, n, n))
    for i in xrange(iters):
        #if (i % 10) == 0:
        #    print i,
        # Data
        ## Fist, I created the matrix with the random data
        points = np.random.standard_normal((n, nodes))
        ## Second, I select a random selection of nodes to add the effect
        neg_nodes = nodes - pos_nodes
        change_nodes = np.repeat([0, 1], [neg_nodes, pos_nodes])
        np.random.shuffle(change_nodes)
        ## Finally, I add the effect to a select subjects and nodes
        for i in (change_nodes == 1).nonzero()[0]:
            points[grp == 1, i] += effect

        # Compute Distances
        if dist == "euclidean":
            dmat = euclidean_distances(points)
        elif dist == "pearson":
            dmat = compute_distances(points)
        else:
            raise Exception("Unknown distance measure %s" % dist)
        dmats[i] = dmat
    #print ""

    #print "MDMR"
    pvals = []
    Fvals = []
    pvals, Fvals, _, _ = mdmr(dmats, design, cols, nperms)

    #print "Done"
    return pvals, Fvals
Exemplo n.º 2
0
def dtest(n=50, d=0.0, r=0.0, model_covariate=True, niters=100, nperms=4999):
    import mkl
    mkl.set_num_threads(2)
    
    d   = float(d)
    r   = float(r)
        
    # Data/Distances
    pvals = np.zeros(niters)
    Fvals = np.zeros(niters)
    for i in xrange(niters):
        # Design
        
        ## Categorical
        gp  = np.repeat([0, 1], n/2)
        np.random.shuffle(gp)
        x   = gp*d + np.random.standard_normal(n)
        
        ## Continuous
        # see http://stackoverflow.com/questions/16024677/generate-correlated-data-in-python-3-3
        # and http://stats.stackexchange.com/questions/19367/creating-two-random-sequences-with-50-correlation?lq=1
        uncorrelated    = np.random.standard_normal((2,n))
        motion          = uncorrelated[0]
        y               = r*motion + np.sqrt(1-r**2)*uncorrelated[1]
        
        ## Design Matrix
        if model_covariate:
            design = np.vstack((np.ones(n), gp, motion)).T
        else:
            design = np.vstack((np.ones(n), gp)).T
                
        # Date
        points = np.vstack((x,y)).T
        
        # Distances
        dmat  = euclidean_distances(points)
        dmats = dmat[np.newaxis,:,:]
        
        # Only the group effect is the variable of interest
        cols = [1]
        
        # Call MDMR
        pval, Fval, _, _ = mdmr(dmats, design, cols, nperms)
        
        pvals[i] = pval
        Fvals[i] = Fval
    
    return pvals, Fvals
Exemplo n.º 3
0
def dtest(n=50, d=0.0, r=0.0, model_covariate=True, niters=100, nperms=4999):
    import mkl
    mkl.set_num_threads(2)

    d = float(d)
    r = float(r)

    # Data/Distances
    pvals = np.zeros(niters)
    Fvals = np.zeros(niters)
    for i in xrange(niters):
        # Design

        ## Categorical
        gp = np.repeat([0, 1], n / 2)
        np.random.shuffle(gp)
        x = gp * d + np.random.standard_normal(n)

        ## Continuous
        # see http://stackoverflow.com/questions/16024677/generate-correlated-data-in-python-3-3
        # and http://stats.stackexchange.com/questions/19367/creating-two-random-sequences-with-50-correlation?lq=1
        uncorrelated = np.random.standard_normal((2, n))
        motion = uncorrelated[0]
        y = r * motion + np.sqrt(1 - r**2) * uncorrelated[1]

        ## Design Matrix
        if model_covariate:
            design = np.vstack((np.ones(n), gp, motion)).T
        else:
            design = np.vstack((np.ones(n), gp)).T

        # Date
        points = np.vstack((x, y)).T

        # Distances
        dmat = euclidean_distances(points)
        dmats = dmat[np.newaxis, :, :]

        # Only the group effect is the variable of interest
        cols = [1]

        # Call MDMR
        pval, Fval, _, _ = mdmr(dmats, design, cols, nperms)

        pvals[i] = pval
        Fvals[i] = Fval

    return pvals, Fvals
Exemplo n.º 4
0
def dtest(pos_nodes=0, effect=0.0, dist="euclidean", n=100, nodes=400, nperms=4999, iters=100):
    import mkl
    mkl.set_num_threads(2)
    
    print "Start"

    #print "Categorical Effect"
    grp  = np.repeat([0, 1], n/2)
    np.random.shuffle(grp)

    #print "Design Matrix"
    design = np.vstack((np.ones(n), grp)).T
    cols = [1]

    #print "Distance Matrices"
    dmats = np.zeros((iters,n,n))
    for i in xrange(iters):
        #if (i % 10) == 0:
        #    print i,
        # Data
        ## Fist, I created the matrix with the random data
        points = np.random.standard_normal((n,nodes))
        ## Second, I select a random selection of nodes to add the effect
        neg_nodes = nodes - pos_nodes
        change_nodes = np.repeat([0,1], [neg_nodes, pos_nodes])
        np.random.shuffle(change_nodes)
        ## Finally, I add the effect to a select subjects and nodes
        for i in (change_nodes==1).nonzero()[0]:
            points[grp==1,i] += effect
        
        # Compute Distances
        if dist == "euclidean":
            dmat    = euclidean_distances(points)
        elif dist == "pearson":
            dmat    = compute_distances(points)
        else:
            raise Exception("Unknown distance measure %s" % dist)
        dmats[i]    = dmat
    #print ""

    #print "MDMR"
    pvals = []; Fvals = [];
    pvals, Fvals, _, _ = mdmr(dmats, design, cols, nperms)
    
    #print "Done"
    return pvals, Fvals