Created
December 19, 2013 13:31
-
-
Save CerebralMastication/8039120 to your computer and use it in GitHub Desktop.
Example of iman conover
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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