Skip to content

Instantly share code, notes, and snippets.

View danlurie's full-sized avatar

Daniel Lurie danlurie

View GitHub Profile
import os
import sys
import nipype.interfaces.io as nio
import nipype.pipeline.engine as pe
from nipype import Node, Function
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
from nipype.utils.filemanip import loadpkl
from niworkflows.interfaces.bids import BIDSDataGrabber
from niworkflows.utils.bids import collect_data
import pdb
@danlurie
danlurie / comparing_slopes.md
Created May 31, 2021 01:08
Comparing dependent partial correlations from separate models and autocorrelated data.

I have a single dependent variable Y, K independent variables of interest (X1, X2... Xk), and a single independent variable of non-interest (Z).

I am interested in the relationship between Y and each X, while accounting for the effect of Z. In other words, I am interested in the partial correlations.

Further, I want to compare the slopes of each X to each other, both to evaluate whether some X's have a larger effect than others, and because I want to be able to talk about the presence/absence of a significant effect of each X without falling into the trap of "The Difference Between “Significant” and “Not Significant” is not Itself Statistically Significant".

Complicating factors:

  • There is high co-linearity between many of the X variables. Because of this, and because I have a priori theoretical reasons to be interested in the non-unique variance explained by each X, I assess the effect of each X in a separate model (Y ~ X1 + Z, Y ~ X
unit = [1,0,-1]
Mi = np.empty((27,6), dtype='float')
M_orig = np.flip(np.array(list(itertools.product(unit, repeat=3))), axis=1).astype('float')
M = M_orig.copy()
for row_idx, row_vector in enumerate(M_orig):
row_sum = np.sum(abs(row_vector))
if row_sum == 2:
M[row_idx] = row_vector * (1 / np.sqrt(2))
%create the design matrix, Mi
M = nan(26,3);
Mi = nan(26,6);
Morig = nan(26,3);
i = 1;
unit = [1 0 -1];
for c = unit(1:3)
for b = unit(1:3)
for a = unit(1:3)
M(i,:) = [a b c];
@danlurie
danlurie / sns_partial_series_error.ipynb
Created October 18, 2019 21:06
Seaborn regplot partial Series error
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@danlurie
danlurie / LG400_Med.txt
Created September 1, 2019 22:21
Principal Gradient of Connectivity
5.406879894463452629e+00
3.551887510356126487e+00
4.706248834708515183e+00
5.274285864789658440e+00
4.884599592112461863e+00
-8.065247292292481163e+00
-1.259245327705776418e+01
5.530874590401705149e+00
-2.755716231832272989e+00
7.663190355450852920e-01
@danlurie
danlurie / Python Surface Plotting.ipynb
Last active December 13, 2019 04:17
Python Surface Plotting
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
function [outputBnormFiles] = backNormROI(structuralImage,outputSpaceImage,toBackNormROIs,outputPrefix,outputDirectory,varargin)
% INPUTS:
% structuralDirectory - directory for structural - generate norm files here
% structuralImage - image that will be normalized
% meanEpiFile - image for the mean of the functionals
% preprocessingDirectory - make a directory for the backNormROIs
% toBackNormROIs - images that will be backnormalized
% assume MNI spaces
% outputPrefix - append this prefix to the backNormROIs
%
@danlurie
danlurie / sdout.txt
Created March 11, 2019 23:48
Rapidtide2 IndexError
(rapidtide) # dlurie@nx4 in ~/Software/rapidtide [16:26:10]
$ rapidtide2 /home/despoB/dlurie/Projects/despolab_lesion/sandbox/sub-101_clean.nii.gz /home/despoB/dlurie/Projects/despolab_lesion/sandbox/rapidtide_testing/patient/clean_blaise_rerun/ --corrmask=/home/despoB/dlurie/Projects/despolab_lesion/data/patients/preproc/out/fmriprep/sub-101/func/sub-101_task-rest_acq-128px_run-01_bold_space-T1w_brainmask.nii.gz -L --passes=3 --despecklepasses=4 -r 10,10 -f 2.5
/home/despoB/dlurie/anaconda3/envs/rapidtide/lib/python3.6/site-packages/statsmodels/compat/pandas.py:56: FutureWarning: The pandas.core.datetools module is deprecated and will be removed in a future version. Please use the pandas.tseries module instead.
from pandas.core import datetools
/home/despoB/dlurie/anaconda3/envs/rapidtide/lib/python3.6/site-packages/rapidtide-1.7.0-py3.6.egg/rapidtide
/home/despoB/dlurie/anaconda3/envs/rapidtide/bin/rapidtide2 version: v1.7.0 124-g5e5ed34
using standard scipy.fftpack
numba exists
memprofiler does not exist
from flask import render_template, flash
from flask.ext.appbuilder.models.sqla.interface import SQLAInterface
from flask.ext.appbuilder import ModelView, expose, BaseView, has_access, SimpleFormView
from app import appbuilder, db
from wtforms import StringField
from wtforms.validators import DataRequired
from flask.ext.appbuilder.fieldwidgets import BS3TextFieldWidget
from flask.ext.appbuilder.forms import DynamicForm
from .compute import test_rand