Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
# This sets the pdf font type so that it imports correctly in Adobe Illustrator. | |
# Source: http://jonathansoma.com/lede/data-studio/matplotlib/exporting-from-matplotlib-to-open-in-adobe-illustrator/ | |
import matplotlib | |
matplotlib.rcParams['pdf.fonttype'] = 42 | |
matplotlib.rcParams['ps.fonttype'] = 42 | |
# Generating 2x retina plots | |
%config InlineBackend.figure_format = 'retina' | |
# Set base figure size |
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 numpy as np | |
import pandas as pd | |
def parse_triangle(df, condition='upper'): | |
''' | |
This function grabs the upper triangle of a correlation matrix | |
by masking out the bottom triangle (tril) and returns the values. | |
You can use scipy.spatial.distance.squareform to recreate matrix from upper triangle | |
Args: | |
df: pandas or numpy correlation matrix |
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
# First load rpy2 | |
%load_ext rpy2.ipython | |
# Then load packages in a separate cell | |
%%R | |
require('lme4') | |
require('lmerTest') | |
require('lattice') | |
require('boot') | |
require('sjPlot') |
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
# Correct p-value by adjusting degrees of freedom. | |
# Degrees of freedom is divided by two and then looked up | |
# Reference: | |
# https://www.ncbi.nlm.nih.gov/pubmed/27751943 | |
# Chen, G., Taylor, P. A., Shin, Y. W., Reynolds, R. C., & Cox, R. W. (2017). Untangling the relatedness among correlations, Part II: Inter-subject correlation group analysis through linear mixed-effects modeling. Neuroimage, 147, 825-840. | |
from scipy.stats import t | |
tt = 9.83 | |
df = 17.6/2. | |
pval = t.sf(np.abs(tt), df)*2 |
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
def crosscorr(datax, datay, lag=0): | |
""" Lag-N cross correlation. | |
Calculates cross correlations using pandas functionality that can be used in a list comprehension. | |
Parameters | |
---------- | |
lag : int, default 0 | |
datax, datay : pandas.Series objects of equal length | |
Returns |
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}") |
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
# Set window size to compute moving window synchrony. | |
r_window_size = 120 | |
# Interpolate missing data. | |
df_interpolated = df.interpolate() | |
# Compute rolling window synchrony | |
rolling_r = df_interpolated['S1_Joy'].rolling(window=r_window_size, center=True).corr(df_interpolated['S2_Joy']) | |
f,ax=plt.subplots(2,1,figsize=(14,6),sharex=True) | |
df.rolling(window=30,center=True).median().plot(ax=ax[0]) | |
ax[0].set(xlabel='Frame',ylabel='Smiling Evidence') | |
rolling_r.plot(ax=ax[1]) |
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
def crosscorr(datax, datay, lag=0, wrap=False): | |
""" Lag-N cross correlation. | |
Shifted data filled with NaNs | |
Parameters | |
---------- | |
lag : int, default 0 | |
datax, datay : pandas.Series objects of equal length | |
Returns |
OlderNewer