Skip to content

Instantly share code, notes, and snippets.

@jcheong0428
Last active December 30, 2021 03:49
Show Gist options
  • Save jcheong0428/20f737f0641777d3548e3798138714d0 to your computer and use it in GitHub Desktop.
Save jcheong0428/20f737f0641777d3548e3798138714d0 to your computer and use it in GitHub Desktop.
sim_mat1.py
import seaborn as sns
import numpy as np
import pandas as pd
import scipy.stats as stats
from scipy.spatial.distance import squareform
import matplotlib.pyplot as plt
# n is the number of subjects or items that will determine the size of the correlation matrix.
n = 20
data_length = 50
nr = .58
# Random data
np.random.seed(0)
m1_u = np.random.normal(loc=0, scale=1, size=(data_length, n))
m2_u = nr*np.random.normal(loc=0, scale=1, size=(data_length, n)) + (1-nr)*m1_u
m1 = pd.DataFrame(m1_u).corr()
m2 = pd.DataFrame(m2_u).corr()
f,axes = plt.subplots(1,2, figsize=(10,5))
sns.set_style("white")
for ix, m in enumerate([m1,m2]):
sns.heatmap(m, cmap="RdBu_r", center=0, vmin=-1, vmax=1, ax=axes[ix], square=True, cbar_kws={"shrink": .5}, xticklabels=True)
axes[ix].set(title=f"m{ix+1}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment