Skip to content

Instantly share code, notes, and snippets.

@jcheong0428
Last active March 13, 2023 19:45
Show Gist options
  • Save jcheong0428/b04c657e82d2655e5f30747b44465e71 to your computer and use it in GitHub Desktop.
Save jcheong0428/b04c657e82d2655e5f30747b44465e71 to your computer and use it in GitHub Desktop.
synchrony_pearsonr
import pandas as pd
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns
import scipy.stats as stats
df = pd.read_csv('synchrony_sample.csv')
overall_pearson_r = df.corr().iloc[0,1]
print(f"Pandas computed Pearson r: {overall_pearson_r}")
# out: Pandas computed Pearson r: 0.2058774513561943
r, p = stats.pearsonr(df.dropna()['S1_Joy'], df.dropna()['S2_Joy'])
print(f"Scipy computed Pearson r: {r} and p-value: {p}")
# out: Scipy computed Pearson r: 0.20587745135619354 and p-value: 3.7902989479463397e-51
# Compute rolling window synchrony
f,ax=plt.subplots(figsize=(7,3))
df.rolling(window=30,center=True).median().plot(ax=ax)
ax.set(xlabel='Time',ylabel='Pearson r')
ax.set(title=f"Overall Pearson r = {np.round(overall_pearson_r,2)}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment