Skip to content

Commit

Permalink
backup
Browse files Browse the repository at this point in the history
  • Loading branch information
BrainStatsSam committed Jul 20, 2023
1 parent 3015ca8 commit 905d7e4
Show file tree
Hide file tree
Showing 19 changed files with 5,816 additions and 211 deletions.
32 changes: 16 additions & 16 deletions build/lib/pyperm/glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import warnings


def glm_perm(y, Z, X, distbn, link, nperm=1000, alpha=0.05):
def glm_perm(y, Z, X, distbn, link, scores=None, nperm=1000, alpha=0.05):
""" glm_perm runs sign-flipping pemrutations for generalized linear model
Inputs:
Expand Down Expand Up @@ -122,20 +122,21 @@ def compute_scores_mv(y, Z, X, distbn, link):
distbn = 'binomial'
linkfn = 'logit'
scores, _ = pr.compute_scores_mv(y, Z, X, distbn, link)
scores, _, _ = pr.compute_scores_mv(y, Z, X, distbn, linkfn)
"""
betahat_0, fitted_values_0, psZ, _ = pr.glm_seq(
y, Z, distbn, link, 'Fitting null glm model, progress:')
glm0 = [betahat_0, fitted_values_0, psZ]

XZ_design = np.concatenate((Z, X), axis=1)
print('')
betahat_1, fitted_values_1, psX, _ = pr.glm_seq(
y, XZ_design, distbn, link, 'Fitting full glm model, progress:')
glm1 = [betahat_1, fitted_values_1, psX]
#XZ_design = np.concatenate((Z, X), axis=1)
# print('')
# betahat_1, fitted_values_1, psX, _ = pr.glm_seq(
# y, XZ_design, distbn, link, 'Fitting full glm model, progress:')
#glm1 = [betahat_1, fitted_values_1, psX]

# Combine the perfect separations locations into a single vector
pslocs = np.unique(np.concatenate((np.where(psZ)[0], np.where(psX)[0])))
pslocs = np.where(psZ)[0]
#pslocs = np.unique(np.concatenate((np.where(psZ)[0], np.where(psX)[0])))

# Get the important constants
nvox = y.shape[1]
Expand All @@ -150,14 +151,13 @@ def compute_scores_mv(y, Z, X, distbn, link):
# yvox = np.matrix(y[:, i]).T
yvox = y[:, i]
fitted_0_vox = np.matrix(fitted_values_0[:, i]).T
fitted_1_vox = np.matrix(fitted_values_1[:, i]).T
scores[i, :, :] = pr.compute_scores(yvox, Z, X, fitted_0_vox,
fitted_1_vox, distbn, link, 'effective')
scores[i, :, :] = pr.compute_scores(
yvox, Z, X, fitted_0_vox, distbn, link, 'effective')

return scores, pslocs, glm0, glm1
return scores, pslocs, glm0


def compute_scores_from_glm(y, Z, X, pslocs, fitted_values_0, fitted_values, distbn, link, score_type='effective'):
def compute_scores_from_glm(y, Z, X, pslocs, fitted_values_0, distbn, link, score_type='effective'):
"""
Inputs:
y: a numpy matrix of shape(n_samples, 1) representing the
Expand Down Expand Up @@ -187,14 +187,13 @@ def compute_scores_from_glm(y, Z, X, pslocs, fitted_values_0, fitted_values, dis
# yvox = np.matrix(y[:, i]).T
yvox = y[:, i]
fitted_0_vox = np.matrix(fitted_values_0[:, i]).T
fitted_1_vox = np.matrix(fitted_values[:, i]).T
scores[i, :, :] = pr.compute_scores(
yvox, Z, X, fitted_0_vox, fitted_1_vox, distbn, link, score_type)
yvox, Z, X, fitted_0_vox, distbn, link, score_type)

return scores


def compute_scores(y, Z, X, fitted_values_0, fitted_values, family, link, score_type='effective'):
def compute_scores(y, Z, X, fitted_values_0, family, link, score_type='effective'):
"""
Inputs:
y: a numpy matrix of shape(n_samples, 1) representing the
Expand All @@ -211,6 +210,7 @@ def compute_scores(y, Z, X, fitted_values_0, fitted_values, family, link, score_
linkfn: a string specifying the link function. Must be one of['log',
'logit', 'probit', 'cauchy', 'cloglog', 'identity', 'inverse']
"""
# Doesn't seem like the fitted_values are being used, double check in own time and then fix this!
nsubj = y.shape[0]

# Obtain the derivative and variance evaluated at the fitted values
Expand Down
11 changes: 11 additions & 0 deletions build/lib/pyperm/stats_and_aux_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
A file contain statistics functions
"""
# Import statements
import fnmatch
import os
from time import sleep
import sys
import numpy as np
Expand Down Expand Up @@ -486,3 +488,12 @@ def combine_arrays(arrays):
return np.array([])
else:
return np.concatenate(non_zero_arrays)


def list_files(directory, search_string):
file_list = []
for root, dirs, files in os.walk(directory):
for file_name in files:
if fnmatch.fnmatch(file_name, f'*{search_string}*'):
file_list.append(file_name)
return file_list
Loading

0 comments on commit 905d7e4

Please sign in to comment.