Skip to content

Instantly share code, notes, and snippets.

@janfait
Forked from CerebralMastication/gist:8039120
Last active August 26, 2015 12:06
Show Gist options
  • Save janfait/7563185f54d97d2c057e to your computer and use it in GitHub Desktop.
Save janfait/7563185f54d97d2c057e to your computer and use it in GitHub Desktop.
Example of iman conover
import pandas as pd
## dummy covariance matrix
cov = eye(2) + -.7
fill_diagonal(cov, 1)
# a little bit of non correalted random variates
# also sometimes called the marginal distributions
n = 10000
inputData = pd.DataFrame({'a': np.random.normal(0,10,n), 'b': np.random.normal(10,20,n)})
def makeCorrelated( y, corMatrix ):
c = multivariate_normal(zeros(size( y, 1 ) ) , corMatrix, size( y, 0 ) )
key = argsort( argsort(c, axis=0), axis=0 ).T
out = map(take, map(sort, y.values.T), key)
out = array(out)
return pd.DataFrame(out).T
correlated = makeCorrelated( inputData, cov )
p = pd.scatter_matrix( correlated )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment