Skip to content
Browse files

Write code to plot hit rate minus FA rate.m

  • Loading branch information...
1 parent 89c4511 commit 633e1c8bf6467fe0d259257f0fa6927cff4795f1 @dabliss committed
Showing with 39 additions and 134 deletions.
  1. +4 −1 README
  2. +0 −76 get_old_v_new_hit_minus_FA.m
  3. +35 −20 plot_old_v_new_d_primes.m → plot_old_v_new.m
  4. +0 −29 plot_old_v_new_hit_minus_FA.m
  5. +0 −8 remove_nonlick_time.m
View
5 README
@@ -6,7 +6,7 @@ How to do stuff:
B) W = window_lick_rates(times, words)
* Plot average d' by contrast across all sessions, all animals
- 1) plot_old_v_new_d_primes
+ 1) plot_old_v_new('d')
A) [words codes times] = read_logfile(logfile)
B) W = window_lick_rates(times, words)
C) [words codes times] = motivated_time(W, words, codes, times);
@@ -14,4 +14,7 @@ How to do stuff:
i) column = code_go(code)
ii) column = code_nogo(code)
+* Plot hit rate minus FA rate across all sessions, all animals
+ 1) plot_old_v_new('h')
+
*
View
76 get_old_v_new_hit_minus_FA.m
@@ -1,76 +0,0 @@
-function hit_minus_FA_by_task = get_old_v_new_hit_minus_FA(subject)
-
-data_dir = '~/Science/dan/data_and_figures/';
-date_dirs = dir(data_dir);
-n_sessions = [0; 0];
-hit_minus_FA_by_task = cell(2, 1);
-for i = 3:length(date_dirs)
- test_date = date_dirs(i).name;
- if regexp(test_date, '[0-9]{6}')
- logfile = dir([data_dir test_date '/' subject '*.log']);
- if ~isempty(logfile)
- % Assume no more than one logfile per day for each subject.
- logfile = logfile(1).name;
- if strcmp(logfile, [subject '-lucas_discrim_airpuff_4contrast.log'])
- i_task = 1;
- elseif strcmp(logfile, ...
- [subject '-bliss_random_no3rule_halfITI_halfTO.log'])
- i_task = 2;
- else
- continue
- end
- n_sessions(i_task) = n_sessions(i_task) + 1;
- [descriptions codes times] = read_logfile([data_dir ...
- test_date '/' logfile]);
- [lick_rates overall_mean] = get_window_lick_rates(times, ...
- descriptions);
- [start_time end_time] = get_motivated_period(lick_rates, ...
- overall_mean);
- i_motivated = times >= start_time & times <= end_time;
- descriptions = descriptions(i_motivated);
- codes = codes(i_motivated);
- % Now make sure you're using only complete trials.
- i_first_trial_start = find(strcmp(descriptions, 'Manual'), 1);
- i_last_trial_end = find(codes == 7, 1, 'last');
- descriptions = descriptions(i_first_trial_start:i_last_trial_end);
- codes = codes(i_first_trial_start:i_last_trial_end);
- contrasts = abs(codes(strcmp(descriptions, 'Manual')));
- stim_codes = codes(strcmp(descriptions, 'Video') | ...
- strcmp(descriptions, 'Picture'));
- responses = [];
- for j = 1:length(stim_codes)-1
- code_string = int2str(stim_codes(j));
- first_digit = code_string(1);
- switch first_digit
- case '2'
- if stim_codes(j+1) == 3
- responses = [responses; 1];
- else
- responses = [responses; 0];
- end
- case '1'
- if stim_codes(j+1) == 4
- responses = [responses; 2];
- else
- responses = [responses; 3];
- end
- end
- end
- if length(contrasts) ~= length(responses)
- if length(contrasts) == length(responses) + 1
- contrasts = contrasts(1:end-1);
- else
- disp(responses)
- error(['Contrasts: ' int2str(length(contrasts)) ...
- ', Responses: ' int2str(length(responses))])
- end
- end
- [hits misses FAs CRs]=sort_responses_by_contrast(responses,...
- contrasts);
- hit_rates = hits./(hits + misses);
- FA_rates = FAs./(FAs + CRs);
- hit_minus_FA_by_task{i_task} = [hit_minus_FA_by_task{i_task}; ...
- hit_rates - FA_rates];
- end
- end
-end
View
55 plot_old_v_new_d_primes.m → plot_old_v_new.m
@@ -1,6 +1,11 @@
+function plot_old_v_new(stat)
+% plot_old_v_new(stat)
+%
+% stat can be 'd' for d' or 'h' for hit rate minus FA rate.
+
data_dir = '~/Science/dan/data_and_figures/';
date_dirs = dir(data_dir);
-d_primes_by_task = cell(2, 1);
+stat_by_task = cell(2, 1);
for i = 3:length(date_dirs)
test_date = date_dirs(i).name;
if regexp(test_date, '[0-9]{6}')
@@ -20,27 +25,29 @@
responses = code_responses(words, codes);
hit_rates = responses(:, 1) ./ (responses(:, 1) + responses(:, 2));
FA_rates = responses(:, 4) ./ (responses(:, 4) + responses(:, 3));
- % When hit or FA rate is 1, d' is +Inf or -Inf, respectively.
- hit_rates(find(hit_rates == 1)) = 0.9999;
- FA_rates(find(FA_rates == 1)) = 0.9999;
- for k = 1:length(hit_rates)
- d_primes(k) = norminv(hit_rates(k),0,1) - ...
- norminv(FA_rates(k),0,1);
+ if strcmp(stat, 'd')
+ % When hit or FA rate is 1, d' is +Inf or -Inf, respectively.
+ hit_rates(find(hit_rates == 1)) = 0.9999;
+ FA_rates(find(FA_rates == 1)) = 0.9999;
+ for k = 1:length(hit_rates)
+ stat_val(k) = norminv(hit_rates(k),0,1) - ...
+ norminv(FA_rates(k),0,1);
+ end
+ else
+ stat_val = hit_rates' - FA_rates';
end
- d_primes_by_task{i_task} = [d_primes_by_task{i_task}; d_primes];
+ stat_by_task{i_task} = [stat_by_task{i_task}; stat_val];
end
end
end
figure;
contrasts = [0 20 40 100];
colors = 'rb';
-for i = 1:length(d_primes_by_task)
- d_primes = d_primes_by_task{i};
- mean_d_prime = mean(d_primes, 1);
- n = size(d_primes, 1);
- standard_error = std(d_primes) / sqrt(n);
- errorbar(contrasts, mean_d_prime, standard_error, colors(i), ...
- 'LineWidth', 2);
+for i = 1:length(stat_by_task)
+ stat_val = stat_by_task{i};
+ mean_stat = mean(stat_val, 1);
+ standard_error = std(stat_val) / sqrt(size(stat_val, 1));
+ errorbar(contrasts, mean_stat, standard_error, colors(i), 'LineWidth', 2)
hold on
end
set(gca, 'XTick', contrasts, 'FontSize', 20, 'XLim', [-10 110])
@@ -48,16 +55,24 @@
x_vals = [-2 18 38 98];
y_lim = ylim;
y_vals = y_lim(2) * [0.5 0.5 0.5 0.98];
-old_d_primes = d_primes_by_task{1};
-new_d_primes = d_primes_by_task{2};
+old_stat = stat_by_task{1};
+new_stat = stat_by_task{2};
for i = 1:length(contrasts)
- [h p] = ttest2(old_d_primes(:, i), new_d_primes(:, i));
+ [h p] = ttest2(old_stat(:, i), new_stat(:, i));
if p < 0.05
text(x_vals(i), y_vals(i), '*', 'FontSize', 40)
end
end
-ylabel('d''');
+if strcmp(stat, 'd')
+ ylabel('d''');
+else
+ ylabel('Hit Rate - FA Rate')
+end
xlabel('Contrast (%)')
legend('Old', 'New', 'Location', 'Best');
cd(data_dir)
-export_fig -painters -r600 -q101 old_v_new_d_primes_all.pdf
+if strcmp(stat, 'd')
+ export_fig -painters -r600 -q101 old_v_new_d_primes_all.pdf
+else
+ export_fig -painters -r600 -q101 old_v_new_hit_minus_FA_all.pdf
+end
View
29 plot_old_v_new_hit_minus_FA.m
@@ -1,29 +0,0 @@
-function plot_old_v_new_hit_minus_FA(hit_minus_FA_by_task, subject)
-
-data_dir = '~/Science/dan/data_and_figures/';
-figure;
-contrasts = [0 20 40 100];
-colors = 'rb';
-for i = 1:2
- n = size(hit_minus_FA_by_task{i}, 1);
- mean_hit_minus_FA = mean(hit_minus_FA_by_task{i}, 1);
- standard_error = std(hit_minus_FA_by_task{i}) / sqrt(n);
- errorbar(contrasts, mean_hit_minus_FA, standard_error, colors(i), ...
- 'LineWidth', 2);
- hold on
-end
-set(gca, 'XTick', contrasts, 'FontSize', 20, 'XLim', [-10 110])
-set(gcf, 'Color', 'w')
-if strcmp(subject, 'all')
- y_lim = ylim;
- text(18, y_lim(2)*0.82, '*', 'FontSize', 40)
-end
-ylabel('Hit Rate - FA Rate');
-xlabel('Contrast (%)')
-if ~strcmp(subject, 'all')
- title(subject);
-end
-legend('Old', 'New', 'Location', 'Best');
-cd(data_dir)
-eval(['export_fig -painters -r600 -q101 old_v_new_hit_minus_FA_' subject ...
- '.pdf'])
View
8 remove_nonlick_time.m
@@ -1,8 +0,0 @@
-function [responses contrasts] = remove_nonlick_time(responses, contrasts)
-% [responses contrasts] = remove_nonlick_time(responses, contrasts)
-
-% Use only the responses between the first and last lick.
-i_first_lick = find(responses == 1 | responses == 2, 1);
-i_last_lick = find(responses == 1 | responses == 2, 1, 'last');
-responses = responses(i_first_lick:i_last_lick);
-contrasts = contrasts(i_first_lick:i_last_lick);

0 comments on commit 633e1c8

Please sign in to comment.
Something went wrong with that request. Please try again.