Skip to content

Instantly share code, notes, and snippets.

View raphaelvallat's full-sized avatar

Raphael Vallat raphaelvallat

View GitHub Profile
@raphaelvallat
raphaelvallat / distcorr.py
Last active December 12, 2023 06:50 — forked from wladston/distcorr.py
Distance correlation with permutation test
import numpy as np
import multiprocessing
from joblib import Parallel, delayed
from scipy.spatial.distance import pdist, squareform
def _dcorr(y, n2, A, dcov2_xx):
"""Helper function for distance correlation bootstrapping.
"""
# Pairwise Euclidean distances
b = squareform(pdist(y, metric='euclidean'))
@raphaelvallat
raphaelvallat / mutual_info.py
Created February 14, 2019 18:55 — forked from GaelVaroquaux/mutual_info.py
Estimating entropy and mutual information with scikit-learn
'''
Non-parametric computation of entropy and mutual-information
Adapted by G Varoquaux for code created by R Brette, itself
from several papers (see in the code).
These computations rely on nearest-neighbor statistics
'''
import numpy as np
@raphaelvallat
raphaelvallat / ecg_derived_respiration.ipynb
Last active April 8, 2025 22:14
Extract respiration signal and respiratory rate from ECG using R-R interval.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@raphaelvallat
raphaelvallat / closest_divisor.py
Last active March 10, 2018 02:14
Find the divisor of a number closest to another number
import numpy as np
def find_closest_divisor(n, m):
"""Find the divisor of n closest to m
"""
divisors = np.array([ i for i in range(1, int(np.sqrt(n)+1)) if n % i == 0 ])
divisions = n / divisors
return divisions[np.argmin(np.abs(m - divisions))]
number, divisor = 1024, 100
@raphaelvallat
raphaelvallat / anova_mixed.r
Last active March 20, 2018 18:37
Mixed within-between ANOVA in R
library(ez)
library(lsmeans)
library(effsize)
# Load the file
df <- read.csv(file="", head=TRUE, sep=",")
# Choose dependant variable (e.g. reaction time)
df$dv <- df$RT