From b5d944139669da9e865ae9bf3c3322a659052908 Mon Sep 17 00:00:00 2001 From: katieemmons <56890287+katieemmons@users.noreply.github.com> Date: Tue, 22 Oct 2019 14:36:24 -0700 Subject: [PATCH] Create individual_tests --- individual_tests | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 individual_tests diff --git a/individual_tests b/individual_tests new file mode 100644 index 0000000..c042a4d --- /dev/null +++ b/individual_tests @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Tue Oct 15 14:47:35 2019 + +@author: katieemmons +""" + +import pandas as pd +#replace file with path to individuals data in .txt format +file = r'/Users/katieemmons/Desktop/behavioral/100/clouds_2bo_raw.txt' + +df = pd.read_csv(file) +print(file) + +#creates two additional columns in df +df['correct resp'] = df.resp == df.want +df['unknown resp'] = df.resp == "????" + +#list of experimental conditions +conditions = ["maintain space", "maintain pitch", "maintain both", "switch space", "switch pitch", "switch both"] + + +# calculates perent correct for each condition for an individual participant +def percentCorrect(str): + correct_responses = (df.loc[df['cond'] == str, 'correct resp'].sum()) + total_trials = ((df['cond'] == str).sum()) + return (correct_responses/total_trials * 100) + +for x in conditions: + percentCorrect(x) + print(x, "percent correct:", percentCorrect(x)) + +# calculates the total number of unknown responses for each condition for an individual participant +def unknownResponse(str): + unknown_resp = (df.loc[df['cond'] == str, 'unknown resp'].sum()) + return(unknown_resp) + +for x in conditions : + unknownResponse(x) + print(x, "unknowns :", unknownResponse(x)) + + # 0 = 'want' +# 1 = 'resp' +# 2 = 'cond' +# 3 = 'correct resp' (boolean) +# 4 = 'unknown resp' (boolean) + +# calculates percent correct for each syllable position for an individual participant +def syllablePercentCorrect (int): + n=0 + total_trials = len(df.index) + for ind in df.index: + if(((df.iat[ind,0])[int]) == ((df.iat[ind,1][int]))): + n=n+1 + return (n/total_trials) + +for x in range (0,4): + syllablePercentCorrect(x) + print (x+1, "th syllable:", syllablePercentCorrect(x)) + +# calculates the number of unknown responses for each syllable for an individual participant + +def unknownSyllable (int): + n=0 + for ind in df.index: + if("?" == ((df.iat[ind,1][int]))): + n = n+1 + return (n) + +for x in range (0,4): + unknownSyllable(x) + print(unknownSyllable(x), "unknown responses in", x+1, "th syllable")