Skip to content

Commit

Permalink
Merge pull request #19 from mingujo/master
Browse files Browse the repository at this point in the history
Fixed organize_behavior_data, and did the LOGISTIC REGRESSION ON RESP…
  • Loading branch information
timothy1191xa committed Nov 8, 2015
2 parents 5f020e1 + 2fb0dd1 commit de3595b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
33 changes: 33 additions & 0 deletions code/utils/logistic_reg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pandas as pd
import statsmodels.api as sm
import pylab as pl
import numpy as np

#PREDICT SUBJECT's DECISION TO WHETHER GAMBLE OR NOT GIVEN WITH GAIN AND LOSS AMOUNT using LOGISTIC REGRESSION

project_location="../../"
data_location=project_location+"data/ds005/"

run1 = pd.read_table(data_location+"sub001/behav/task001_run001/behavdata.txt")
run2 = pd.read_table(data_location+"sub001/behav/task001_run002/behavdata.txt")
run3 = pd.read_table(data_location+"sub001/behav/task001_run003/behavdata.txt")

run_1=run1.append(run2)
run_total=run_1.append(run3) #append all the data frames of run

a = run_total.drop('onset', 1) # drop onset column

run_organized = a.drop('PTval', 1) # drop PTval column

cols = run_organized.columns.tolist() # reorganize the columns
cols.insert(0, cols.pop(cols.index('respcat'))) # put respcat into front
run_organized = run_organized.reindex(columns= cols) # reorganize

run_final = run_organized.drop(run_organized[run_organized.respcat == -1].index) # drop error in experiment

train_cols = run_final.columns[1:3] # train columns are gain and loss
logit = sm.Logit(run_final['respcat'], run_final[train_cols]) # do regression
result = logit.fit()
result.summary()

run_final['respcat_pred']=result.predict(run_final[train_cols]) # add prediction on the data frame
4 changes: 2 additions & 2 deletions code/utils/organize_behavior_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
behav_total_run=np.concatenate((behav1,behav2,behav3),axis=0)

"""delete the rows that contain -1 in respcat (these are errors in experiment so we should take them out"""
behav_total_run=np.delete(behav_total_run, behav_total_run[:,5]==-1,axis=0)
behavior=np.delete(behav_total_run, np.where(behav_total_run[:,5]==-1),axis=0)

#your behav_total_run is ready to use!
print(your "behavior" is ready to use!)

0 comments on commit de3595b

Please sign in to comment.