-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaptIncludePredInteractionTerms.m
More file actions
50 lines (40 loc) · 1.79 KB
/
aptIncludePredInteractionTerms.m
File metadata and controls
50 lines (40 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function [predX,predNames] = aptIncludePredInteractionTerms
% apt.predInteraction contains a string of TERM1*TERM2 with TERM1 and TERM2
% existing predictors.
global apt
if ~isfield(apt.pred,'InteractionTerms')
return
end
if isfield(apt.config,'knownSequences')
idxCategories = find(~(cellfun(@isempty,strfind(apt.predNames,'a13'))&cellfun(@isempty,strfind(apt.predNames,'b6'))));
idxSeqSpec = find(~(cellfun(@isempty,strfind(apt.predNames,'G'))&cellfun(@isempty,strfind(apt.predNames,'T')) ...
&cellfun(@isempty,strfind(apt.predNames,'C'))&cellfun(@isempty,strfind(apt.predNames,'A'))));
idxSeqSpec = setdiff(idxSeqSpec,find(~cellfun(@isempty,strfind(apt.predNames,'Array'))));
moreInteractions = cell(length(idxCategories)*length(idxSeqSpec),1);
counter = 1;
for iC = 1:length(idxCategories)
for iS = 1:length(idxSeqSpec)
moreInteractions{counter} = [apt.predNames{idxCategories(iC)} '*' apt.predNames{idxSeqSpec(iS)}];
counter = counter + 1;
end
end
if isempty(apt.pred.InteractionTerms)
apt.pred.InteractionTerms = moreInteractions;
else
apt.pred.InteractionTerms = [apt.pred.InteractionTerms;moreInteractions];
end
end
for iInteraction = 1:length(apt.pred.InteractionTerms)
intTerms = strsplit(apt.pred.InteractionTerms{iInteraction},'*');
idx1 = find(strcmp(apt.predNames,intTerms{1}));
idx2 = find(strcmp(apt.predNames,intTerms{2}));
if length(idx1)~= 1 || length(idx2)~= 1
error('Interaction terms are ambiguous!')
end
XInteraction(:,iInteraction) = apt.predX(idx1,:).*apt.predX(idx2,:);
end
for iInteraction = 1:length(apt.pred.InteractionTerms)
apt.predNames{end+1} = ['Int_' apt.pred.InteractionTerms{iInteraction}];
end
apt.predX = [apt.predX; XInteraction'];
end