-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
672 changed files
with
104,542 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
% Not complete yet. Please edit me | ||
% | ||
% Function for adding a variable to a dataset in a systematic way. | ||
% - Checks IDs of subjects to make sure data is added in the correct order. | ||
% - Values for missing data are coded as missing values, as specified in dat.Description.Missing_Values | ||
% - Handles Subject_Level or Event_Level data | ||
|
||
varname = 'ValenceType'; | ||
var_to_add = SETUP.data.X; | ||
|
||
% get indices | ||
[subjn, ia, ib] = intersect(dat.Subj_Level.id, subjname2, 'stable'); | ||
|
||
wh_subjs = false(length(dat.Subj_Level.id)); | ||
wh_subjs(ia) = true; | ||
|
||
n = length(dat.Subj_Level.id); | ||
|
||
|
||
% set missing value | ||
missingval = dat.Description.Missing_Values; | ||
if ischar(missingval), missingval = str2num(missingval); | ||
|
||
|
||
nmissing = length(dat.Subj_Level.id) - length(ia); | ||
fprintf('Adding variable %s:\n\tSubjects with missing data: %d\n', varname, nmissing); | ||
|
||
nextra = length(subjname2) - length(ia); | ||
fprintf('\tSubjects not in dataset (will not be added): %d\n', nextra); | ||
|
||
is_subj_level = iscell(var_to_add); | ||
|
||
% Subject level | ||
% simplest case | ||
% -------------------------------------------------------------------- | ||
if is_subj_level | ||
|
||
newvar = repmat(missingval, n, 1); | ||
|
||
newvar(ia) = var_to_add(ib); | ||
|
||
return | ||
|
||
end | ||
|
||
% Event level | ||
% -------------------------------------------------------------------- | ||
|
||
for i = 1:n | ||
|
||
|
||
|
||
end | ||
|
||
|
||
str2num('NaN') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
function [dat, descrip, colors, h1, s1] = bars(obj, varnames, varargin) | ||
% | ||
% | ||
% Takes any optional inputs to barplot_colored.m | ||
% | ||
% Bar plot for canlab_dataset object | ||
% | ||
% Usage: | ||
% ------------------------------------------------------------------------- | ||
% [dat, descrip, colors, h1, s1] = bars(obj, varnames, varargin) | ||
% Takes any optional inputs to barplot_colored.m | ||
% | ||
% Author and copyright information: | ||
% ------------------------------------------------------------------------- | ||
% Copyright (C) 2013 Tor Wager | ||
% | ||
% This program is free software: you can redistribute it and/or modify | ||
% it under the terms of the GNU General Public License as published by | ||
% the Free Software Foundation, either version 3 of the License, or | ||
% (at your option) any later version. | ||
% | ||
% This program is distributed in the hope that it will be useful, | ||
% but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
% GNU General Public License for more details. | ||
% | ||
% You should have received a copy of the GNU General Public License | ||
% along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
% | ||
% Inputs: | ||
% ------------------------------------------------------------------------- | ||
% obj canlab_dataset object | ||
% varnames Cell string of variable names to plot | ||
% | ||
% Takes any optional inputs to barplot_colored.m | ||
% | ||
% Outputs: | ||
% ------------------------------------------------------------------------- | ||
% dat data matrix for each variable | ||
% | ||
% Examples: | ||
% ------------------------------------------------------------------------- | ||
% | ||
% create_figure('NPS values - All subjects'); | ||
% | ||
% varnames = {'15' '13' '11' ' 9' '16' '14' '12' '10'}; | ||
% xvals = [1 2 4 5 8 9 11 12]; | ||
% colors = {[1 0 0] [0 1 0] [1 0 0] [0 1 0] [1 0 0] [0 1 0] [1 0 0] [0 1 0]}; | ||
% bars(LevoNPS, varnames, 'x', xvals, 'colors', colors, 'XTickLabels', varnames, 'within', 'nofig'); | ||
% | ||
% | ||
% See also: | ||
% * list other functions related to this one, and alternatives* | ||
|
||
% Programmers' notes: | ||
% List dates and changes here, and author of changes | ||
|
||
n = length(varnames); | ||
colors = scn_standard_colors(n); | ||
|
||
|
||
% ------------------------------------------------------------------------- | ||
% DEFAULTS AND INPUTS | ||
% ------------------------------------------------------------------------- | ||
|
||
% optional inputs with default values | ||
% ----------------------------------- | ||
% - allowable_args is a cell array of argument names | ||
% - avoid spaces, special characters, and names of existing functions | ||
% - variables will be assigned based on these names | ||
% i.e., if you use an arg named 'cl', a variable called cl will be | ||
% created in the workspace | ||
|
||
allowable_args = {'colors' 'nofig'}; | ||
|
||
default_values = {colors [0]}; | ||
|
||
% define actions for each input | ||
% ----------------------------------- | ||
% - cell array with one cell for each allowable argument | ||
% - these have special meanings in the code below | ||
% - allowable actions for inputs in the code below are: 'assign_next_input' or 'flag_on' | ||
|
||
actions = {'assign_next_input' 'flag_on'}; | ||
|
||
% logical vector and indices of which inputs are text | ||
textargs = cellfun(@ischar, varargin); | ||
whtextargs = find(textargs); | ||
|
||
for i = 1:length(allowable_args) | ||
|
||
% assign default | ||
% ------------------------------------------------------------------------- | ||
|
||
eval([allowable_args{i} ' = default_values{i};']); | ||
|
||
wh = strcmp(allowable_args{i}, varargin(textargs)); | ||
|
||
if any(wh) | ||
% Optional argument has been entered | ||
% ------------------------------------------------------------------------- | ||
|
||
wh = whtextargs(wh); | ||
if length(wh) > 1, warning(['input ' allowable_args{i} ' is duplicated.']); end | ||
|
||
switch actions{i} | ||
case 'assign_next_input' | ||
eval([allowable_args{i} ' = varargin{wh(1) + 1};']); | ||
varargin{wh(1) + 1} = []; | ||
|
||
case 'flag_on' | ||
eval([allowable_args{i} ' = 1;']); | ||
|
||
otherwise | ||
error(['Coding bug: Illegal action for argument ' allowable_args{i}]) | ||
end | ||
|
||
end % argument is input | ||
end | ||
|
||
% END DEFAULTS AND INPUTS | ||
% ------------------------------------------------------------------------- | ||
|
||
% REST OF BAR PLOT | ||
|
||
|
||
[dat, ~, ~, descrip] = get_var(obj, varnames, varargin{:}); | ||
|
||
descrip = cat(1, descrip{:}); | ||
|
||
|
||
colors = cat(1, colors{:}); | ||
|
||
xvals = 1:n; | ||
|
||
if nofig | ||
else | ||
|
||
create_figure('bars'); | ||
end | ||
|
||
[h1, s1] = barplot_colored(dat, varargin{:}); | ||
% set(h2, 'BarWidth', .9) | ||
colormap(colors) | ||
|
||
fprintf('T-tests against zero\n'); | ||
fprintf('Description\tt(%3.0f)\tp\n', size(dat, 1) - 1); | ||
|
||
% Print table - t-test against zero | ||
for i = 1:n | ||
[h, p, ci, stats] = ttest(dat(:, i)); | ||
if p < .001, str = '***'; | ||
elseif p < .01, str = '**'; | ||
elseif p < .05, str = '*'; | ||
elseif p < .10, str = '+'; | ||
else str = ' '; | ||
end | ||
|
||
fprintf('%s\t%3.2f\t%3.6f\t%s\n', descrip{i}, stats.tstat, p, str); | ||
end | ||
|
||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
% D = canlab_dataset(); | ||
% | ||
% Constructs a new, empty instance of a canlab_dataset object. | ||
% The fields of this object can subsequently be assigned data. | ||
% | ||
% The dataset (D) The dataset (D) is a way of collecting behavioral data | ||
% and/or meta-data about fMRI (and other) studies in a standardized format. | ||
% It has entries for experiment description, Subject-level | ||
% variables, Event-level variables (e.g., for fMRI events or trials in a | ||
% behavioral experiment) and other fields for sub-event level data (e.g., | ||
% physio or continuous ratings within trials). | ||
% | ||
% See D.Description for some basic info. | ||
% | ||
% Dataset methods include: | ||
% | ||
% write_text -> writes a flat text file (data across all subjects) | ||
% concatenate -> returns flat matrix of data across all subjects to the workspace | ||
% get_var -> get event-level data from one variable and return in matrix and cell formats | ||
% scatterplot -> standard or multi-line scatterplot of relationship between two variables | ||
% scattermatrix -> Scatterplot matrix of pairwise event-level variables | ||
% | ||
% - type methods(canlab_dataset) for a list of all methods | ||
% | ||
% Copyright Tor Wager, 2013 | ||
|
||
classdef canlab_dataset | ||
|
||
properties | ||
|
||
% Build a dataset containing the key variables | ||
|
||
|
||
Description = struct('Experiment_Name', [], 'Missing_Values', [], 'Subj_Level', [], 'Event_Level', []); | ||
|
||
Subj_Level = struct('id', cell(1), 'names', cell(1), 'type', cell(1), 'units', cell(1), 'descrip', cell(1), 'data', []); | ||
|
||
Event_Level = struct('names', cell(1), 'type', cell(1), 'units', cell(1), 'descrip', cell(1), 'data', cell(1)); | ||
|
||
Sub_Event_Level = struct('names', cell(1), 'type', cell(1), 'units', cell(1), 'descrip', cell(1), 'data', cell(1)); | ||
|
||
Continuous = struct('names', cell(1), 'type', cell(1), 'units', cell(1), 'descrip', cell(1), 'data', cell(1)); | ||
|
||
wh_keep = struct(); | ||
|
||
end % properties | ||
|
||
%% Subject-level data | ||
|
||
methods | ||
|
||
% Class constructor | ||
function obj = canlab_dataset(varargin) | ||
|
||
obj.Description.Subj_Level{1, 1} = 'id: Unique text identifier for each subject (e.g., subject code)'; | ||
|
||
obj.Description.Subj_Level{2, 1} = 'data: cell array, one cell per subject, with rectangular data matrix.'; | ||
obj.Description.Subj_Level{3, 1} = ' Each row is one event, each column a variable, with names in .names'; | ||
|
||
obj.Description.Event_Level{1, 1} = 'data: cell array, one cell per subject, with rectangular data matrix.'; | ||
obj.Description.Event_Level{2, 1} = ' Each row is one event, each column a variable, with names in .names'; | ||
|
||
|
||
end % constructor function | ||
|
||
end % methods | ||
|
||
|
||
end % classdef | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
function [names, ids, dat, descrips] = concatenate(D, varargin) | ||
% | ||
% Concatenates Subject-level and Event-level data across all subjects | ||
% | ||
% [names ids dat] = concatenate(D) | ||
% | ||
% INPUT: | ||
% D: canlab_dataset | ||
% varargin: currently accepts a wh_keep (logical array) | ||
% | ||
% OUTPUT: | ||
% Names: cell array of variable names | ||
% | ||
% Descrip: cell array of variable descriptions | ||
% | ||
% ids: subject IDs matching data rows in dat | ||
% | ||
% dat: subjects*events x variables matrix | ||
% | ||
% - subject number, event number are included | ||
% - all subject-level and event-level data are included | ||
% - this format appropriate for, e.g., SAS/HLM | ||
% | ||
% Examples: | ||
% [names, ids, flatdat] = concatenate(D); | ||
% id_numbers = flatdat(:, 1); | ||
% | ||
% wh_subjs = true(size(D.Subj_Level.id)); | ||
% wh_subjs([13 18 19]) = false; | ||
% [names, ids, dat] = concatenate(D, wh_subjs); | ||
% | ||
% % Copyright Tor Wager, 2013 | ||
|
||
% select subjects | ||
wh_ids = true(length(D.Subj_Level.id), 1); | ||
if length(varargin) > 0, wh_ids = logical(varargin{1}); end | ||
whfind = find(wh_ids); | ||
|
||
names = {'subj_num' D.Subj_Level.names{:} 'Event_number' D.Event_Level.names{:}}; | ||
descrips = {'subj_num' D.Subj_Level.descrip{:} 'Event_number' D.Event_Level.descrip{:}}; | ||
|
||
|
||
n = length(D.Subj_Level.id(wh_ids)); | ||
|
||
x = D.Event_Level.data(wh_ids); | ||
|
||
|
||
for i = 1:n | ||
|
||
e = size(D.Event_Level.data{whfind(i)}, 1); | ||
|
||
ids{i} = repmat(D.Subj_Level.id{whfind(i)}, e, 1); | ||
|
||
% subj ID subj level data trialID event data | ||
x{i} = [repmat(i, e, 1) repmat(D.Subj_Level.data(whfind(i), :), e, 1) (1:e)' x{i}]; | ||
|
||
end | ||
|
||
ids = strvcat(ids{:}); | ||
|
||
dat = cat(1, x{:}); | ||
|
||
end % function |
Oops, something went wrong.