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 |
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
# First gist for Hungarian post. | |
# Brute force estimation of optimal assignment for given preference. | |
%matplotlib inline | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
sns.set_context('talk') | |
sns.set_style('white') | |
import itertools | |
import numpy as np |
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
%%timeit | |
# Second gist for Hungarian post. | |
# Estimates the time needed for brute force optimal assignment for group size 10. | |
# Takes about 3 minutes. | |
maxsums, colixs = [], [] | |
group_size = 10 | |
np.random.seed(0) | |
preferences = np.random.rand(group_size,group_size) | |
rowix = list(range(group_size)) # rows don't need to be permuted |
OlderNewer