Giter VIP home page Giter VIP logo

pylearn-mulm's Introduction

Massive univariate linear model

Provide basic features similar to "statmodels" (like OLS) where Y is a matrix of many responses where many independant fit are requested.

Important links

Installation

Unless you already have Numpy and Scipy installed, you need to install them:

sudo apt-get install python-numpy python-scipy

Clone the repository from github

git clone https://github.com/neurospin/pylearn-mulm.git

Add pylearn-mulm in your $PYTHONPATH

Dataset

import numpy as np
import mulm
import statsmodels.api as sm

n = 100
X = np.random.randn(n, 5)
Y = np.random.randn(n, 10)
beta = np.random.randn(5, 1)
# Causal model: add X on the 2 first variables
Y[:, :2] += np.dot(X, beta)

T-tests with MULM

t-test of all the regressors (by default MULM and statsmodel do two-tailed tests). Use Ordinary least squares (OLS).

contrasts = np.identity(X.shape[1])

mod = mulm.MUOLS(Y, X)
mulm_tvals, mulm_pvals, mulm_df = mod.fit().t_test(contrasts, pval=True, two_tailed=True)

Use statmodels, need to iterate over Y columns

sm_tvals = list()
sm_pvals = list()
for j in range(Y.shape[1]):
    mod = sm.OLS(Y[:, j], X)
    sm_ttest = mod.fit().t_test(contrasts)
    sm_tvals.append(sm_ttest.tvalue)
    sm_pvals.append(sm_ttest.pvalue)

sm_tvals = np.asarray(sm_tvals).T
sm_pvals = np.asarray(sm_pvals).T


# Check that results ar similar
np.allclose(mulm_tvals, sm_tvals)
np.allclose(mulm_pvals, sm_pvals)

Multiple comparison: maxT

import numpy as np
import mulm
import pylab as plt

n = 100
px = 5
py_info = 2
py_noize = 100

beta = np.array([1, 0, .5] + [0] * (px - 4) + [2]).reshape((px, 1))
X = np.hstack([np.random.randn(n, px-1), np.ones((n, 1))]) # X with intercept
Y = np.random.randn(n, py_info + py_noize)
# Causal model: add X on the first py_info variable
Y[:, :py_info] += np.dot(X, beta)

# t-test all the regressors (by default mulm and sm do two-tailed tests)
contrasts = np.identity(X.shape[1])

mod = mulm.MUOLS(Y, X)
tvals, rawp, df = mod.fit().t_test(contrasts, pval=True, two_tailed=True)
tvals, maxT, df2 = mod.t_test_maxT(contrasts, two_tailed=True)


n, bins, patches = plt.hist([rawp[0,:], maxT[0,:]],
                            color=['blue', 'red'], label=['rawp','maxT'])
plt.legend()
plt.show()

pylearn-mulm's People

Contributors

duchesnay avatar jinpengli avatar agrigis avatar

Stargazers

Pauline Favre avatar Kyle Shlansker avatar Chrinide avatar Vishal Belsare avatar  avatar

Watchers

Gael Varoquaux avatar bthirion avatar  avatar Matthieu Perrot avatar  avatar James Cloos avatar Denis Rivière avatar Tommy Löfstedt avatar  avatar Vincent Frouin avatar Hadj Selem avatar  avatar Mathieu Dubois avatar PHILIPPE Cathy avatar Laure H avatar LAJOUS Helene avatar  avatar gareaut avatar De Pierrefeu avatar

pylearn-mulm's Issues

Excessive dependencies

I have some concern about the number of mandatory dependencies of MULM.

Having to install MULM on several computers, I often enter a recursive installation problem:

  • in order to use MULM, you need EPAC
  • in order to use EPAC, you need soma-workflow
  • in order to use soma-workflow, you need dill
    Moreover you need fairly recent version of those packages which means:
  • finding the webpage
  • cloning git repositories
  • installing if necessary
  • updating PYTHONPATH (twice if you use spyder)
    All of this has to be done whether or not you use the parallel features.

I know that this is documented and that those dependencies are needed for some tasks. I was just wondering if we could try to import the packages only when needed.

Problem with SomaWorkflowEngine

Hello,

When I run the main() in mulm/models.py all the jobs failed with:

Traceback (most recent call last):
  File "./brainomics/pylearn-epac/bin/epac_mapper", line 78, in <module>
    f = open(relative_filepath, 'r')
IOError: [Errno 2] No such file or directory: './0.job'

Nothing was written in the working directory.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.