Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
function [X, yc, pc, ynan, p, text_vars] = read_data(beh_type, lag,...
beh, dirstring, pats)
% This function was made to read in the data. The data function
% reads in the data as a table which reads in blanks as NaNs. It
% renames the variables as necessary and selects a subset of variables
% to analyze.
% It runs the cleaning and lagging data to provide an X and y dataset.
% Parameters:
% beh_type: 'AGG','SIB','BOTH' - the type of behavior
% lag: number of lagged days to examine; positive integer
% beh: whether or not to include prior behavior as a lagged variable
% (true or false)
% dirstring: a string to save out the directory
% pats: a string array of variable patterns, can be prefix to i
T = readtable(strcat(beh_type,'.csv'),...
'PreserveVariableNames',true);
T = renamevars(T,["BM_Menses"],["Menses"]);
if ~exist('beh','var')
beh = false;
end
A = {'Weather_TMAX',...
'Weather_TMIN',...
'Weather_PRCP',...
'Weather_SNOW',...
'Weather_SNWD',...
'Moon Rise',...
'Moon Culmination',...
'Moon Set',...
'Moon Altitude',...
'Moon Azimuth',...
'Moon Shadow Length',...
'Moon Distance',...
'Moon Phase',...
'Moon Age',...
'Moon Next New',...
'Moon Next Full',...
'Allergen_Trees',...
'Allergen_Weeds',...
'Allergen_Grasses',...
'Allergen_Total',...
'Sleep_Hours',...
'Sleep_Interruptions',...
'BM_Count',...
'BM_Bristol_Extreme',...
'BM_Bristol_Max',...
'BM_Bristol_Min',...
'BM_Bristol',...
'BM_Intervention',...
'BM_Time',...
'BM_Abnormal',...
'BM_Constipation',...
'BM_Diarrhea',...
'Menses'};
if beh
A{end+1} = 'Behavior_Factor';
pats = [pats, "Behavior_Factor"];
end
B = string(A);
T_X = table2array(T(:,B));
T_y = table2array(T(:,'Behavior_Factor'));
T_person = table2array(T(:,'Person_ID'));
% females = load('females.csv');
% non_females = setdiff(unique(T_person), females);
% %females = non_females;
% for i=1:length(females)
% subplot(round(length(females)/2),2,i)
% menses = T_X(T_person==females(i),end);
% plot(menses);
% hold on;
% unique(menses(~isnan(menses)))
% end
% error()
dataset = 'complete';
[Xc,yc,pc, ynan,p] = CleanUpData_lag(T_X,...
T_y,dataset,T_person,lag);
%X = zscore(Xc);
X = Xc;
vars = zeros(length(B),1);
for k=1:length(pats)
for i=1:length(B)
if startsWith(B(i), pats(k))
vars(i) = 1;
end
end
end
vars = logical(vars);
lagged_vars = [];
for i=1:lag
lagged_vars = [lagged_vars; vars];
end
lagged_vars = logical(lagged_vars);
text_vars = B(lagged_vars);
log_output(dirstring,string(text_vars));
size(lagged_vars)
writematrix(lagged_vars, strcat(dirstring,'/variables.txt'))
pause(3)
size(X)
X = X(:,lagged_vars);
size(X)
pause(2)
end