Skip to content

Instantly share code, notes, and snippets.

@CerebralMastication
Created December 19, 2013 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save CerebralMastication/8039120 to your computer and use it in GitHub Desktop.
Save CerebralMastication/8039120 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