Last active
March 13, 2023 19:45
-
-
Save jcheong0428/b04c657e82d2655e5f30747b44465e71 to your computer and use it in GitHub Desktop.
synchrony_pearsonr
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 | |
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