From efd1762af1ab50dd7d475319b063d88974b483a5 Mon Sep 17 00:00:00 2001 From: Kelly Ruggles Date: Fri, 14 Nov 2014 10:41:02 -0500 Subject: [PATCH] CDC updates OR --- heatmaps/demographics_2013_CI.m | 621 ++++++++++++++ heatmaps/run_demographics_2013.m | 45 + odds_ratio/OR_2013_categorical.m | 154 ++++ odds_ratio/create_RR_OR_2013_CI.m | 169 ++++ odds_ratio/create_RR_OR_2013_CI_black.m | 188 +++++ odds_ratio/create_RR_OR_2013_CI_boys.m | 188 +++++ odds_ratio/create_RR_OR_2013_CI_categorical.m | 214 +++++ odds_ratio/create_RR_OR_2013_CI_cluster.m | 169 ++++ odds_ratio/create_RR_OR_2013_CI_girls.m | 188 +++++ odds_ratio/create_RR_OR_2013_CI_hispanic.m | 188 +++++ odds_ratio/create_RR_OR_2013_CI_race_sex.m | 214 +++++ odds_ratio/create_RR_OR_2013_CI_white.m | 188 +++++ odds_ratio/process_cluster_OR_CI.m | 64 ++ .../process_cluster_OR_CI_WHITE_girls.m | 41 + odds_ratio/process_cluster_OR_CI_girls.m | 41 + odds_ratio/run_OR_2013_categorical_activity.m | 6 + odds_ratio/run_OR_2013_categorical_gun.m | 4 + odds_ratio/run_OR_2013_categorical_violence.m | 10 + prescriptiondrugs/OR_plot_Rxdrugs_table.m | 71 ++ prescriptiondrugs/PO_freqv2.m | 18 +- prescriptiondrugs/PO_freqv3.m | 260 ++++++ prescriptiondrugs/heroin_freqv3.m | 262 ++++++ prescriptiondrugs/injected_freqv3.m | 262 ++++++ sleep/sleep_boys_girls_2013_CI_FINAL.m | 769 ++++++++++++++++++ sleep/sleep_boys_girls_2013_CI_v2.m | 262 ++++++ sleep/sleep_comparisons.m | 2 +- sleep/sleep_comparisonsv2.m | 177 ++++ 27 files changed, 4757 insertions(+), 18 deletions(-) create mode 100644 heatmaps/demographics_2013_CI.m create mode 100644 heatmaps/run_demographics_2013.m create mode 100644 odds_ratio/OR_2013_categorical.m create mode 100644 odds_ratio/create_RR_OR_2013_CI.m create mode 100644 odds_ratio/create_RR_OR_2013_CI_black.m create mode 100644 odds_ratio/create_RR_OR_2013_CI_boys.m create mode 100644 odds_ratio/create_RR_OR_2013_CI_categorical.m create mode 100644 odds_ratio/create_RR_OR_2013_CI_cluster.m create mode 100644 odds_ratio/create_RR_OR_2013_CI_girls.m create mode 100644 odds_ratio/create_RR_OR_2013_CI_hispanic.m create mode 100644 odds_ratio/create_RR_OR_2013_CI_race_sex.m create mode 100644 odds_ratio/create_RR_OR_2013_CI_white.m create mode 100644 odds_ratio/process_cluster_OR_CI.m create mode 100644 odds_ratio/process_cluster_OR_CI_WHITE_girls.m create mode 100644 odds_ratio/process_cluster_OR_CI_girls.m create mode 100644 odds_ratio/run_OR_2013_categorical_activity.m create mode 100644 odds_ratio/run_OR_2013_categorical_gun.m create mode 100644 odds_ratio/run_OR_2013_categorical_violence.m create mode 100644 prescriptiondrugs/OR_plot_Rxdrugs_table.m create mode 100644 prescriptiondrugs/PO_freqv3.m create mode 100644 prescriptiondrugs/heroin_freqv3.m create mode 100644 prescriptiondrugs/injected_freqv3.m create mode 100644 sleep/sleep_boys_girls_2013_CI_FINAL.m create mode 100644 sleep/sleep_boys_girls_2013_CI_v2.m create mode 100644 sleep/sleep_comparisonsv2.m diff --git a/heatmaps/demographics_2013_CI.m b/heatmaps/demographics_2013_CI.m new file mode 100644 index 0000000..5a0a61a --- /dev/null +++ b/heatmaps/demographics_2013_CI.m @@ -0,0 +1,621 @@ + function [conf_mat, total, x_mat, n_mat, conf_mat2] = demographics_2013_CI( question_mat, race, sex, grade, weight, years ) + + %resize and deal with the number of years in each + [r,c]=size(question_mat); + label_=question_mat(:,1); + question_mat=question_mat(:,2:c); + sex=sex(:,2:c); + race=race(:,2:c); + weight=weight(:,2:c); + [r,c]=size(question_mat); + minimum=1; + maximum=max(max(question_mat)); + cat_n=maximum; + conf_mat=cell(76,cat_n,r); %(demographics, number categorical responses, years) + n_mat=zeros(75,r); %total number for conf_mat calculation + x_mat=zeros(75,cat_n,r); %number in that categoriy for conf_mat + + %set up matrices + for i=1:r + count=2; + conf_mat{1,1,i}=years(i); + for j=minimum:maximum; + conf_mat{1,count,i}=j; + count=count+1; + end + conf_mat{2,1,i}='total'; + conf_mat{3,1,i}='girls'; + conf_mat{4,1,i}='boys'; + conf_mat{5,1,i}='W'; + conf_mat{6,1,i}='B'; + conf_mat{7,1,i}='H'; + conf_mat{8,1,i}='O'; + conf_mat{9,1,i}='9'; + conf_mat{10,1,i}='10'; + conf_mat{11,1,i}='11'; + conf_mat{12,1,i}='12'; + + conf_mat{13,1,i}='Wg'; + conf_mat{14,1,i}='Wb'; + conf_mat{15,1,i}='Bg'; + conf_mat{16,1,i}='Bb'; + conf_mat{17,1,i}='Hg'; + conf_mat{18,1,i}='Hb'; + conf_mat{19,1,i}='Og'; + conf_mat{20,1,i}='Ob'; + + conf_mat{21,1,i}='9g'; + conf_mat{22,1,i}='9b'; + conf_mat{23,1,i}='10g'; + conf_mat{24,1,i}='10b'; + conf_mat{25,1,i}='11g'; + conf_mat{26,1,i}='11b'; + conf_mat{27,1,i}='12g'; + conf_mat{28,1,i}='12b'; + + conf_mat{29,1,i}='W9'; + conf_mat{30,1,i}='W10'; + conf_mat{31,1,i}='W11'; + conf_mat{32,1,i}='W12'; + conf_mat{33,1,i}='B9'; + conf_mat{34,1,i}='B10'; + conf_mat{35,1,i}='B11'; + conf_mat{36,1,i}='B12'; + conf_mat{37,1,i}='H9'; + conf_mat{38,1,i}='H10'; + conf_mat{39,1,i}='H11'; + conf_mat{40,1,i}='H12'; + conf_mat{41,1,i}='O9'; + conf_mat{42,1,i}='O10'; + conf_mat{43,1,i}='O11'; + conf_mat{44,1,i}='O12'; + + conf_mat{45,1,i}='W9g'; + conf_mat{46,1,i}='W10g'; + conf_mat{47,1,i}='W11g'; + conf_mat{48,1,i}='W12g'; + conf_mat{49,1,i}='W9b'; + conf_mat{50,1,i}='W10b'; + conf_mat{51,1,i}='W11b'; + conf_mat{52,1,i}='W12b'; + + conf_mat{53,1,i}='B9g'; + conf_mat{54,1,i}='B10g'; + conf_mat{55,1,i}='B11g'; + conf_mat{56,1,i}='B12g'; + conf_mat{57,1,i}='B9b'; + conf_mat{58,1,i}='B10b'; + conf_mat{59,1,i}='B11b'; + conf_mat{60,1,i}='B12b'; + + conf_mat{61,1,i}='H9g'; + conf_mat{62,1,i}='H10g'; + conf_mat{63,1,i}='H11g'; + conf_mat{64,1,i}='H12g'; + conf_mat{65,1,i}='H9b'; + conf_mat{66,1,i}='H10b'; + conf_mat{67,1,i}='H11b'; + conf_mat{68,1,i}='H12b'; + + conf_mat{69,1,i}='O9g'; + conf_mat{70,1,i}='O10g'; + conf_mat{71,1,i}='O11g'; + conf_mat{72,1,i}='O12g'; + conf_mat{73,1,i}='O9b'; + conf_mat{74,1,i}='O10b'; + conf_mat{75,1,i}='O11b'; + conf_mat{76,1,i}='O12b'; + + end + total=conf_mat; + for i=1:r + index_girls{i}=find(sex(i,:)==1); + index_boys{i}=find(sex(i,:)==2); + index_W{i}=find(race(i,:)== 1 ); + index_B{i}=find(race(i,:)== 2 ); + index_H{i}=find(race(i,:)== 3 ); + index_O{i}=find(race(i,:)== 4 ); + index_9{i}=find(grade(i,:)== 1 ); + index_10{i}=find(grade(i,:)== 2 ); + index_11{i}=find(grade(i,:)== 3 ); + index_12{i}=find(grade(i,:)== 4 ); + + index_W9{i}=intersect(index_9{i},index_W{i}); + index_W10{i}=intersect(index_10{i},index_W{i}); + index_W11{i}=intersect(index_11{i},index_W{i}); + index_W12{i}=intersect(index_12{i},index_W{i}); + + index_B9{i}=intersect(index_9{i},index_B{i}); + index_B10{i}=intersect(index_10{i},index_B{i}); + index_B11{i}=intersect(index_11{i},index_B{i}); + index_B12{i}=intersect(index_12{i},index_B{i}); + + index_H9{i}=intersect(index_9{i},index_H{i}); + index_H10{i}=intersect(index_10{i},index_H{i}); + index_H11{i}=intersect(index_11{i},index_H{i}); + index_H12{i}=intersect(index_12{i},index_H{i}); + + index_O9{i}=intersect(index_9{i},index_O{i}); + index_O10{i}=intersect(index_10{i},index_O{i}); + index_O11{i}=intersect(index_11{i},index_O{i}); + index_O12{i}=intersect(index_12{i},index_O{i}); + + index_missQ{i}=find(question_mat(i,:)== 0); %students who didn't answer the Q + index_nomiss{i}=find(question_mat(i,:)>0); %answers that were NOT missing (ie. 0's and 1's / no's and yes's) + + index_total_b{i}=intersect(index_nomiss{i},index_boys{i}); %index of all boys who answered + index_total_g{i}=intersect(index_nomiss{i},index_girls{i}); %index of all girls who answered + + w=weight(i,:)'; + total_ans(i)=nansum(w(index_nomiss{i})); + total_girls(i)=nansum(w(index_total_g{i})); %total # of girls who answered + total_boys(i)=nansum(w(index_total_b{i})); %total number of boys who answered + total_W{i}=nansum(w(intersect(index_nomiss{i}, index_W{i}))); %total # of white students who answered + total_B{i}=nansum(w(intersect(index_nomiss{i}, index_B{i}))); %total # of black students who answered + total_H{i}=nansum(w(intersect(index_nomiss{i}, index_H{i}))); %total # of hispanic students who answered + total_O{i}=nansum(w(intersect(index_nomiss{i}, index_O{i}))); %total # of "other" students who answered + + total_w(i)=total_W{i}; + total_b(i)=total_B{i}; + total_h(i)=total_H{i}; + total_o(i)=total_O{i}; + + total_Wb(i)=nansum(w(intersect(index_total_b{i},index_W{i}))); + total_Wg(i)=nansum(w(intersect(index_total_g{i},index_W{i}))); + total_Bb(i)=nansum(w(intersect(index_total_b{i},index_B{i}))); + total_Bg(i)=nansum(w(intersect(index_total_g{i},index_B{i}))); + total_Hb(i)=nansum(w(intersect(index_total_b{i},index_H{i}))); + total_Hg(i)=nansum(w(intersect(index_total_g{i},index_H{i}))); + total_Ob(i)=nansum(w(intersect(index_total_b{i},index_O{i}))); + total_Og(i)=nansum(w(intersect(index_total_g{i},index_O{i}))); + total_9(i)=nansum(w(intersect((index_9{i}),index_nomiss{i}))); + total_10(i)=nansum(w(intersect((index_10{i}),index_nomiss{i}))); + total_11(i)=nansum(w(intersect((index_11{i}),index_nomiss{i}))); + total_12(i)=nansum(w(intersect((index_12{i}),index_nomiss{i}))); + + total_9G(i)=nansum(w(intersect(index_9{i},index_total_g{i}))); + total_10G(i)=nansum(w(intersect(index_10{i},index_total_g{i}))); + total_11G(i)=nansum(w(intersect(index_11{i},index_total_g{i}))); + total_12G(i)=nansum(w(intersect(index_12{i},index_total_g{i}))); + + total_9B(i)=nansum(w(intersect(index_9{i},index_total_b{i}))); + total_10B(i)=nansum(w(intersect(index_10{i},index_total_b{i}))); + total_11B(i)=nansum(w(intersect(index_11{i},index_total_b{i}))); + total_12B(i)=nansum(w(intersect(index_12{i},index_total_b{i}))); + + total_9G_W(i)=nansum(w(intersect(index_W9{i},index_total_g{i}))); + total_9B_W(i)=nansum(w(intersect(index_W9{i},index_total_b{i}))); + total_9G_B(i)=nansum(w(intersect(index_B9{i},index_total_g{i}))); + total_9B_B(i)=nansum(w(intersect(index_B9{i},index_total_b{i}))); + + total_9G_H(i)=nansum(w(intersect(index_H9{i},index_total_g{i}))); + total_9B_H(i)=nansum(w(intersect(index_H9{i},index_total_b{i}))); + total_9G_O(i)=nansum(w(intersect(index_O9{i},index_total_g{i}))); + total_9B_O(i)=nansum(w(intersect(index_O9{i},index_total_b{i}))); + + total_10G_W(i)=nansum(w(intersect(index_W10{i},index_total_g{i}))); + total_10B_W(i)=nansum(w(intersect(index_W10{i},index_total_b{i}))); + total_10G_B(i)=nansum(w(intersect(index_B10{i},index_total_g{i}))); + total_10B_B(i)=nansum(w(intersect(index_B10{i}, index_total_b{i}))); + + total_10G_H(i)=nansum(w(intersect(index_H10{i},index_total_g{i}))); + total_10B_H(i)=nansum(w(intersect(index_H10{i},index_total_b{i}))); + total_10G_O(i)=nansum(w(intersect(index_O10{i},index_total_g{i}))); + total_10B_O(i)=nansum(w(intersect(index_O10{i},index_total_b{i}))); + + total_11G_W(i)=nansum(w(intersect(index_W11{i},index_total_g{i}))); + total_11B_W(i)=nansum(w(intersect(index_W11{i},index_total_b{i}))); + total_11G_B(i)=nansum(w(intersect(index_B11{i},index_total_g{i}))); + total_11B_B(i)=nansum(w(intersect(index_B11{i},index_total_b{i}))); + + total_11G_H(i)=nansum(w(intersect(index_H11{i},index_total_g{i}))); + total_11B_H(i)=nansum(w(intersect(index_H11{i},index_total_b{i}))); + total_11G_O(i)=nansum(w(intersect(index_O11{i},index_total_g{i}))); + total_11B_O(i)=nansum(w(intersect(index_O11{i},index_total_b{i}))); + + total_12G_W(i)=nansum(w(intersect(index_W12{i},index_total_g{i}))); + total_12B_W(i)=nansum(w(intersect(index_W12{i},index_total_b{i}))); + total_12G_B(i)=nansum(w(intersect(index_B12{i},index_total_g{i}))); + total_12B_B(i)=nansum(w(intersect(index_B12{i},index_total_b{i}))); + + total_12G_H(i)=nansum(w(intersect(index_H12{i},index_total_g{i}))); + total_12B_H(i)=nansum(w(intersect(index_H12{i},index_total_b{i}))); + total_12G_O(i)=nansum(w(intersect(index_O12{i},index_total_g{i}))); + total_12B_O(i)=nansum(w(intersect(index_O12{i},index_total_b{i}))); + + total_9_W(i)=nansum(w(intersect(index_nomiss{i},index_W9{i}))); + total_9_B(i)=nansum(w(intersect(index_nomiss{i},index_B9{i}))); + total_9_H(i)=nansum(w(intersect(index_nomiss{i},index_H9{i}))); + total_9_O(i)=nansum(w(intersect(index_nomiss{i},index_O9{i}))); + + total_10_W(i)=nansum(w(intersect(index_nomiss{i},index_W10{i}))); + total_10_B(i)=nansum(w(intersect(index_nomiss{i},index_B10{i}))); + total_10_H(i)=nansum(w(intersect(index_nomiss{i},index_H10{i}))); + total_10_O(i)=nansum(w(intersect(index_nomiss{i},index_O10{i}))); + + total_11_W(i)=nansum(w(intersect(index_nomiss{i},index_W11{i}))); + total_11_B(i)=nansum(w(intersect(index_nomiss{i},index_B11{i}))); + total_11_H(i)=nansum(w(intersect(index_nomiss{i},index_H11{i}))); + total_11_O(i)=nansum(w(intersect(index_nomiss{i},index_O11{i}))); + + total_12_W(i)=nansum(w(intersect(index_nomiss{i},index_W12{i}))); + total_12_B(i)=nansum(w(intersect(index_nomiss{i},index_B12{i}))); + total_12_H(i)=nansum(w(intersect(index_nomiss{i},index_H12{i}))); + total_12_O(i)=nansum(w(intersect(index_nomiss{i},index_O12{i}))); + %for stats fihnd total in each year + n_mat (1,i)= total_ans(i); + n_mat (2,i)=total_girls(i); + n_mat (3,i)=total_boys(i); + n_mat (4,i)=total_w(i); + n_mat (5,i)=total_b(i); + n_mat (6,i)=total_h(i); + n_mat (7,i)=total_o(i); + n_mat (8,i)=total_9(i); + n_mat (9,i)=total_10(i); + n_mat (10,i)=total_11(i); + n_mat (11,i)=total_12(i); + + n_mat (12,i)=total_Wg(i); + n_mat (13,i)=total_Wb(i); + n_mat (14,i)=total_Bg(i); + n_mat (15,i)=total_Bb(i); + n_mat (16,i)=total_Hg(i); + n_mat (17,i)=total_Hb(i); + n_mat (18,i)=total_Og(i); + n_mat (19,i)=total_Ob(i); + + n_mat (20,i)=total_9G(i); + n_mat (21,i)=total_9B(i); + n_mat (22,i)=total_10G(i); + n_mat (23,i)=total_10B(i); + n_mat (24,i)=total_11G(i); + n_mat (25,i)=total_11B(i); + n_mat (26,i)=total_12G(i); + n_mat (27,i)=total_12B(i); + + n_mat (28,i)=total_9_W(i); + n_mat (29,i)=total_10_W(i); + n_mat (30,i)=total_11_W(i); + n_mat (31,i)=total_12_W(i); + n_mat (32,i)=total_9_B(i); + n_mat (33,i)=total_10_B(i); + n_mat (34,i)=total_11_B(i); + n_mat (35,i)=total_12_B(i); + n_mat (36,i)=total_9_H(i); + n_mat (37,i)=total_10_H(i); + n_mat (38,i)=total_11_H(i); + n_mat (39,i)=total_12_H(i); + n_mat (40,i)=total_9_O(i); + n_mat (41,i)=total_10_O(i); + n_mat (42,i)=total_11_O(i); + n_mat (43,i)=total_12_O(i); + + n_mat (44,i)=total_9G_W(i); + n_mat (45,i)=total_10G_W(i); + n_mat (46,i)=total_11G_W(i); + n_mat (47,i)=total_12G_W(i); + n_mat (48,i)=total_9B_W(i); + n_mat (49,i)=total_10B_W(i); + n_mat (50,i)=total_11B_W(i); + n_mat (51,i)=total_12B_W(i); + + n_mat (52,i)=total_9G_B(i); + n_mat (53,i)=total_10G_B(i); + n_mat (54,i)=total_11G_B(i); + n_mat (55,i)=total_12G_B(i); + n_mat (56,i)=total_9B_B(i); + n_mat (57,i)=total_10B_B(i); + n_mat (58,i)=total_11B_B(i); + n_mat (59,i)=total_12B_B(i); + + n_mat (60,i)=total_9G_H(i); + n_mat (61,i)=total_10G_H(i); + n_mat (62,i)=total_11G_H(i); + n_mat (63,i)=total_12G_H(i); + n_mat (64,i)=total_9B_H(i); + n_mat (65,i)=total_10B_H(i); + n_mat (66,i)=total_11B_H(i); + n_mat (67,i)=total_12B_H(i); + + n_mat (68,i)=total_9G_O(i); + n_mat (69,i)=total_10G_O(i); + n_mat (70,i)=total_11G_O(i); + n_mat (71,i)=total_12G_O(i); + n_mat (72,i)=total_9B_O(i); + n_mat (73,i)=total_10B_O(i); + n_mat (74,i)=total_11B_O(i); + n_mat (75,i)=total_12B_O(i); + + %************************************** + w=weight(i,:)'; + count=1; + for j=minimum:maximum + index_yes{i}=find(question_mat(i,:)==j); + index_yesgirls{i}=intersect(index_yes{i},index_girls{i}); + index_yesboys{i}=intersect(index_yes{i},index_boys{i}); + yes_girls(i)=nansum(w(index_yesgirls{i})); + yes_boys(i)=nansum(w(index_yesboys{i})); + total_yes(i)=nansum(w(index_yes{i})); + yes_W(i)=nansum(w(intersect(index_yes{i}, index_W{i}))); + yes_B(i)=nansum(w(intersect(index_yes{i}, index_B{i}))); + yes_H(i)=nansum(w(intersect(index_yes{i}, index_H{i}))); + yes_O(i)=nansum(w(intersect(index_yes{i}, index_O{i}))); + yes_WG(i)=nansum(w(intersect(index_yesgirls{i},index_W{i}))); + yes_BG(i)=nansum(w(intersect(index_yesgirls{i},index_B{i}))); + yes_HG(i)=nansum(w(intersect(index_yesgirls{i},index_H{i}))); + yes_OG(i)=nansum(w(intersect(index_yesgirls{i},index_O{i}))); + yes_WB(i)=nansum(w(intersect(index_yesboys{i},index_W{i}))); + yes_BB(i)=nansum(w(intersect(index_yesboys{i},index_B{i}))); + yes_HB(i)=nansum(w(intersect(index_yesboys{i},index_H{i}))); + yes_OB(i)=nansum(w(intersect(index_yesboys{i},index_O{i}))); + yes_9(i)=nansum(w(intersect(index_yes{i},index_9{i}))); + yes_10(i)=nansum(w(intersect(index_yes{i},index_10{i}))); + yes_11(i)=nansum(w(intersect(index_yes{i},index_11{i}))); + yes_12(i)=nansum(w(intersect(index_yes{i},index_12{i}))); + yes_9b(i)=nansum(w(intersect(index_yesboys{i},index_9{i}))); + yes_10b(i)=nansum(w(intersect(index_yesboys{i},index_10{i}))); + yes_11b(i)=nansum(w(intersect(index_yesboys{i},index_11{i}))); + yes_12b(i)=nansum(w(intersect(index_yesboys{i},index_12{i}))); + yes_9g(i)=nansum(w(intersect(index_yesgirls{i},index_9{i}))); + yes_10g(i)=nansum(w(intersect(index_yesgirls{i},index_10{i}))); + yes_11g(i)=nansum(w(intersect(index_yesgirls{i},index_11{i}))); + yes_12g(i)=nansum(w(intersect(index_yesgirls{i},index_12{i}))); + + + yes_9WB(i)=nansum(w(intersect(index_yesboys{i},index_W9{i}))); + yes_10WB(i)=nansum(w(intersect(index_yesboys{i},index_W10{i}))); + yes_11WB(i)=nansum(w(intersect(index_yesboys{i},index_W11{i}))); + yes_12WB(i)=nansum(w(intersect(index_yesboys{i},index_W12{i}))); + yes_9WG(i)=nansum(w(intersect(index_yesgirls{i},index_W9{i}))); + yes_10WG(i)=nansum(w(intersect(index_yesgirls{i},index_W10{i}))); + yes_11WG(i)=nansum(w(intersect(index_yesgirls{i},index_W11{i}))); + yes_12WG(i)=nansum(w(intersect(index_yesgirls{i},index_W12{i}))); + + yes_9W(i)=nansum(w(intersect(index_yes{i},index_W9{i}))); + yes_10W(i)=nansum(w(intersect(index_yes{i},(index_W10{i})))); + yes_11W(i)=nansum(w(intersect(index_yes{i},(index_W11{i})))); + yes_12W(i)=nansum(w(intersect(index_yes{i},(index_W12{i})))); + + yes_9B(i)=nansum(w(intersect(index_yes{i},(index_B9{i})))); + yes_10B(i)=nansum(w(intersect(index_yes{i},(index_B10{i})))); + yes_11B(i)=nansum(w(intersect(index_yes{i},(index_B11{i})))); + yes_12B(i)=nansum(w(intersect(index_yes{i},(index_B12{i})))); + + yes_9H(i)=nansum(w(intersect(index_yes{i},(index_H9{i})))); + yes_10H(i)=nansum(w(intersect(index_yes{i},(index_H10{i})))); + yes_11H(i)=nansum(w(intersect(index_yes{i},(index_H11{i})))); + yes_12H(i)=nansum(w(intersect(index_yes{i},(index_H12{i})))); + + yes_9O(i)=nansum(w(intersect(index_yes{i},(index_O9{i})))); + yes_10O(i)=nansum(w(intersect(index_yes{i},(index_O10{i})))); + yes_11O(i)=nansum(w(intersect(index_yes{i},(index_O11{i})))); + yes_12O(i)=nansum(w(intersect(index_yes{i},(index_O12{i})))); + + yes_9BB(i)=nansum(w(intersect(index_yesboys{i},index_B9{i}))); + yes_10BB(i)=nansum(w(intersect(index_yesboys{i},index_B10{i}))); + yes_11BB(i)=nansum(w(intersect(index_yesboys{i},index_B11{i}))); + yes_12BB(i)=nansum(w(intersect(index_yesboys{i},index_B12{i}))); + yes_9BG(i)=nansum(w(intersect(index_yesgirls{i},index_B9{i}))); + yes_10BG(i)=nansum(w(intersect(index_yesgirls{i},index_B10{i}))); + yes_11BG(i)=nansum(w(intersect(index_yesgirls{i},index_B11{i}))); + yes_12BG(i)=nansum(w(intersect(index_yesgirls{i},index_B12{i}))); + + yes_9HB(i)=nansum(w(intersect(index_yesboys{i},index_H9{i}))); + yes_10HB(i)=nansum(w(intersect(index_yesboys{i},index_H10{i}))); + yes_11HB(i)=nansum(w(intersect(index_yesboys{i},index_H11{i}))); + yes_12HB(i)=nansum(w(intersect(index_yesboys{i},index_H12{i}))); + yes_9HG(i)=nansum(w(intersect(index_yesgirls{i},index_H9{i}))); + yes_10HG(i)=nansum(w(intersect(index_yesgirls{i},index_H10{i}))); + yes_11HG(i)=nansum(w(intersect(index_yesgirls{i},index_H11{i}))); + yes_12HG(i)=nansum(w(intersect(index_yesgirls{i},index_H12{i}))); + + yes_9OB(i)=nansum(w(intersect(index_yesboys{i},index_O9{i}))); + yes_10OB(i)=nansum(w(intersect(index_yesboys{i},index_O10{i}))); + yes_11OB(i)=nansum(w(intersect(index_yesboys{i},index_O11{i}))); + yes_12OB(i)=nansum(w(intersect(index_yesboys{i},index_O12{i}))); + yes_9OG(i)=nansum(w(intersect(index_yesgirls{i},index_O9{i}))); + yes_10OG(i)=nansum(w(intersect(index_yesgirls{i},index_O10{i}))); + yes_11OG(i)=nansum(w(intersect(index_yesgirls{i},index_O11{i}))); + yes_12OG(i)=nansum(w(intersect(index_yesgirls{i},index_O12{i}))); + + %find prevelance values******************************* + total{2,count+1,i}=total_yes(i)/total_ans(i)*100; %total + total{3,count+1,i}=yes_girls(i)/total_girls(i)*100; %girls + total{4,count+1,i}=yes_boys(i)/total_boys(i)*100; %boys + total{5,count+1,i}=yes_W(i)/total_w(i)*100; %whites + total{6,count+1,i}=yes_B(i)/total_b(i)*100; %blacks + total{7,count+1,i}=yes_H(i)/total_h(i)*100; %hispanics + total{8,count+1,i}=yes_O(i)/total_o(i)*100; %other + total{9,count+1,i}=yes_9(i)/total_9(i)*100; + total{10,count+1,i}=yes_10(i)/total_10(i)*100; + total{11,count+1,i}=yes_11(i)/total_11(i)*100; + total{12,count+1,i}=yes_12(i)/total_12(i)*100; + + total{13,count+1,i}=yes_WG(i)/total_Wg(i)*100; %WG + total{14,count+1,i}=yes_WB(i)/total_Wb(i)*100; %WB + total{15,count+1,i}=yes_BG(i)/total_Bg(i)*100; %BG + total{16,count+1,i}=yes_BB(i)/total_Bb(i)*100; %BB + total{17,count+1,i}=yes_HG(i)/total_Hg(i)*100; %HG + total{18,count+1,i}=yes_HB(i)/total_Hb(i)*100; %HB + total{19,count+1,i}=yes_OG(i)/total_Og(i)*100; %OG + total{20,count+1,i}=yes_OB(i)/total_Ob(i)*100; %OB + + total{21,count+1,i}=yes_9g(i)/total_9G(i)*100; + total{22,count+1,i}=yes_9b(i)/total_9B(i)*100; + total{23,count+1,i}=yes_10g(i)/total_10G(i)*100; + total{24,count+1,i}=yes_10b(i)/total_10B(i)*100; + total{25,count+1,i}=yes_11g(i)/total_11G(i)*100; + total{26,count+1,i}=yes_11b(i)/total_11B(i)*100; + total{27,count+1,i}=yes_12g(i)/total_12G(i)*100; + total{28,count+1,i}=yes_12b(i)/total_12B(i)*100; + + total{29,count+1,i}=yes_9W(i)/total_9_W(i)*100; + total{30,count+1,i}=yes_10W(i)/total_10_W(i)*100; + total{31,count+1,i}=yes_11W(i)/total_11_W(i)*100; + total{32,count+1,i}=yes_12W(i)/total_12_W(i)*100; + total{33,count+1,i}=yes_9B(i)/total_9_B(i)*100; + total{34,count+1,i}=yes_10B(i)/total_10_B(i)*100; + total{35,count+1,i}=yes_11B(i)/total_11_B(i)*100; + total{36,count+1,i}=yes_12B(i)/total_12_B(i)*100; + total{37,count+1,i}=yes_9H(i)/total_9_H(i)*100; + total{38,count+1,i}=yes_10H(i)/total_10_H(i)*100; + total{39,count+1,i}=yes_11H(i)/total_11_H(i)*100; + total{40,count+1,i}=yes_12H(i)/total_12_H(i)*100; + total{41,count+1,i}=yes_9O(i)/total_9_O(i)*100; + total{42,count+1,i}=yes_10O(i)/total_10_O(i)*100; + total{43,count+1,i}=yes_11O(i)/total_11_O(i)*100; + total{44,count+1,i}=yes_12O(i)/total_12_O(i)*100; + + total{45,count+1,i}=yes_9WG(i)/total_9G_W(i)*100; + total{46,count+1,i}=yes_10WG(i)/total_10G_W(i)*100; + total{47,count+1,i}=yes_11WG(i)/total_11G_W(i)*100; + total{48,count+1,i}=yes_12WG(i)/total_12G_W(i)*100; + total{49,count+1,i}=yes_9WB(i)/total_9B_W(i)*100; + total{50,count+1,i}=yes_10WB(i)/total_10B_W(i)*100; + total{51,count+1,i}=yes_11WB(i)/total_11B_W(i)*100; + total{52,count+1,i}=yes_12WB(i)/total_12B_W(i)*100; + + total{53,count+1,i}=yes_9BG(i)/total_9G_B(i)*100; + total{54,count+1,i}=yes_10BG(i)/total_10G_B(i)*100; + total{55,count+1,i}=yes_11BG(i)/total_11G_B(i)*100; + total{56,count+1,i}=yes_12BG(i)/total_12G_B(i)*100; + total{57,count+1,i}=yes_9BB(i)/total_9B_B(i)*100; + total{58,count+1,i}=yes_10BB(i)/total_10B_B(i)*100; + total{59,count+1,i}=yes_11BB(i)/total_11B_B(i)*100; + total{60,count+1,i}=yes_12BB(i)/total_12B_B(i)*100; + + total{61,count+1,i}=yes_9HG(i)/total_9G_H(i)*100; + total{62,count+1,i}=yes_10HG(i)/total_10G_H(i)*100; + total{63,count+1,i}=yes_11HG(i)/total_11G_H(i)*100; + total{64,count+1,i}=yes_12HG(i)/total_12G_H(i)*100; + total{65,count+1,i}=yes_9HB(i)/total_9B_H(i)*100; + total{66,count+1,i}=yes_10HB(i)/total_10B_H(i)*100; + total{67,count+1,i}=yes_11HB(i)/total_11B_H(i)*100; + total{68,count+1,i}=yes_12HB(i)/total_12B_H(i)*100; + + total{69,count+1,i}=yes_9OG(i)/total_9G_O(i)*100; + total{70,count+1,i}=yes_10OG(i)/total_10G_O(i)*100; + total{71,count+1,i}=yes_11OG(i)/total_11G_O(i)*100; + total{72,count+1,i}=yes_12OG(i)/total_12G_O(i)*100; + total{73,count+1,i}=yes_9OB(i)/total_9B_O(i)*100; + total{74,count+1,i}=yes_10OB(i)/total_10B_O(i)*100; + total{75,count+1,i}=yes_11OB(i)/total_11B_O(i)*100; + total{76,count+1,i}=yes_12OB(i)/total_12B_O(i)*100; + + %for confidence intervals + x_mat(1,count,i)=total_yes(i); + x_mat(2,count,i)=yes_girls(i); + x_mat(3,count,i)=yes_boys(i); + x_mat(4,count,i)=yes_W(i); + x_mat(5,count,i)=yes_B(i); + x_mat(6,count,i)=yes_H(i); + x_mat(7,count,i)=yes_O(i); + x_mat(8,count,i)=yes_9(i); + x_mat(9,count,i)=yes_10(i); + x_mat(10,count,i)=yes_11(i); + x_mat(11,count,i)=yes_12(i); + + x_mat(12,count,i)=yes_WG(i); + x_mat(13,count,i)=yes_WB(i); + x_mat(14,count,i)=yes_BG(i); + x_mat(15,count,i)=yes_BB(i); + x_mat(16,count,i)=yes_HG(i); + x_mat(17,count,i)=yes_HB(i); + x_mat(18,count,i)=yes_OG(i); + x_mat(19,count,i)=yes_OB(i); + + x_mat(20,count,i)=yes_9g(i); + x_mat(21,count,i)=yes_9b(i); + x_mat(22,count,i)=yes_10g(i); + x_mat(23,count,i)=yes_10b(i); + x_mat(24,count,i)=yes_11g(i); + x_mat(25,count,i)=yes_11b(i); + x_mat(26,count,i)=yes_12g(i); + x_mat(27,count,i)=yes_12b(i); + + x_mat(28,count,i)=yes_9W(i); + x_mat(29,count,i)=yes_10W(i); + x_mat(30,count,i)=yes_11W(i); + x_mat(31,count,i)=yes_12W(i); + x_mat(32,count,i)=yes_9B(i); + x_mat(33,count,i)=yes_10B(i); + x_mat(34,count,i)=yes_11B(i); + x_mat(35,count,i)=yes_12B(i); + x_mat(36,count,i)=yes_9H(i); + x_mat(37,count,i)=yes_10H(i); + x_mat(38,count,i)=yes_11H(i); + x_mat(39,count,i)=yes_12H(i); + x_mat(40,count,i)=yes_9O(i); + x_mat(41,count,i)=yes_10O(i); + x_mat(42,count,i)=yes_11O(i); + x_mat(43,count,i)=yes_12O(i); + + x_mat(44,count,i)=yes_9WG(i); + x_mat(45,count,i)=yes_10WG(i); + x_mat(46,count,i)=yes_11WG(i); + x_mat(47,count,i)=yes_12WG(i); + x_mat(48,count,i)=yes_9WB(i); + x_mat(49,count,i)=yes_10WB(i); + x_mat(50,count,i)=yes_11WB(i); + x_mat(51,count,i)=yes_12WB(i); + + x_mat(52,count,i)=yes_9BG(i); + x_mat(53,count,i)=yes_10BG(i); + x_mat(54,count,i)=yes_11BG(i); + x_mat(55,count,i)=yes_12BG(i); + x_mat(56,count,i)=yes_9BB(i); + x_mat(57,count,i)=yes_10BB(i); + x_mat(58,count,i)=yes_11BB(i); + x_mat(59,count,i)=yes_12BB(i); + + x_mat(60,count,i)=yes_9HG(i); + x_mat(61,count,i)=yes_10HG(i); + x_mat(62,count,i)=yes_11HG(i); + x_mat(63,count,i)=yes_12HG(i); + x_mat(64,count,i)=yes_9HB(i); + x_mat(65,count,i)=yes_10HB(i); + x_mat(66,count,i)=yes_11HB(i); + x_mat(67,count,i)=yes_12HB(i); + + x_mat(68,count,i)=yes_9OG(i); + x_mat(69,count,i)=yes_10OG(i); + x_mat(70,count,i)=yes_11OG(i); + x_mat(71,count,i)=yes_12OG(i); + x_mat(72,count,i)=yes_9OB(i); + x_mat(73,count,i)=yes_10OB(i); + x_mat(74,count,i)=yes_11OB(i); + x_mat(75,count,i)=yes_12OB(i); + count=count+1; + end + end + + %confidence interval + z=1.96; + for i=1:75 + for j=1:r + n=n_mat(i,j); + for k=1:cat_n + x=x_mat(i,k, j); %x_mat=zeros(59,5,r); + p=x/n; %x is the number of subjects saying "yes", n is the total subjects + upper=((p+z*sqrt(p*(1-p)/n))*100); + lower=((p-z*sqrt(p*(1-p)/n))*100); + upper=sprintf('%0.1f',round(upper*10)/10); + lower=sprintf('%0.1f',round(lower*10)/10); + n_round=total{i+1, k+1, j}; + n_round=sprintf('%0.1f',round(n_round*10)/10); + conf_mat{i+1,k+1, j}=[n_round ' (' lower ', ' upper ')']; + end + end + end + + + count_c=1; + [r,c,z]=size(conf_mat); + conf_mat2=cell(r,c*z+z); + for i=1:z + new_mat=conf_mat(:,1:c,i); + conf_mat2(:,count_c:count_c+c-1)=new_mat; + count_c=count_c+c+1; + end + + end diff --git a/heatmaps/run_demographics_2013.m b/heatmaps/run_demographics_2013.m new file mode 100644 index 0000000..4481217 --- /dev/null +++ b/heatmaps/run_demographics_2013.m @@ -0,0 +1,45 @@ +cd .. +cd .. +cd data +cd Controls_061514 +sex=importdata('sex-NaN.txt', '\t'); +race=importdata('race-NaN.txt', '\t'); +weight=importdata('weights-NaN.txt','\t'); +grade=importdata('grade-NaN.txt','\t'); +cd .. +cd results_103114 +cd cat +ques=input ('Enter in the question number you want to use (ex. Q01): ', 's'); +question_mat=importdata([ques '-cat-NaN.txt'], '\t'); +[r,c]=size(question_mat); +labels=question_mat(:,1); +question_mat=question_mat(:,2:c); +years=[2001 2003 2005 2007 2009 2011 2013]; +start_year=0; +end_year=0; +years2=double.empty; +count=1; +for i=1:numel(years) + indx=find(labels==years(i)); + if numel(indx)==1 + if start_year==0 + start_year=i; + else + end_year=i; + end + years2(count)=years(i); + count=count+1; + end +end + +[r,c]=size(sex); +weight=weight(start_year:end_year,2:c); +race=race(start_year:end_year,2:c); +sex=sex(start_year:end_year,2:c); +grade=grade(start_year:end_year,2:c); +cd .. +cd .. +cd .. +cd programs +cd heatmaps +[conf_mat, total, x_mat, n_mat, conf_mat2] = demographics_2013_CI( question_mat, race, sex, grade, weight, years2 ); \ No newline at end of file diff --git a/odds_ratio/OR_2013_categorical.m b/odds_ratio/OR_2013_categorical.m new file mode 100644 index 0000000..e3a43c9 --- /dev/null +++ b/odds_ratio/OR_2013_categorical.m @@ -0,0 +1,154 @@ + +function [] = OR_2013_categorical(ques1) + + k=1; %counter for rows in rel_risk_cell and odds_ratio_cell + + load reverse_code_091914 + cd results_103114 + cd cat + file1=[ques1 '-cat-NaN.txt']; + quest_1=importdata(file1, '\t'); + filename1=ques1; + a1=char(ques1); + ct=''; + for q=2:numel(a1) + c1=a1(q) ; + ct=[ct c1]; + end + ct=str2num(ct); + q1_RC=reverse_code(ct,1) ; + [r,c]=size(quest_1); + max_q1=max(max(quest_1(:,2:c))); + + %filename2 + files2=dir(fullfile('/ifs/data/proteomics/projects/cdc/matlab/results_103114/NaN/', '*.txt')); + cd .. + cd NaN + N=length(files2); + for CAT=1:max_q1 %for each categorical response for question 1 + for n=1:N %for each question 2 + quest_2=importdata(files2(n).name, '\t'); + filename2=''; + a2=char(files2(n).name); + b2=strfind(a2,'-'); + for m=1:(b2(1)-1) + c2=a2(m); + filename2=[filename2 c2]; + end + ct=[]; + for m=2:(b2(1)-1) + c2=a2(m); + ct=[ct c2]; + end + files2(n).name; + ct=str2num(ct); + q2_RC=reverse_code(ct,1) ; + + %PROCESS THE COMBO + if ( isnan(q2_RC)==0 && isnan(q1_RC)==0) + + [r1,c1]=size(quest_1); + [r2,c2]=size(quest_2) ; + year=[2001 2003 2005 2007 2009 2011 2013]; + year1=quest_1(:,1); + year2=quest_2(:,1); + year_final=double.empty; + quest_1F=double.empty; + quest_2F=double.empty; + counter=1; + s=0; %start for 1 + e=1; %start for 2 + for ii=1:numel(year) + y=year(ii); + indx1=find(year1==y); + indx2=find(year2==y); + if numel(indx1)>0 && numel(indx2)>0 %both in the matrix + year_final(counter,1)=y; + quest_1F(counter,:)=quest_1(indx1,2:c1); + quest_2F(counter,:)=quest_2(indx2,2:c2); + e=ii; + if (counter==1) + s=ii; + end + counter=counter+1; + end + end + [r,c]=size(quest_1F); + K=s+2; + for i=1:r %each year + %Q1: + index_yes_1{i}=find(quest_1F(i,:)>=CAT); %students who answered yes to Q1 + index_no_1{i}=find(quest_1F0 && numel(indx2)>0 %both in the matrix + year_final(counter,1)=y; + quest_1F(counter,:)=quest_1(indx1,2:c1); + quest_2F(counter,:)=quest_2(indx2,2:c2); + e=ii; + if (counter==1) + s=ii; + end + counter=counter+1; + end + end + [r,c]=size(quest_1F); + K=s+2; + for i=1:r + %Q1: + if q1_RC==1 + index_no_1{i}=find(quest_1F(i,:)==1); %students who answered yes to Q1 + index_yes_1{i}=find(quest_1F(i,:)==0); %students who answered no to Q1 + index_miss_1{i}=find(quest_1F(i,:)==9); %students who didn't answer Q1 + else + index_yes_1{i}=find(quest_1F(i,:)==1); %students who answered yes to Q1 + index_no_1{i}=find(quest_1F(i,:)==0); %students who answered no to Q1 + index_miss_1{i}=find(quest_1F(i,:)==9); %students who didn't answer Q1 + end + %Q2: + if q2_RC==1 + index_no_2{i}=find(quest_2F(i,:)==1); + index_yes_2{i}=find(quest_2F(i,:)==0); + index_miss_2{i}=find(quest_2F(i,:)==9); + else + index_yes_2{i}=find(quest_2F(i,:)==1); + index_no_2{i}=find(quest_2F(i,:)==0); + index_miss_2{i}=find(quest_2F(i,:)==9); + end + + index_yes_both{i}=intersect(index_yes_1{i}, index_yes_2{i}); %students who said yes to both Qs + index_no_both{i}=intersect(index_no_1{i}, index_no_2{i}); %student who said no to both Qs + index_yes1_no2{i}=intersect(index_yes_1{i}, index_no_2{i}); %students who said yes to Q1 and no to Q2 + index_no1_yes2{i}=intersect(index_no_1{i}, index_yes_2{i}); %students who said no to Q1 and yes to Q2 + index_miss_both{i}=intersect(index_miss_1{i}, index_miss_2{i}); %students who left out both qs + + + total_yes_both(i)=length(index_yes_both{i}); %total who said yes to both questions + total_no_both(i)=length(index_no_both{i}); %total who said no to both questions + total_yes1_no2(i)=length(index_yes1_no2{i}); %total who said yes to Q1 and no to Q2 + total_no1_yes2(i)=length(index_no1_yes2{i}); %total who said no to Q1 and yes to Q2 + % Q1 + % + % | yes | no + % ______|_______|_________ + % Q2 yes | a | b + % ______|_______|_________ + % no | c | d + + a=total_yes_both(i); + d=total_no_both(i); + c=total_yes1_no2(i); + b=total_no1_yes2(i); + + %formula for odds ratio: + OR= (a*d)/(b*c); + + %find confidence interval for OR + lnOR=log(OR); + seOR=sqrt((1/a)+(1/b)+(1/c)+(1/d)); + CI_upper=lnOR+1.96*seOR; + CI_lower=lnOR-1.96*seOR; + %odds_ratio cell matrix: + odds_ratio_cell{k,1}=[filename1]; + odds_ratio_cell{k,2}=[filename2]; + x=num2cell(OR); + odds_ratio_cell(k,K)=x; + OR_CI{k,1}=[filename1]; + OR_CI{k,2}=[filename2]; + OR_CI{k,K}=[CI_lower ', ' CI_upper]; + + K=K+1 ; + end + k=k+1; + end + end +end + +save('OR_2013', 'odds_ratio_cell'); +save('OR_CI_2013', 'OR_CI'); \ No newline at end of file diff --git a/odds_ratio/create_RR_OR_2013_CI_black.m b/odds_ratio/create_RR_OR_2013_CI_black.m new file mode 100644 index 0000000..83f3fd2 --- /dev/null +++ b/odds_ratio/create_RR_OR_2013_CI_black.m @@ -0,0 +1,188 @@ +%has reverse code information incorporated into this analysis + +% This program goes through all the binary_NaN files and gets the relative risk of every combination +% of variables and displays them in a chart as follows: + +% V1 | V2 | RR2001 | RR 2003 | RR2005 | RR2007 | RR2009 | RR2011 +%____|____|________|_________|________|________|________|________ +% | | | | | | | + +% It then does the same thing for odds ratio + +cd .. +cd Controls_061514 +sex=importdata('sex-NaN.txt', '\t'); +race=importdata('race-NaN.txt', '\t'); +cd .. +cd matlab + +k=1; %counter for rows in rel_risk_cell and odds_ratio_cell + +files1=dir(fullfile('/ifs/data/proteomics/projects/cdc/matlab/results_103114/NaN/', '*.txt')); + +load reverse_code_091914 +cd results_103114 +cd NaN + +P=length(files1); +for p=1:P + files1(p).name; + quest_1=importdata(files1(p).name, '\t'); + filename1=''; + a1=char(files1(p).name); + b1=strfind(a1,'-'); + for q=1:(b1(1)-1) + c1=a1(q); + filename1=[filename1 c1]; + end + ct=[]; + for q=2:(b1(1)-1) + c1=a1(q) ; + if c1~=0 + ct=[ct c1]; + end + end + ct=str2num(ct); + q1_RC=reverse_code(ct,1); + + %filename2 + files2=dir(fullfile('/ifs/data/proteomics/projects/cdc/matlab/results_103114/NaN/', '*.txt')); + N=length(files2); + for n=1:N + quest_2=importdata(files2(n).name, '\t'); + filename2=''; + a2=char(files2(n).name); + b2=strfind(a2,'-'); + for m=1:(b2(1)-1) + c2=a2(m); + filename2=[filename2 c2]; + end + ct=[]; + for m=2:(b2(1)-1) + c2=a2(m); + if c2~=0 + ct=[ct c2] ; + end + end + ct=str2num(ct); + q2_RC=reverse_code(ct,1); + + %PROCESS THE COMBO + if ( isnan(q2_RC)==0 && isnan(q1_RC)==0) + + [r1,c1]=size(quest_1); + [r2,c2]=size(quest_2) ; + year=[2001 2003 2005 2007 2009 2011 2013]; + year1=quest_1(:,1); + year2=quest_2(:,1); + year_final=double.empty; + quest_1F=double.empty; + quest_2F=double.empty; + counter=1; + s=0; %start for 1 + e=1; %start for 2 + for ii=1:numel(year) + y=year(ii); + indx1=find(year1==y); + indx2=find(year2==y); + if numel(indx1)>0 && numel(indx2)>0 %both in the matrix + year_final(counter,1)=y; + quest_1F(counter,:)=quest_1(indx1,2:c1); + quest_2F(counter,:)=quest_2(indx2,2:c2); + e=ii; + if (counter==1) + s=ii; + end + counter=counter+1; + end + end + [r,c]=size(quest_1F); + K=s+2; + for i=1:r + %Q1: + index_B{i}=find(race(i,:)== 2 ); + + if q1_RC==1 + index_no{i}=find(quest_1F(i,:)==1); %students who answered yes to Q1 + index_yes{i}=find(quest_1F(i,:)==0); %students who answered no to Q1 + index_yesB_1{i}=intersect(index_yes{i},index_B{i}); + index_noB_1{i}=intersect(index_no{i},index_B{i}); + index_miss_1{i}=find(quest_1F(i,:)==9); %students who didn't answer Q1 + else + index_yes{i}=find(quest_1F(i,:)==1); %students who answered yes to Q1 + index_no{i}=find(quest_1F(i,:)==0); %students who answered no to Q1 + index_yesB_1{i}=intersect(index_yes{i},index_B{i}); + index_noB_1{i}=intersect(index_no{i},index_B{i}); + index_miss_1{i}=find(quest_1F(i,:)==9); %students who didn't answer Q1 + end + %Q2: + if q2_RC==1 + index_no{i}=find(quest_2F(i,:)==1); + index_yes{i}=find(quest_2F(i,:)==0); + index_yesB_2{i}=intersect(index_yes{i},index_B{i}); + index_noB_2{i}=intersect(index_no{i},index_B{i}); + index_miss_2{i}=find(quest_2F(i,:)==9); + else + index_yes{i}=find(quest_2F(i,:)==1); + index_no{i}=find(quest_2F(i,:)==0); + index_yesB_2{i}=intersect(index_yes{i},index_B{i}); + index_noB_2{i}=intersect(index_no{i},index_B{i}); + index_miss_2{i}=find(quest_2F(i,:)==9); + end + + index_yes_both{i}=intersect(index_yesB_1{i}, index_yesB_2{i}); %students who said yes to both Qs + index_no_both{i}=intersect(index_noB_1{i}, index_noB_2{i}); %student who said no to both Qs + index_yes1_no2{i}=intersect(index_yesB_1{i}, index_noB_2{i}); %students who said yes to Q1 and no to Q2 + index_no1_yes2{i}=intersect(index_noB_1{i}, index_yesB_2{i}); %students who said no to Q1 and yes to Q2 + index_miss_both{i}=intersect(index_miss_1{i}, index_miss_2{i}); %students who left out both qs + + + total_yes_both(i)=length(index_yes_both{i}); %total who said yes to both questions + total_no_both(i)=length(index_no_both{i}); %total who said no to both questions + total_yes1_no2(i)=length(index_yes1_no2{i}); %total who said yes to Q1 and no to Q2 + total_no1_yes2(i)=length(index_no1_yes2{i}); %total who said no to Q1 and yes to Q2 + % Q1 + % + % | yes | no + % ______|_______|_________ + % Q2 yes | a | b + % ______|_______|_________ + % no | c | d + + a=total_yes_both(i); + d=total_no_both(i); + c=total_yes1_no2(i); + b=total_no1_yes2(i); + + %formula for odds ratio: + OR= (a*d)/(b*c); + + %find confidence interval for OR + lnOR=log(OR); + seOR=sqrt((1/a)+(1/b)+(1/c)+(1/d)); + CI_upper=lnOR+1.96*seOR; + CI_lower=lnOR-1.96*seOR; + CI_upper=exp(CI_upper); + CI_lower=exp(CI_lower); + %odds_ratio cell matrix: + odds_ratio_cell{k,1}=[filename1]; + odds_ratio_cell{k,2}=[filename2]; + x=num2cell(OR); + odds_ratio_cell(k,K)=x; + OR_CI{k,1}=[filename1]; + OR_CI{k,2}=[filename2]; + upper=sprintf('%0.2f',round(CI_upper*100)/100); + lower=sprintf('%0.2f',round(CI_lower*100)/100); + OR_CI{k,K}=[lower ', ' upper]; + + K=K+1 ; + end + k=k+1; + end + end +end + +cd .. +cd .. +save('OR_2013_BLACK', 'odds_ratio_cell'); +save('OR_CI_2013_BLACK', 'OR_CI'); \ No newline at end of file diff --git a/odds_ratio/create_RR_OR_2013_CI_boys.m b/odds_ratio/create_RR_OR_2013_CI_boys.m new file mode 100644 index 0000000..ddf03f5 --- /dev/null +++ b/odds_ratio/create_RR_OR_2013_CI_boys.m @@ -0,0 +1,188 @@ +%has reverse code information incorporated into this analysis + +% This program goes through all the binary_NaN files and gets the relative risk of every combination +% of variables and displays them in a chart as follows: + +% V1 | V2 | RR2001 | RR 2003 | RR2005 | RR2007 | RR2009 | RR2011 +%____|____|________|_________|________|________|________|________ +% | | | | | | | + +% It then does the same thing for odds ratio + +cd .. +cd Controls_061514 +sex=importdata('sex-NaN.txt', '\t'); +race=importdata('race-NaN.txt', '\t'); +cd .. +cd matlab + +k=1; %counter for rows in rel_risk_cell and odds_ratio_cell + +files1=dir(fullfile('/ifs/data/proteomics/projects/cdc/matlab/results_103114/NaN/', '*.txt')); + +load reverse_code_091914 +cd results_103114 +cd NaN + +P=length(files1); +for p=1:P + files1(p).name; + quest_1=importdata(files1(p).name, '\t'); + filename1=''; + a1=char(files1(p).name); + b1=strfind(a1,'-'); + for q=1:(b1(1)-1) + c1=a1(q); + filename1=[filename1 c1]; + end + ct=[]; + for q=2:(b1(1)-1) + c1=a1(q) ; + if c1~=0 + ct=[ct c1]; + end + end + ct=str2num(ct); + q1_RC=reverse_code(ct,1); + + %filename2 + files2=dir(fullfile('/ifs/data/proteomics/projects/cdc/matlab/results_103114/NaN/', '*.txt')); + N=length(files2); + for n=1:N + quest_2=importdata(files2(n).name, '\t'); + filename2=''; + a2=char(files2(n).name); + b2=strfind(a2,'-'); + for m=1:(b2(1)-1) + c2=a2(m); + filename2=[filename2 c2]; + end + ct=[]; + for m=2:(b2(1)-1) + c2=a2(m); + if c2~=0 + ct=[ct c2] ; + end + end + ct=str2num(ct); + q2_RC=reverse_code(ct,1); + + %PROCESS THE COMBO + if ( isnan(q2_RC)==0 && isnan(q1_RC)==0) + + [r1,c1]=size(quest_1); + [r2,c2]=size(quest_2) ; + year=[2001 2003 2005 2007 2009 2011 2013]; + year1=quest_1(:,1); + year2=quest_2(:,1); + year_final=double.empty; + quest_1F=double.empty; + quest_2F=double.empty; + counter=1; + s=0; %start for 1 + e=1; %start for 2 + for ii=1:numel(year) + y=year(ii); + indx1=find(year1==y); + indx2=find(year2==y); + if numel(indx1)>0 && numel(indx2)>0 %both in the matrix + year_final(counter,1)=y; + quest_1F(counter,:)=quest_1(indx1,2:c1); + quest_2F(counter,:)=quest_2(indx2,2:c2); + e=ii; + if (counter==1) + s=ii; + end + counter=counter+1; + end + end + [r,c]=size(quest_1F); + K=s+2; + for i=1:r + %Q1: + index_boys{i}=find(sex(i,:)==2); + + if q1_RC==1 + index_no{i}=find(quest_1F(i,:)==1); %students who answered yes to Q1 + index_yes{i}=find(quest_1F(i,:)==0); %students who answered no to Q1 + index_yesboys_1{i}=intersect(index_yes{i},index_boys{i}); + index_noboys_1{i}=intersect(index_no{i},index_boys{i}); + index_miss_1{i}=find(quest_1F(i,:)==9); %students who didn't answer Q1 + else + index_yes{i}=find(quest_1F(i,:)==1); %students who answered yes to Q1 + index_no{i}=find(quest_1F(i,:)==0); %students who answered no to Q1 + index_yesboys_1{i}=intersect(index_yes{i},index_boys{i}); + index_noboys_1{i}=intersect(index_no{i},index_boys{i}); + index_miss_1{i}=find(quest_1F(i,:)==9); %students who didn't answer Q1 + end + %Q2: + if q2_RC==1 + index_no{i}=find(quest_2F(i,:)==1); + index_yes{i}=find(quest_2F(i,:)==0); + index_yesboys_2{i}=intersect(index_yes{i},index_boys{i}); + index_noboys_2{i}=intersect(index_no{i},index_boys{i}); + index_miss_2{i}=find(quest_2F(i,:)==9); + else + index_yes{i}=find(quest_2F(i,:)==1); + index_no{i}=find(quest_2F(i,:)==0); + index_yesboys_2{i}=intersect(index_yes{i},index_boys{i}); + index_noboys_2{i}=intersect(index_no{i},index_boys{i}); + index_miss_2{i}=find(quest_2F(i,:)==9); + end + + index_yes_both{i}=intersect(index_yesboys_1{i}, index_yesboys_2{i}); %students who said yes to both Qs + index_no_both{i}=intersect(index_noboys_1{i}, index_noboys_2{i}); %student who said no to both Qs + index_yes1_no2{i}=intersect(index_yesboys_1{i}, index_noboys_2{i}); %students who said yes to Q1 and no to Q2 + index_no1_yes2{i}=intersect(index_noboys_1{i}, index_yesboys_2{i}); %students who said no to Q1 and yes to Q2 + index_miss_both{i}=intersect(index_miss_1{i}, index_miss_2{i}); %students who left out both qs + + + total_yes_both(i)=length(index_yes_both{i}); %total who said yes to both questions + total_no_both(i)=length(index_no_both{i}); %total who said no to both questions + total_yes1_no2(i)=length(index_yes1_no2{i}); %total who said yes to Q1 and no to Q2 + total_no1_yes2(i)=length(index_no1_yes2{i}); %total who said no to Q1 and yes to Q2 + % Q1 + % + % | yes | no + % ______|_______|_________ + % Q2 yes | a | b + % ______|_______|_________ + % no | c | d + + a=total_yes_both(i); + d=total_no_both(i); + c=total_yes1_no2(i); + b=total_no1_yes2(i); + + %formula for odds ratio: + OR= (a*d)/(b*c); + + %find confidence interval for OR + lnOR=log(OR); + seOR=sqrt((1/a)+(1/b)+(1/c)+(1/d)); + CI_upper=lnOR+1.96*seOR; + CI_lower=lnOR-1.96*seOR; + CI_upper=exp(CI_upper); + CI_lower=exp(CI_lower); + %odds_ratio cell matrix: + odds_ratio_cell{k,1}=[filename1]; + odds_ratio_cell{k,2}=[filename2]; + x=num2cell(OR); + odds_ratio_cell(k,K)=x; + OR_CI{k,1}=[filename1]; + OR_CI{k,2}=[filename2]; + upper=sprintf('%0.2f',round(CI_upper*100)/100); + lower=sprintf('%0.2f',round(CI_lower*100)/100); + OR_CI{k,K}=[lower ', ' upper]; + + K=K+1 ; + end + k=k+1; + end + end +end + +cd .. +cd .. +save('OR_2013_boys', 'odds_ratio_cell'); +save('OR_CI_2013_boys', 'OR_CI'); \ No newline at end of file diff --git a/odds_ratio/create_RR_OR_2013_CI_categorical.m b/odds_ratio/create_RR_OR_2013_CI_categorical.m new file mode 100644 index 0000000..911b2f3 --- /dev/null +++ b/odds_ratio/create_RR_OR_2013_CI_categorical.m @@ -0,0 +1,214 @@ +%has reverse code information incorporated into this analysis + +% This program goes through all the binary_NaN files and gets the relative risk of every combination +% of variables and displays them in a chart as follows: + +% V1 | V2 | RR2001 | RR 2003 | RR2005 | RR2007 | RR2009 | RR2011 +%____|____|________|_________|________|________|________|________ +% | | | | | | | + +% It then does the same thing for odds ratio + +cd .. +cd Controls_061514 +sex=importdata('sex-NaN.txt', '\t'); +race=importdata('race-NaN.txt', '\t'); +cd .. +cd matlab + +k=1; %counter for rows in rel_risk_cell and odds_ratio_cell + +files1=dir(fullfile('/ifs/data/proteomics/projects/cdc/matlab/results_103114/NaN/', '*.txt')); +load reverse_code_091914 + +P=length(files1); +for R=1:3 %race + for G=1:2 %gender + cd results_103114 + cd NaN + for p=1:P %question + files1(p).name; + quest_1=importdata(files1(p).name, '\t'); + filename1=''; + a1=char(files1(p).name); + b1=strfind(a1,'-'); + for q=1:(b1(1)-1) + c1=a1(q); + filename1=[filename1 c1]; + end + ct=[]; + for q=2:(b1(1)-1) + c1=a1(q) ; + if c1~=0 + ct=[ct c1]; + end + end + ct=str2num(ct); + q1_RC=reverse_code(ct,1); + + %filename2 + files2=dir(fullfile('/ifs/data/proteomics/projects/cdc/matlab/results_103114/NaN/', '*.txt')); + N=length(files2); + for n=1:N + quest_2=importdata(files2(n).name, '\t'); + filename2=''; + a2=char(files2(n).name); + b2=strfind(a2,'-'); + for m=1:(b2(1)-1) + c2=a2(m); + filename2=[filename2 c2]; + end + ct=[]; + for m=2:(b2(1)-1) + c2=a2(m); + if c2~=0 + ct=[ct c2] ; + end + end + ct=str2num(ct); + q2_RC=reverse_code(ct,1); + + %PROCESS THE COMBO + if ( isnan(q2_RC)==0 && isnan(q1_RC)==0) + + [r1,c1]=size(quest_1); + [r2,c2]=size(quest_2) ; + year=[2001 2003 2005 2007 2009 2011 2013]; + year1=quest_1(:,1); + year2=quest_2(:,1); + year_final=double.empty; + quest_1F=double.empty; + quest_2F=double.empty; + counter=1; + s=0; %start for 1 + e=1; %start for 2 + for ii=1:numel(year) + y=year(ii); + indx1=find(year1==y); + indx2=find(year2==y); + if numel(indx1)>0 && numel(indx2)>0 %both in the matrix + year_final(counter,1)=y; + quest_1F(counter,:)=quest_1(indx1,2:c1); + quest_2F(counter,:)=quest_2(indx2,2:c2); + e=ii; + if (counter==1) + s=ii; + end + counter=counter+1; + end + end + [r,c]=size(quest_1F); + K=s+2; + for i=1:r + %Q1: + index_final{i}=find(race(i,:)== R && sex(i,:)==G ); + + if q1_RC==1 + index_no{i}=find(quest_1F(i,:)==1); %students who answered yes to Q1 + index_yes{i}=find(quest_1F(i,:)==0); %students who answered no to Q1 + index_yes_1{i}=intersect(index_yes{i},index_final{i}); + index_no_1{i}=intersect(index_no{i},index_final{i}); + index_miss_1{i}=find(quest_1F(i,:)==9); %students who didn't answer Q1 + else + index_yes{i}=find(quest_1F(i,:)==1); %students who answered yes to Q1 + index_no{i}=find(quest_1F(i,:)==0); %students who answered no to Q1 + index_yes_1{i}=intersect(index_yes{i},index_final{i}); + index_no_1{i}=intersect(index_no{i},index_final{i}); + index_miss_1{i}=find(quest_1F(i,:)==9); %students who didn't answer Q1 + end + %Q2: + if q2_RC==1 + index_no{i}=find(quest_2F(i,:)==1); + index_yes{i}=find(quest_2F(i,:)==0); + index_yes_2{i}=intersect(index_yes{i},index_final{i}); + index_no_2{i}=intersect(index_no{i},index_final{i}); + index_miss_2{i}=find(quest_2F(i,:)==9); + else + index_yes{i}=find(quest_2F(i,:)==1); + index_no{i}=find(quest_2F(i,:)==0); + index_yes_2{i}=intersect(index_yes{i},index_final{i}); + index_no_2{i}=intersect(index_no{i},index_final{i}); + index_miss_2{i}=find(quest_2F(i,:)==9); + end + + index_yes_both{i}=intersect(index_yes_1{i}, index_yes_2{i}); %students who said yes to both Qs + index_no_both{i}=intersect(index_no_1{i}, index_no_2{i}); %student who said no to both Qs + index_yes1_no2{i}=intersect(index_yes_1{i}, index_no_2{i}); %students who said yes to Q1 and no to Q2 + index_no1_yes2{i}=intersect(index_no_1{i}, index_yes_2{i}); %students who said no to Q1 and yes to Q2 + index_miss_both{i}=intersect(index_miss_1{i}, index_miss_2{i}); %students who left out both qs + + + total_yes_both(i)=length(index_yes_both{i}); %total who said yes to both questions + total_no_both(i)=length(index_no_both{i}); %total who said no to both questions + total_yes1_no2(i)=length(index_yes1_no2{i}); %total who said yes to Q1 and no to Q2 + total_no1_yes2(i)=length(index_no1_yes2{i}); %total who said no to Q1 and yes to Q2 + % Q1 + % + % | yes | no + % ______|_______|_________ + % Q2 yes | a | b + % ______|_______|_________ + % no | c | d + + a=total_yes_both(i); + d=total_no_both(i); + c=total_yes1_no2(i); + b=total_no1_yes2(i); + + %formula for odds ratio: + OR= (a*d)/(b*c); + + %find confidence interval for OR + lnOR=log(OR); + seOR=sqrt((1/a)+(1/b)+(1/c)+(1/d)); + CI_upper=lnOR+1.96*seOR; + CI_lower=lnOR-1.96*seOR; + CI_upper=exp(CI_upper); + CI_lower=exp(CI_lower); + %odds_ratio cell matrix: + odds_ratio_cell{k,1}=[filename1]; + odds_ratio_cell{k,2}=[filename2]; + x=num2cell(OR); + odds_ratio_cell(k,K)=x; + OR_CI{k,1}=[filename1]; + OR_CI{k,2}=[filename2]; + upper=sprintf('%0.2f',round(CI_upper*100)/100); + lower=sprintf('%0.2f',round(CI_lower*100)/100); + OR_CI{k,K}=[lower ', ' upper]; + + K=K+1 ; + end + k=k+1; + end + end + end + + cd .. + cd .. + if R==1 + if G==1 + save('OR_2013_WHITE_GIRLS', 'odds_ratio_cell'); + save('OR_CI_2013_WHITE_GIRLS', 'OR_CI'); + elseif G==2 + save('OR_2013_WHITE_BOYS', 'odds_ratio_cell'); + save('OR_CI_2013_WHITE_BOYS', 'OR_CI'); + end + elseif R==2 + if G==1 + save('OR_2013_BLACK_GIRLS', 'odds_ratio_cell'); + save('OR_CI_2013_BLACK_GIRLS', 'OR_CI'); + elseif G==2 + save('OR_2013_BLACK_BOYS', 'odds_ratio_cell'); + save('OR_CI_2013_BLACK_BOYS', 'OR_CI'); + end + elseif R==3 + if G==1 + save('OR_2013_HISPANIC_GIRLS', 'odds_ratio_cell'); + save('OR_CI_2013_HISPANIC_GIRLS', 'OR_CI'); + elseif G==2 + save('OR_2013_HISPANIC_BOYS', 'odds_ratio_cell'); + save('OR_CI_2013_HISPANIC_BOYS', 'OR_CI'); + end + end + end +end \ No newline at end of file diff --git a/odds_ratio/create_RR_OR_2013_CI_cluster.m b/odds_ratio/create_RR_OR_2013_CI_cluster.m new file mode 100644 index 0000000..59d2452 --- /dev/null +++ b/odds_ratio/create_RR_OR_2013_CI_cluster.m @@ -0,0 +1,169 @@ +%has reverse code information incorporated into this analysis + +% This program goes through all the binary_NaN files and gets the relative risk of every combination +% of variables and displays them in a chart as follows: + +% V1 | V2 | RR2001 | RR 2003 | RR2005 | RR2007 | RR2009 | RR2011 +%____|____|________|_________|________|________|________|________ +% | | | | | | | + +% It then does the same thing for odds ratio + + +k=1; %counter for rows in rel_risk_cell and odds_ratio_cell + +files1=dir(fullfile('/ifs/data/proteomics/projects/cdc/matlab/results_103114/NaN/', '*.txt')); + +load reverse_code_091914 +cd results_103114 +cd NaN + +P=length(files1); +for p=1:P + files1(p).name; + quest_1=importdata(files1(p).name, '\t'); + filename1=''; + a1=char(files1(p).name); + b1=strfind(a1,'-'); + for q=1:(b1(1)-1) + c1=a1(q); + filename1=[filename1 c1]; + end + ct=[]; + for q=2:(b1(1)-1) + c1=a1(q) ; + ct=[ct c1]; + end + ct=str2num(ct) + q1_RC=reverse_code(ct,1) + + %filename2 + files2=dir(fullfile('/ifs/data/proteomics/projects/cdc/matlab/results_103114/NaN/', '*.txt')); + N=length(files2); + for n=1:N + quest_2=importdata(files2(n).name, '\t'); + filename2=''; + a2=char(files2(n).name); + b2=strfind(a2,'-'); + files2(n).name + for m=1:(b2(1)-1) + c2=a2(m); + filename2=[filename2 c2]; + end + ct=[]; + for m=2:(b2(1)-1) + c2=a2(m); + ct=[ct c2] ; + end + ct=str2num(ct); + q2_RC=reverse_code(ct,1); + + %PROCESS THE COMBO + if ( isnan(q2_RC)==0 && isnan(q1_RC)==0) + + [r1,c1]=size(quest_1); + [r2,c2]=size(quest_2) ; + year=[2001 2003 2005 2007 2009 2011 2013]; + year1=quest_1(:,1); + year2=quest_2(:,1); + year_final=double.empty; + quest_1F=double.empty; + quest_2F=double.empty; + counter=1; + s=0; %start for 1 + e=1; %start for 2 + for ii=1:numel(year) + y=year(ii); + indx1=find(year1==y); + indx2=find(year2==y); + if numel(indx1)>0 && numel(indx2)>0 %both in the matrix + year_final(counter,1)=y; + quest_1F(counter,:)=quest_1(indx1,2:c1); + quest_2F(counter,:)=quest_2(indx2,2:c2); + e=ii; + if (counter==1) + s=ii; + end + counter=counter+1; + end + end + [r,c]=size(quest_1F); + K=s+2; + for i=1:r + %Q1: + if q1_RC==1 + index_no_1{i}=find(quest_1F(i,:)==1); %students who answered yes to Q1 + index_yes_1{i}=find(quest_1F(i,:)==0); %students who answered no to Q1 + index_miss_1{i}=find(quest_1F(i,:)==9); %students who didn't answer Q1 + else + index_yes_1{i}=find(quest_1F(i,:)==1); %students who answered yes to Q1 + index_no_1{i}=find(quest_1F(i,:)==0); %students who answered no to Q1 + index_miss_1{i}=find(quest_1F(i,:)==9); %students who didn't answer Q1 + end + %Q2: + if q2_RC==1 + index_no_2{i}=find(quest_2F(i,:)==1); + index_yes_2{i}=find(quest_2F(i,:)==0); + index_miss_2{i}=find(quest_2F(i,:)==9); + else + index_yes_2{i}=find(quest_2F(i,:)==1); + index_no_2{i}=find(quest_2F(i,:)==0); + index_miss_2{i}=find(quest_2F(i,:)==9); + end + + index_yes_both{i}=intersect(index_yes_1{i}, index_yes_2{i}); %students who said yes to both Qs + index_no_both{i}=intersect(index_no_1{i}, index_no_2{i}); %student who said no to both Qs + index_yes1_no2{i}=intersect(index_yes_1{i}, index_no_2{i}); %students who said yes to Q1 and no to Q2 + index_no1_yes2{i}=intersect(index_no_1{i}, index_yes_2{i}); %students who said no to Q1 and yes to Q2 + index_miss_both{i}=intersect(index_miss_1{i}, index_miss_2{i}); %students who left out both qs + + + total_yes_both(i)=length(index_yes_both{i}); %total who said yes to both questions + total_no_both(i)=length(index_no_both{i}); %total who said no to both questions + total_yes1_no2(i)=length(index_yes1_no2{i}); %total who said yes to Q1 and no to Q2 + total_no1_yes2(i)=length(index_no1_yes2{i}); %total who said no to Q1 and yes to Q2 + % Q1 + % + % | yes | no + % ______|_______|_________ + % Q2 yes | a | b + % ______|_______|_________ + % no | c | d + + a=total_yes_both(i); + d=total_no_both(i); + c=total_yes1_no2(i); + b=total_no1_yes2(i); + + %formula for odds ratio: + OR= (a*d)/(b*c); + + %find confidence interval for OR + lnOR=log(OR); + seOR=sqrt((1/a)+(1/b)+(1/c)+(1/d)); + CI_upper=lnOR+1.96*seOR; + CI_lower=lnOR-1.96*seOR; + CI_upper=exp(CI_upper); + CI_lower=exp(CI_lower); + %odds_ratio cell matrix: + odds_ratio_cell{k,1}=[filename1]; + odds_ratio_cell{k,2}=[filename2]; + x=num2cell(OR); + odds_ratio_cell(k,K)=x; + OR_CI{k,1}=[filename1]; + OR_CI{k,2}=[filename2]; + upper=sprintf('%0.2f',round(CI_upper*100)/100); + lower=sprintf('%0.2f',round(CI_lower*100)/100); + OR_CI{k,K}=[lower ', ' upper]; + + K=K+1 ; + end + k=k+1; + end + end +end + +cd .. +cd .. +save('OR_2013', 'odds_ratio_cell'); +save('OR_CI_2013', 'OR_CI'); \ No newline at end of file diff --git a/odds_ratio/create_RR_OR_2013_CI_girls.m b/odds_ratio/create_RR_OR_2013_CI_girls.m new file mode 100644 index 0000000..e377421 --- /dev/null +++ b/odds_ratio/create_RR_OR_2013_CI_girls.m @@ -0,0 +1,188 @@ +%has reverse code information incorporated into this analysis + +% This program goes through all the binary_NaN files and gets the relative risk of every combination +% of variables and displays them in a chart as follows: + +% V1 | V2 | RR2001 | RR 2003 | RR2005 | RR2007 | RR2009 | RR2011 +%____|____|________|_________|________|________|________|________ +% | | | | | | | + +% It then does the same thing for odds ratio + +cd .. +cd Controls_061514 +sex=importdata('sex-NaN.txt', '\t'); +race=importdata('race-NaN.txt', '\t'); +cd .. +cd matlab + +k=1; %counter for rows in rel_risk_cell and odds_ratio_cell + +files1=dir(fullfile('/ifs/data/proteomics/projects/cdc/matlab/results_103114/NaN/', '*.txt')); + +load reverse_code_091914 +cd results_103114 +cd NaN + +P=length(files1); +for p=1:P + files1(p).name; + quest_1=importdata(files1(p).name, '\t'); + filename1=''; + a1=char(files1(p).name); + b1=strfind(a1,'-'); + for q=1:(b1(1)-1) + c1=a1(q); + filename1=[filename1 c1]; + end + ct=[]; + for q=2:(b1(1)-1) + c1=a1(q) ; + if c1~=0 + ct=[ct c1]; + end + end + ct=str2num(ct); + q1_RC=reverse_code(ct,1); + + %filename2 + files2=dir(fullfile('/ifs/data/proteomics/projects/cdc/matlab/results_103114/NaN/', '*.txt')); + N=length(files2); + for n=1:N + quest_2=importdata(files2(n).name, '\t'); + filename2=''; + a2=char(files2(n).name); + b2=strfind(a2,'-'); + for m=1:(b2(1)-1) + c2=a2(m); + filename2=[filename2 c2]; + end + ct=[]; + for m=2:(b2(1)-1) + c2=a2(m); + if c2~=0 + ct=[ct c2] ; + end + end + ct=str2num(ct); + q2_RC=reverse_code(ct,1); + + %PROCESS THE COMBO + if ( isnan(q2_RC)==0 && isnan(q1_RC)==0) + + [r1,c1]=size(quest_1); + [r2,c2]=size(quest_2) ; + year=[2001 2003 2005 2007 2009 2011 2013]; + year1=quest_1(:,1); + year2=quest_2(:,1); + year_final=double.empty; + quest_1F=double.empty; + quest_2F=double.empty; + counter=1; + s=0; %start for 1 + e=1; %start for 2 + for ii=1:numel(year) + y=year(ii); + indx1=find(year1==y); + indx2=find(year2==y); + if numel(indx1)>0 && numel(indx2)>0 %both in the matrix + year_final(counter,1)=y; + quest_1F(counter,:)=quest_1(indx1,2:c1); + quest_2F(counter,:)=quest_2(indx2,2:c2); + e=ii; + if (counter==1) + s=ii; + end + counter=counter+1; + end + end + [r,c]=size(quest_1F); + K=s+2; + for i=1:r + %Q1: + index_girls{i}=find(sex(i,:)==1); + + if q1_RC==1 + index_no{i}=find(quest_1F(i,:)==1); %students who answered yes to Q1 + index_yes{i}=find(quest_1F(i,:)==0); %students who answered no to Q1 + index_yesgirls_1{i}=intersect(index_yes{i},index_girls{i}); + index_nogirls_1{i}=intersect(index_no{i},index_girls{i}); + index_miss_1{i}=find(quest_1F(i,:)==9); %students who didn't answer Q1 + else + index_yes{i}=find(quest_1F(i,:)==1); %students who answered yes to Q1 + index_no{i}=find(quest_1F(i,:)==0); %students who answered no to Q1 + index_yesgirls_1{i}=intersect(index_yes{i},index_girls{i}); + index_nogirls_1{i}=intersect(index_no{i},index_girls{i}); + index_miss_1{i}=find(quest_1F(i,:)==9); %students who didn't answer Q1 + end + %Q2: + if q2_RC==1 + index_no{i}=find(quest_2F(i,:)==1); + index_yes{i}=find(quest_2F(i,:)==0); + index_yesgirls_2{i}=intersect(index_yes{i},index_girls{i}); + index_nogirls_2{i}=intersect(index_no{i},index_girls{i}); + index_miss_2{i}=find(quest_2F(i,:)==9); + else + index_yes{i}=find(quest_2F(i,:)==1); + index_no{i}=find(quest_2F(i,:)==0); + index_yesgirls_2{i}=intersect(index_yes{i},index_girls{i}); + index_nogirls_2{i}=intersect(index_no{i},index_girls{i}); + index_miss_2{i}=find(quest_2F(i,:)==9); + end + + index_yes_both{i}=intersect(index_yesgirls_1{i}, index_yesgirls_2{i}); %students who said yes to both Qs + index_no_both{i}=intersect(index_nogirls_1{i}, index_nogirls_2{i}); %student who said no to both Qs + index_yes1_no2{i}=intersect(index_yesgirls_1{i}, index_nogirls_2{i}); %students who said yes to Q1 and no to Q2 + index_no1_yes2{i}=intersect(index_nogirls_1{i}, index_yesgirls_2{i}); %students who said no to Q1 and yes to Q2 + index_miss_both{i}=intersect(index_miss_1{i}, index_miss_2{i}); %students who left out both qs + + + total_yes_both(i)=length(index_yes_both{i}); %total who said yes to both questions + total_no_both(i)=length(index_no_both{i}); %total who said no to both questions + total_yes1_no2(i)=length(index_yes1_no2{i}); %total who said yes to Q1 and no to Q2 + total_no1_yes2(i)=length(index_no1_yes2{i}); %total who said no to Q1 and yes to Q2 + % Q1 + % + % | yes | no + % ______|_______|_________ + % Q2 yes | a | b + % ______|_______|_________ + % no | c | d + + a=total_yes_both(i); + d=total_no_both(i); + c=total_yes1_no2(i); + b=total_no1_yes2(i); + + %formula for odds ratio: + OR= (a*d)/(b*c); + + %find confidence interval for OR + lnOR=log(OR); + seOR=sqrt((1/a)+(1/b)+(1/c)+(1/d)); + CI_upper=lnOR+1.96*seOR; + CI_lower=lnOR-1.96*seOR; + CI_upper=exp(CI_upper); + CI_lower=exp(CI_lower); + %odds_ratio cell matrix: + odds_ratio_cell{k,1}=[filename1]; + odds_ratio_cell{k,2}=[filename2]; + x=num2cell(OR); + odds_ratio_cell(k,K)=x; + OR_CI{k,1}=[filename1]; + OR_CI{k,2}=[filename2]; + upper=sprintf('%0.2f',round(CI_upper*100)/100); + lower=sprintf('%0.2f',round(CI_lower*100)/100); + OR_CI{k,K}=[lower ', ' upper]; + + K=K+1 ; + end + k=k+1; + end + end +end + +cd .. +cd .. +save('OR_2013_girls', 'odds_ratio_cell'); +save('OR_CI_2013_girls', 'OR_CI'); \ No newline at end of file diff --git a/odds_ratio/create_RR_OR_2013_CI_hispanic.m b/odds_ratio/create_RR_OR_2013_CI_hispanic.m new file mode 100644 index 0000000..06804c9 --- /dev/null +++ b/odds_ratio/create_RR_OR_2013_CI_hispanic.m @@ -0,0 +1,188 @@ +%has reverse code information incorporated into this analysis + +% This program goes through all the binary_NaN files and gets the relative risk of every combination +% of variables and displays them in a chart as follows: + +% V1 | V2 | RR2001 | RR 2003 | RR2005 | RR2007 | RR2009 | RR2011 +%____|____|________|_________|________|________|________|________ +% | | | | | | | + +% It then does the same thing for odds ratio + +cd .. +cd Controls_061514 +sex=importdata('sex-NaN.txt', '\t'); +race=importdata('race-NaN.txt', '\t'); +cd .. +cd matlab + +k=1; %counter for rows in rel_risk_cell and odds_ratio_cell + +files1=dir(fullfile('/ifs/data/proteomics/projects/cdc/matlab/results_103114/NaN/', '*.txt')); + +load reverse_code_091914 +cd results_103114 +cd NaN + +P=length(files1); +for p=1:P + files1(p).name; + quest_1=importdata(files1(p).name, '\t'); + filename1=''; + a1=char(files1(p).name); + b1=strfind(a1,'-'); + for q=1:(b1(1)-1) + c1=a1(q); + filename1=[filename1 c1]; + end + ct=[]; + for q=2:(b1(1)-1) + c1=a1(q) ; + if c1~=0 + ct=[ct c1]; + end + end + ct=str2num(ct); + q1_RC=reverse_code(ct,1); + + %filename2 + files2=dir(fullfile('/ifs/data/proteomics/projects/cdc/matlab/results_103114/NaN/', '*.txt')); + N=length(files2); + for n=1:N + quest_2=importdata(files2(n).name, '\t'); + filename2=''; + a2=char(files2(n).name); + b2=strfind(a2,'-'); + for m=1:(b2(1)-1) + c2=a2(m); + filename2=[filename2 c2]; + end + ct=[]; + for m=2:(b2(1)-1) + c2=a2(m); + if c2~=0 + ct=[ct c2] ; + end + end + ct=str2num(ct); + q2_RC=reverse_code(ct,1); + + %PROCESS THE COMBO + if ( isnan(q2_RC)==0 && isnan(q1_RC)==0) + + [r1,c1]=size(quest_1); + [r2,c2]=size(quest_2) ; + year=[2001 2003 2005 2007 2009 2011 2013]; + year1=quest_1(:,1); + year2=quest_2(:,1); + year_final=double.empty; + quest_1F=double.empty; + quest_2F=double.empty; + counter=1; + s=0; %start for 1 + e=1; %start for 2 + for ii=1:numel(year) + y=year(ii); + indx1=find(year1==y); + indx2=find(year2==y); + if numel(indx1)>0 && numel(indx2)>0 %both in the matrix + year_final(counter,1)=y; + quest_1F(counter,:)=quest_1(indx1,2:c1); + quest_2F(counter,:)=quest_2(indx2,2:c2); + e=ii; + if (counter==1) + s=ii; + end + counter=counter+1; + end + end + [r,c]=size(quest_1F); + K=s+2; + for i=1:r + %Q1: + index_H{i}=find(race(i,:)== 3 ); + + if q1_RC==1 + index_no{i}=find(quest_1F(i,:)==1); %students who answered yes to Q1 + index_yes{i}=find(quest_1F(i,:)==0); %students who answered no to Q1 + index_yesH_1{i}=intersect(index_yes{i},index_H{i}); + index_noH_1{i}=intersect(index_no{i},index_H{i}); + index_miss_1{i}=find(quest_1F(i,:)==9); %students who didn't answer Q1 + else + index_yes{i}=find(quest_1F(i,:)==1); %students who answered yes to Q1 + index_no{i}=find(quest_1F(i,:)==0); %students who answered no to Q1 + index_yesH_1{i}=intersect(index_yes{i},index_H{i}); + index_noH_1{i}=intersect(index_no{i},index_H{i}); + index_miss_1{i}=find(quest_1F(i,:)==9); %students who didn't answer Q1 + end + %Q2: + if q2_RC==1 + index_no{i}=find(quest_2F(i,:)==1); + index_yes{i}=find(quest_2F(i,:)==0); + index_yesH_2{i}=intersect(index_yes{i},index_H{i}); + index_noH_2{i}=intersect(index_no{i},index_H{i}); + index_miss_2{i}=find(quest_2F(i,:)==9); + else + index_yes{i}=find(quest_2F(i,:)==1); + index_no{i}=find(quest_2F(i,:)==0); + index_yesH_2{i}=intersect(index_yes{i},index_H{i}); + index_noH_2{i}=intersect(index_no{i},index_H{i}); + index_miss_2{i}=find(quest_2F(i,:)==9); + end + + index_yes_both{i}=intersect(index_yesH_1{i}, index_yesH_2{i}); %students who said yes to both Qs + index_no_both{i}=intersect(index_noH_1{i}, index_noH_2{i}); %student who said no to both Qs + index_yes1_no2{i}=intersect(index_yesH_1{i}, index_noH_2{i}); %students who said yes to Q1 and no to Q2 + index_no1_yes2{i}=intersect(index_noH_1{i}, index_yesH_2{i}); %students who said no to Q1 and yes to Q2 + index_miss_both{i}=intersect(index_miss_1{i}, index_miss_2{i}); %students who left out both qs + + + total_yes_both(i)=length(index_yes_both{i}); %total who said yes to both questions + total_no_both(i)=length(index_no_both{i}); %total who said no to both questions + total_yes1_no2(i)=length(index_yes1_no2{i}); %total who said yes to Q1 and no to Q2 + total_no1_yes2(i)=length(index_no1_yes2{i}); %total who said no to Q1 and yes to Q2 + % Q1 + % + % | yes | no + % ______|_______|_________ + % Q2 yes | a | b + % ______|_______|_________ + % no | c | d + + a=total_yes_both(i); + d=total_no_both(i); + c=total_yes1_no2(i); + b=total_no1_yes2(i); + + %formula for odds ratio: + OR= (a*d)/(b*c); + + %find confidence interval for OR + lnOR=log(OR); + seOR=sqrt((1/a)+(1/b)+(1/c)+(1/d)); + CI_upper=lnOR+1.96*seOR; + CI_lower=lnOR-1.96*seOR; + CI_upper=exp(CI_upper); + CI_lower=exp(CI_lower); + %odds_ratio cell matrix: + odds_ratio_cell{k,1}=[filename1]; + odds_ratio_cell{k,2}=[filename2]; + x=num2cell(OR); + odds_ratio_cell(k,K)=x; + OR_CI{k,1}=[filename1]; + OR_CI{k,2}=[filename2]; + upper=sprintf('%0.2f',round(CI_upper*100)/100); + lower=sprintf('%0.2f',round(CI_lower*100)/100); + OR_CI{k,K}=[lower ', ' upper]; + + K=K+1 ; + end + k=k+1; + end + end +end + +cd .. +cd .. +save('OR_2013_HISPANIC', 'odds_ratio_cell'); +save('OR_CI_2013_HISPANIC', 'OR_CI'); \ No newline at end of file diff --git a/odds_ratio/create_RR_OR_2013_CI_race_sex.m b/odds_ratio/create_RR_OR_2013_CI_race_sex.m new file mode 100644 index 0000000..911b2f3 --- /dev/null +++ b/odds_ratio/create_RR_OR_2013_CI_race_sex.m @@ -0,0 +1,214 @@ +%has reverse code information incorporated into this analysis + +% This program goes through all the binary_NaN files and gets the relative risk of every combination +% of variables and displays them in a chart as follows: + +% V1 | V2 | RR2001 | RR 2003 | RR2005 | RR2007 | RR2009 | RR2011 +%____|____|________|_________|________|________|________|________ +% | | | | | | | + +% It then does the same thing for odds ratio + +cd .. +cd Controls_061514 +sex=importdata('sex-NaN.txt', '\t'); +race=importdata('race-NaN.txt', '\t'); +cd .. +cd matlab + +k=1; %counter for rows in rel_risk_cell and odds_ratio_cell + +files1=dir(fullfile('/ifs/data/proteomics/projects/cdc/matlab/results_103114/NaN/', '*.txt')); +load reverse_code_091914 + +P=length(files1); +for R=1:3 %race + for G=1:2 %gender + cd results_103114 + cd NaN + for p=1:P %question + files1(p).name; + quest_1=importdata(files1(p).name, '\t'); + filename1=''; + a1=char(files1(p).name); + b1=strfind(a1,'-'); + for q=1:(b1(1)-1) + c1=a1(q); + filename1=[filename1 c1]; + end + ct=[]; + for q=2:(b1(1)-1) + c1=a1(q) ; + if c1~=0 + ct=[ct c1]; + end + end + ct=str2num(ct); + q1_RC=reverse_code(ct,1); + + %filename2 + files2=dir(fullfile('/ifs/data/proteomics/projects/cdc/matlab/results_103114/NaN/', '*.txt')); + N=length(files2); + for n=1:N + quest_2=importdata(files2(n).name, '\t'); + filename2=''; + a2=char(files2(n).name); + b2=strfind(a2,'-'); + for m=1:(b2(1)-1) + c2=a2(m); + filename2=[filename2 c2]; + end + ct=[]; + for m=2:(b2(1)-1) + c2=a2(m); + if c2~=0 + ct=[ct c2] ; + end + end + ct=str2num(ct); + q2_RC=reverse_code(ct,1); + + %PROCESS THE COMBO + if ( isnan(q2_RC)==0 && isnan(q1_RC)==0) + + [r1,c1]=size(quest_1); + [r2,c2]=size(quest_2) ; + year=[2001 2003 2005 2007 2009 2011 2013]; + year1=quest_1(:,1); + year2=quest_2(:,1); + year_final=double.empty; + quest_1F=double.empty; + quest_2F=double.empty; + counter=1; + s=0; %start for 1 + e=1; %start for 2 + for ii=1:numel(year) + y=year(ii); + indx1=find(year1==y); + indx2=find(year2==y); + if numel(indx1)>0 && numel(indx2)>0 %both in the matrix + year_final(counter,1)=y; + quest_1F(counter,:)=quest_1(indx1,2:c1); + quest_2F(counter,:)=quest_2(indx2,2:c2); + e=ii; + if (counter==1) + s=ii; + end + counter=counter+1; + end + end + [r,c]=size(quest_1F); + K=s+2; + for i=1:r + %Q1: + index_final{i}=find(race(i,:)== R && sex(i,:)==G ); + + if q1_RC==1 + index_no{i}=find(quest_1F(i,:)==1); %students who answered yes to Q1 + index_yes{i}=find(quest_1F(i,:)==0); %students who answered no to Q1 + index_yes_1{i}=intersect(index_yes{i},index_final{i}); + index_no_1{i}=intersect(index_no{i},index_final{i}); + index_miss_1{i}=find(quest_1F(i,:)==9); %students who didn't answer Q1 + else + index_yes{i}=find(quest_1F(i,:)==1); %students who answered yes to Q1 + index_no{i}=find(quest_1F(i,:)==0); %students who answered no to Q1 + index_yes_1{i}=intersect(index_yes{i},index_final{i}); + index_no_1{i}=intersect(index_no{i},index_final{i}); + index_miss_1{i}=find(quest_1F(i,:)==9); %students who didn't answer Q1 + end + %Q2: + if q2_RC==1 + index_no{i}=find(quest_2F(i,:)==1); + index_yes{i}=find(quest_2F(i,:)==0); + index_yes_2{i}=intersect(index_yes{i},index_final{i}); + index_no_2{i}=intersect(index_no{i},index_final{i}); + index_miss_2{i}=find(quest_2F(i,:)==9); + else + index_yes{i}=find(quest_2F(i,:)==1); + index_no{i}=find(quest_2F(i,:)==0); + index_yes_2{i}=intersect(index_yes{i},index_final{i}); + index_no_2{i}=intersect(index_no{i},index_final{i}); + index_miss_2{i}=find(quest_2F(i,:)==9); + end + + index_yes_both{i}=intersect(index_yes_1{i}, index_yes_2{i}); %students who said yes to both Qs + index_no_both{i}=intersect(index_no_1{i}, index_no_2{i}); %student who said no to both Qs + index_yes1_no2{i}=intersect(index_yes_1{i}, index_no_2{i}); %students who said yes to Q1 and no to Q2 + index_no1_yes2{i}=intersect(index_no_1{i}, index_yes_2{i}); %students who said no to Q1 and yes to Q2 + index_miss_both{i}=intersect(index_miss_1{i}, index_miss_2{i}); %students who left out both qs + + + total_yes_both(i)=length(index_yes_both{i}); %total who said yes to both questions + total_no_both(i)=length(index_no_both{i}); %total who said no to both questions + total_yes1_no2(i)=length(index_yes1_no2{i}); %total who said yes to Q1 and no to Q2 + total_no1_yes2(i)=length(index_no1_yes2{i}); %total who said no to Q1 and yes to Q2 + % Q1 + % + % | yes | no + % ______|_______|_________ + % Q2 yes | a | b + % ______|_______|_________ + % no | c | d + + a=total_yes_both(i); + d=total_no_both(i); + c=total_yes1_no2(i); + b=total_no1_yes2(i); + + %formula for odds ratio: + OR= (a*d)/(b*c); + + %find confidence interval for OR + lnOR=log(OR); + seOR=sqrt((1/a)+(1/b)+(1/c)+(1/d)); + CI_upper=lnOR+1.96*seOR; + CI_lower=lnOR-1.96*seOR; + CI_upper=exp(CI_upper); + CI_lower=exp(CI_lower); + %odds_ratio cell matrix: + odds_ratio_cell{k,1}=[filename1]; + odds_ratio_cell{k,2}=[filename2]; + x=num2cell(OR); + odds_ratio_cell(k,K)=x; + OR_CI{k,1}=[filename1]; + OR_CI{k,2}=[filename2]; + upper=sprintf('%0.2f',round(CI_upper*100)/100); + lower=sprintf('%0.2f',round(CI_lower*100)/100); + OR_CI{k,K}=[lower ', ' upper]; + + K=K+1 ; + end + k=k+1; + end + end + end + + cd .. + cd .. + if R==1 + if G==1 + save('OR_2013_WHITE_GIRLS', 'odds_ratio_cell'); + save('OR_CI_2013_WHITE_GIRLS', 'OR_CI'); + elseif G==2 + save('OR_2013_WHITE_BOYS', 'odds_ratio_cell'); + save('OR_CI_2013_WHITE_BOYS', 'OR_CI'); + end + elseif R==2 + if G==1 + save('OR_2013_BLACK_GIRLS', 'odds_ratio_cell'); + save('OR_CI_2013_BLACK_GIRLS', 'OR_CI'); + elseif G==2 + save('OR_2013_BLACK_BOYS', 'odds_ratio_cell'); + save('OR_CI_2013_BLACK_BOYS', 'OR_CI'); + end + elseif R==3 + if G==1 + save('OR_2013_HISPANIC_GIRLS', 'odds_ratio_cell'); + save('OR_CI_2013_HISPANIC_GIRLS', 'OR_CI'); + elseif G==2 + save('OR_2013_HISPANIC_BOYS', 'odds_ratio_cell'); + save('OR_CI_2013_HISPANIC_BOYS', 'OR_CI'); + end + end + end +end \ No newline at end of file diff --git a/odds_ratio/create_RR_OR_2013_CI_white.m b/odds_ratio/create_RR_OR_2013_CI_white.m new file mode 100644 index 0000000..a8cf46c --- /dev/null +++ b/odds_ratio/create_RR_OR_2013_CI_white.m @@ -0,0 +1,188 @@ +%has reverse code information incorporated into this analysis + +% This program goes through all the binary_NaN files and gets the relative risk of every combination +% of variables and displays them in a chart as follows: + +% V1 | V2 | RR2001 | RR 2003 | RR2005 | RR2007 | RR2009 | RR2011 +%____|____|________|_________|________|________|________|________ +% | | | | | | | + +% It then does the same thing for odds ratio + +cd .. +cd Controls_061514 +sex=importdata('sex-NaN.txt', '\t'); +race=importdata('race-NaN.txt', '\t'); +cd .. +cd matlab + +k=1; %counter for rows in rel_risk_cell and odds_ratio_cell + +files1=dir(fullfile('/ifs/data/proteomics/projects/cdc/matlab/results_103114/NaN/', '*.txt')); + +load reverse_code_091914 +cd results_103114 +cd NaN + +P=length(files1); +for p=1:P + files1(p).name; + quest_1=importdata(files1(p).name, '\t'); + filename1=''; + a1=char(files1(p).name); + b1=strfind(a1,'-'); + for q=1:(b1(1)-1) + c1=a1(q); + filename1=[filename1 c1]; + end + ct=[]; + for q=2:(b1(1)-1) + c1=a1(q) ; + if c1~=0 + ct=[ct c1]; + end + end + ct=str2num(ct); + q1_RC=reverse_code(ct,1); + + %filename2 + files2=dir(fullfile('/ifs/data/proteomics/projects/cdc/matlab/results_103114/NaN/', '*.txt')); + N=length(files2); + for n=1:N + quest_2=importdata(files2(n).name, '\t'); + filename2=''; + a2=char(files2(n).name); + b2=strfind(a2,'-'); + for m=1:(b2(1)-1) + c2=a2(m); + filename2=[filename2 c2]; + end + ct=[]; + for m=2:(b2(1)-1) + c2=a2(m); + if c2~=0 + ct=[ct c2] ; + end + end + ct=str2num(ct); + q2_RC=reverse_code(ct,1); + + %PROCESS THE COMBO + if ( isnan(q2_RC)==0 && isnan(q1_RC)==0) + + [r1,c1]=size(quest_1); + [r2,c2]=size(quest_2) ; + year=[2001 2003 2005 2007 2009 2011 2013]; + year1=quest_1(:,1); + year2=quest_2(:,1); + year_final=double.empty; + quest_1F=double.empty; + quest_2F=double.empty; + counter=1; + s=0; %start for 1 + e=1; %start for 2 + for ii=1:numel(year) + y=year(ii); + indx1=find(year1==y); + indx2=find(year2==y); + if numel(indx1)>0 && numel(indx2)>0 %both in the matrix + year_final(counter,1)=y; + quest_1F(counter,:)=quest_1(indx1,2:c1); + quest_2F(counter,:)=quest_2(indx2,2:c2); + e=ii; + if (counter==1) + s=ii; + end + counter=counter+1; + end + end + [r,c]=size(quest_1F); + K=s+2; + for i=1:r + %Q1: + index_W{i}=find(race(i,:)== 1 ); + + if q1_RC==1 + index_no{i}=find(quest_1F(i,:)==1); %students who answered yes to Q1 + index_yes{i}=find(quest_1F(i,:)==0); %students who answered no to Q1 + index_yesW_1{i}=intersect(index_yes{i},index_W{i}); + index_noW_1{i}=intersect(index_no{i},index_W{i}); + index_miss_1{i}=find(quest_1F(i,:)==9); %students who didn't answer Q1 + else + index_yes{i}=find(quest_1F(i,:)==1); %students who answered yes to Q1 + index_no{i}=find(quest_1F(i,:)==0); %students who answered no to Q1 + index_yesW_1{i}=intersect(index_yes{i},index_W{i}); + index_noW_1{i}=intersect(index_no{i},index_W{i}); + index_miss_1{i}=find(quest_1F(i,:)==9); %students who didn't answer Q1 + end + %Q2: + if q2_RC==1 + index_no{i}=find(quest_2F(i,:)==1); + index_yes{i}=find(quest_2F(i,:)==0); + index_yesW_2{i}=intersect(index_yes{i},index_W{i}); + index_noW_2{i}=intersect(index_no{i},index_W{i}); + index_miss_2{i}=find(quest_2F(i,:)==9); + else + index_yes{i}=find(quest_2F(i,:)==1); + index_no{i}=find(quest_2F(i,:)==0); + index_yesW_2{i}=intersect(index_yes{i},index_W{i}); + index_noW_2{i}=intersect(index_no{i},index_W{i}); + index_miss_2{i}=find(quest_2F(i,:)==9); + end + + index_yes_both{i}=intersect(index_yesW_1{i}, index_yesW_2{i}); %students who said yes to both Qs + index_no_both{i}=intersect(index_noW_1{i}, index_noW_2{i}); %student who said no to both Qs + index_yes1_no2{i}=intersect(index_yesW_1{i}, index_noW_2{i}); %students who said yes to Q1 and no to Q2 + index_no1_yes2{i}=intersect(index_noW_1{i}, index_yesW_2{i}); %students who said no to Q1 and yes to Q2 + index_miss_both{i}=intersect(index_miss_1{i}, index_miss_2{i}); %students who left out both qs + + + total_yes_both(i)=length(index_yes_both{i}); %total who said yes to both questions + total_no_both(i)=length(index_no_both{i}); %total who said no to both questions + total_yes1_no2(i)=length(index_yes1_no2{i}); %total who said yes to Q1 and no to Q2 + total_no1_yes2(i)=length(index_no1_yes2{i}); %total who said no to Q1 and yes to Q2 + % Q1 + % + % | yes | no + % ______|_______|_________ + % Q2 yes | a | b + % ______|_______|_________ + % no | c | d + + a=total_yes_both(i); + d=total_no_both(i); + c=total_yes1_no2(i); + b=total_no1_yes2(i); + + %formula for odds ratio: + OR= (a*d)/(b*c); + + %find confidence interval for OR + lnOR=log(OR); + seOR=sqrt((1/a)+(1/b)+(1/c)+(1/d)); + CI_upper=lnOR+1.96*seOR; + CI_lower=lnOR-1.96*seOR; + CI_upper=exp(CI_upper); + CI_lower=exp(CI_lower); + %odds_ratio cell matrix: + odds_ratio_cell{k,1}=[filename1]; + odds_ratio_cell{k,2}=[filename2]; + x=num2cell(OR); + odds_ratio_cell(k,K)=x; + OR_CI{k,1}=[filename1]; + OR_CI{k,2}=[filename2]; + upper=sprintf('%0.2f',round(CI_upper*100)/100); + lower=sprintf('%0.2f',round(CI_lower*100)/100); + OR_CI{k,K}=[lower ', ' upper]; + + K=K+1 ; + end + k=k+1; + end + end +end + +cd .. +cd .. +save('OR_2013_WHITE', 'odds_ratio_cell'); +save('OR_CI_2013_WHITE', 'OR_CI'); \ No newline at end of file diff --git a/odds_ratio/process_cluster_OR_CI.m b/odds_ratio/process_cluster_OR_CI.m new file mode 100644 index 0000000..dc64e91 --- /dev/null +++ b/odds_ratio/process_cluster_OR_CI.m @@ -0,0 +1,64 @@ +cd .. +cd .. +cd matrices +load qlabel_090914 +cd .. +cd programs +cd odds_ratios +cd OR_2014_11_04_2decimals +error=0; +demograph=input('Enter in the demographic you want to look at (all, girls, boys, white, black or hispanic): ', 's'); +if strcmp(demograph,'all')==1 + load OR_2013 + load OR_CI_2013 +elseif strcmp(demograph, 'girls')==1 + load OR_2013_girls + load OR_CI_2013_girls +elseif strcmp(demograph, 'boys')==1 + load OR_2013_boys + load OR_CI_2013_boys +elseif strcmp(demograph, 'white')==1 + load OR_2013_WHITE + load OR_CI_2013_WHITE +elseif strcmp(demograph, 'black')==1 + load OR_2013_BLACK + load OR_CI_2013_BLACK +elseif strcmp(demograph, 'hispanic')==1 + load OR_2013_HISPANIC + load OR_CI_2013_HISPANIC +else + error=1; +end +cd .. + +if (error==0) + ques=input ('Enter in the question number you want to use (ex. Q01): ', 's'); + + indx=find (strcmp(odds_ratio_cell(:,1),ques)==1); + if isempty(indx)==0 + plot_mat=odds_ratio_cell(indx,3:9); + CI_mat=OR_CI(indx,3:9); + [r,c]=size(plot_mat); + table_OR=cell(r+1,c+1); + q2=odds_ratio_cell(indx,2); + for j=1:numel(q2) + indx2=find(strcmp(q2{j},qlabel(:,2))==1); + if numel(indx2)>0 + table_OR{j+1,1}=qlabel{indx2,1}; + end + end + x={'2001' '2003' '2005' '2007' '2009' '2011' '2013'}; + table_OR(1,2:c+1)=x; + for j=1:r + for k=1:c + %check for empty + i=cellfun(@isempty,plot_mat(j,k)); + if i==0 + n_round=plot_mat{j,k}; + n_round=sprintf('%0.2f',round(n_round*100)/100); + table_OR{j+1,k+1}=[n_round ' (' num2str(CI_mat{j,k}) ')']; + end + end + end + end +end diff --git a/odds_ratio/process_cluster_OR_CI_WHITE_girls.m b/odds_ratio/process_cluster_OR_CI_WHITE_girls.m new file mode 100644 index 0000000..722239b --- /dev/null +++ b/odds_ratio/process_cluster_OR_CI_WHITE_girls.m @@ -0,0 +1,41 @@ +cd .. +cd .. +cd matrices +load qlabel_090914 +cd .. +cd programs +cd odds_ratios +cd OR_2014_11_04_2decimals +load OR_2013_WHITE_GIRLS +load OR_CI_2013_WHITE_GIRLS +cd .. + +ques=input ('Enter in the question number you want to use (ex. Q01): ', 's'); + +indx=find (strcmp(odds_ratio_cell(:,1),ques)==1); +if isempty(indx)==0 + plot_mat=odds_ratio_cell(indx,3:9); + CI_mat=OR_CI(indx,3:9); + [r,c]=size(plot_mat); + table_OR=cell(r+1,c+1); + q2=odds_ratio_cell(indx,2); + for j=1:numel(q2) + indx2=find(strcmp(q2{j},qlabel(:,2))==1); + if numel(indx2)>0 + table_OR{j+1,1}=qlabel{indx2,1}; + end + end + x={'2001' '2003' '2005' '2007' '2009' '2011' '2013'}; + table_OR(1,2:c+1)=x; + for j=1:r + for k=1:c + %check for empty + i=cellfun(@isempty,plot_mat(j,k)); + if i==0 + n_round=plot_mat{j,k}; + n_round=sprintf('%0.2f',round(n_round*100)/100); + table_OR{j+1,k+1}=[n_round ' (' num2str(CI_mat{j,k}) ')']; + end + end + end +end diff --git a/odds_ratio/process_cluster_OR_CI_girls.m b/odds_ratio/process_cluster_OR_CI_girls.m new file mode 100644 index 0000000..1777c19 --- /dev/null +++ b/odds_ratio/process_cluster_OR_CI_girls.m @@ -0,0 +1,41 @@ +cd .. +cd .. +cd matrices +load qlabel_090914 +cd .. +cd programs +cd odds_ratios +cd OR_2014_11_04_2decimals +load OR_2013_girls +load OR_CI_2013_girls +cd .. + +ques=input ('Enter in the question number you want to use (ex. Q01): ', 's'); + +indx=find (strcmp(odds_ratio_cell(:,1),ques)==1); +if isempty(indx)==0 + plot_mat=odds_ratio_cell(indx,3:9); + CI_mat=OR_CI(indx,3:9); + [r,c]=size(plot_mat); + table_OR=cell(r+1,c+1); + q2=odds_ratio_cell(indx,2); + for j=1:numel(q2) + indx2=find(strcmp(q2{j},qlabel(:,2))==1); + if numel(indx2)>0 + table_OR{j+1,1}=qlabel{indx2,1}; + end + end + x={'2001' '2003' '2005' '2007' '2009' '2011' '2013'}; + table_OR(1,2:c+1)=x; + for j=1:r + for k=1:c + %check for empty + i=cellfun(@isempty,plot_mat(j,k)); + if i==0 + n_round=plot_mat{j,k}; + n_round=sprintf('%0.2f',round(n_round*100)/100); + table_OR{j+1,k+1}=[n_round ' (' num2str(CI_mat{j,k}) ')']; + end + end + end +end diff --git a/odds_ratio/run_OR_2013_categorical_activity.m b/odds_ratio/run_OR_2013_categorical_activity.m new file mode 100644 index 0000000..14dc15e --- /dev/null +++ b/odds_ratio/run_OR_2013_categorical_activity.m @@ -0,0 +1,6 @@ +%physical activity questions +OR_2013_categorical('Q81'); +OR_2013_categorical('Q72'); +OR_2013_categorical('Q66'); +OR_2013_categorical('Q35'); +OR_2013_categorical('Q34'); \ No newline at end of file diff --git a/odds_ratio/run_OR_2013_categorical_gun.m b/odds_ratio/run_OR_2013_categorical_gun.m new file mode 100644 index 0000000..29d7ea7 --- /dev/null +++ b/odds_ratio/run_OR_2013_categorical_gun.m @@ -0,0 +1,4 @@ +%physical activity questions +OR_2013_categorical('Q01'); +OR_2013_categorical('Q02'); +OR_2013_categorical('Q03'); \ No newline at end of file diff --git a/odds_ratio/run_OR_2013_categorical_violence.m b/odds_ratio/run_OR_2013_categorical_violence.m new file mode 100644 index 0000000..bdc2247 --- /dev/null +++ b/odds_ratio/run_OR_2013_categorical_violence.m @@ -0,0 +1,10 @@ +%physical activity questions +OR_2013_categorical('Q04'); +OR_2013_categorical('Q05'); +OR_2013_categorical('Q06'); +OR_2013_categorical('Q07'); +OR_2013_categorical('Q08'); +OR_2013_categorical('Q09'); +OR_2013_categorical('Q10'); +OR_2013_categorical('Q74'); +OR_2013_categorical('Q75'); \ No newline at end of file diff --git a/prescriptiondrugs/OR_plot_Rxdrugs_table.m b/prescriptiondrugs/OR_plot_Rxdrugs_table.m new file mode 100644 index 0000000..87522b0 --- /dev/null +++ b/prescriptiondrugs/OR_plot_Rxdrugs_table.m @@ -0,0 +1,71 @@ +%make heatmaps out of the relative risk matrix + +cd .. +cd .. +cd matrices +load OR_2013_100714 +load OR_CI_2013_100714 +load qlabel_033014 + +table_mat=cell.empty; +table_mat(:,1)={'Ever used cocaine', 'Ever used heroin', 'Ever used methamphetamine', 'Ever injected Drugs', 'Ever used Ecstasy', 'Ever drink alcohol','Drank alcohol*','Had 5+ alcoholic drinks*', 'Ever used marijuana', 'Used marijuana*', 'Ever smoked cigarettes', 'Smoked cigarettes*', 'Felt sad or hopeless^', 'Considered suicide^', 'Planned suicide^', 'Attempted Suicide^', 'Fasted to lose weight*', 'Took pill to lose weight*','Vomited to lose weight*', 'Carried a weapon*', 'Carried a gun*', 'Carried a weapon at school*', 'Felt unsafe at school*', 'Been threatened at school*', 'Been in a fight*','Ever been forced to have sex', 'Been bullied at school^', 'Been electronically bullied^', 'Ridden with a driver who was drinking*'}; +questions={'Q25','Q28','Q29','Q31','Q32', 'Q17','Q18','Q19','Q21','Q23','Q53', 'Q55', 'Q11','Q12','Q13','Q16', 'Q38','Q39','Q40','Q01', 'Q02', 'Q03', 'Q04', 'Q05', 'Q06','Q10', 'Q74', 'Q75', 'Q50'}; + +ques='Q79'; +OR=odds_ratio_cell; +[r,c]=size(OR); +OR=OR(2:r,:); +indx=find(strcmp(OR(:,1),'Q79')==1); %put in the number for Rx drugs +xlab=OR(indx,2); +OR=OR(indx,7:9); +[r,c]=size(OR_CI); +or_ci=OR_CI(2:r,:); +indx=find(strcmp(or_ci(:,1),'Q79')==1); +or_ci=or_ci(indx,7:9); + +table_mat2=double.empty; +count=1; + +avg_mat=double.empty; + +for i=1:numel(questions) + indx=find(strcmp(xlab, questions{i})==1); + table_mat2{count,1}=table_mat{i,1}; + if numel(indx)>0 + for j=1:3 + temp=sprintf('%.1f',OR{indx,j});%num2str(OR{indx,j}); + temp2=or_ci{indx,j}; + num1=''; + num2=''; + a2=char(temp2); + b2=strfind(a2,','); + if (numel(b2)>0) + for m=1:(b2(1)-1) + c2=a2(m); + num1=[num1 c2]; + end + for m=b2(1)+2:numel(a2) + c2=a2(m); + num2=[num2 c2]; + end + num1_=str2double(num1); + num2_=str2double(num2); + lower=exp(num1_); + upper=exp(num2_); + l=sprintf('%.1f',lower); %num2str(lower); + u=sprintf('%.1f',upper);%num2str(upper); + + table_mat{i,j+1}=[temp ' (' l ', ' u ')']; + table_mat2{count, j+1}=temp; + table_mat2{count+1, j+1}=['(' l ', ' u ')']; + avg_mat(i,j)=OR{indx,j}; + end + end + count=count+2; + end +end + +indx=find((avg_mat)==0); +avg_mat(indx)=NaN; +mean=nanmean(avg_mat,2); + diff --git a/prescriptiondrugs/PO_freqv2.m b/prescriptiondrugs/PO_freqv2.m index 74d7ff2..05488e3 100644 --- a/prescriptiondrugs/PO_freqv2.m +++ b/prescriptiondrugs/PO_freqv2.m @@ -12,7 +12,7 @@ sex=sex(5:7,:); grade=grade(5:7,:); cd .. -cd results_061514 +cd results_091614 cd NaN question_mat=importdata('Q79--NaN.txt', '\t'); [r,c]=size(question_mat); @@ -40,27 +40,14 @@ index_10{i}=find(grade(i,:)== 2 ); index_11{i}=find(grade(i,:)== 3 ); index_12{i}=find(grade(i,:)== 4 ); -end -% ^for each desired variable we created an array of the indexes (ie. students) who are a "yes" in that variable - -for i=1:r index_missQ{i}=find(question_mat(i,:)==9); %students who didn't answer the Q index_nomiss{i}=find(question_mat(i,:)==0 | question_mat(i,:)==1); %answers that were NOT missing (ie. 0's and 1's / no's and yes's) -end -for i=1:r missQ(i)=length(index_missQ{i}); %number of students who answered the question each year -end - - -for i=1:r index_total_b{i}=intersect(index_nomiss{i},index_boys{i}); %index of all boys who answered index_total_g{i}=intersect(index_nomiss{i},index_girls{i}); %index of all girls who answered -end -% totals of each race/sex/combo: (for percentages- to compare those who said yes to total questioned) -for i=1:r w=weight(i,:)'; total_ans(i)=nansum(w(index_nomiss{i})); total_girls(i)=nansum(w(index_total_g{i})); %total # of girls who answered @@ -89,10 +76,7 @@ total_10B(i)=nansum(w(intersect(index_10{i},index_total_b{i}))); total_11B(i)=nansum(w(intersect(index_11{i},index_total_b{i}))); total_12B(i)=nansum(w(intersect(index_12{i},index_total_b{i}))); -end -% %yes-es: -for i=1:r w=weight(i,:)'; index_yesgirls{i}=intersect(index_yes{i},index_girls{i}); index_yesboys{i}=intersect(index_yes{i},index_boys{i}); diff --git a/prescriptiondrugs/PO_freqv3.m b/prescriptiondrugs/PO_freqv3.m new file mode 100644 index 0000000..7d80b42 --- /dev/null +++ b/prescriptiondrugs/PO_freqv3.m @@ -0,0 +1,260 @@ + +cd .. +cd .. +cd data +cd Controls_061514 +sex=importdata('sex-NaN.txt', '\t'); +race=importdata('race-NaN.txt', '\t'); +weight=importdata('weights-NaN.txt','\t'); +grade=importdata('grade-NaN.txt','\t'); +weight=weight(5:7,:); +race=race(5:7,:); +sex=sex(5:7,:); +grade=grade(5:7,:); +cd .. +cd results_091614 +cd NaN +question_mat=importdata('Q79--NaN.txt', '\t'); +[r,c]=size(question_mat); +%question_mat=question_mat(:,2:c); +question_mat(:,1)=9; +cd .. +cd .. +cd .. + +cd programs +cd prescriptiondrugs +cd results + +conf_mat=cell.empty; +n_mat=double.empty; +x_mat=double.empty; + +for i=1:r +% total(i)=TOTAL(i,1); + index_yes{i}=find(question_mat(i,:)==1); + index_girls{i}=find(sex(i,:)==1); + index_boys{i}=find(sex(i,:)==2); + index_W{i}=find(race(i,:)== 1 ); + index_B{i}=find(race(i,:)== 2 ); + index_H{i}=find(race(i,:)== 3 ); + index_O{i}=find(race(i,:)== 4 ); + index_9{i}=find(grade(i,:)== 1 ); + index_10{i}=find(grade(i,:)== 2 ); + index_11{i}=find(grade(i,:)== 3 ); + index_12{i}=find(grade(i,:)== 4 ); + + index_missQ{i}=find(question_mat(i,:)==9); %students who didn't answer the Q + index_nomiss{i}=find(question_mat(i,:)==0 | question_mat(i,:)==1); %answers that were NOT missing (ie. 0's and 1's / no's and yes's) + + missQ(i)=length(index_missQ{i}); %number of students who answered the question each year + index_total_b{i}=intersect(index_nomiss{i},index_boys{i}); %index of all boys who answered + index_total_g{i}=intersect(index_nomiss{i},index_girls{i}); %index of all girls who answered + + w=weight(i,:)'; + total_ans(i)=nansum(w(index_nomiss{i})); + total_girls(i)=nansum(w(index_total_g{i})); %total # of girls who answered + total_boys(i)=nansum(w(index_total_b{i})); %total number of boys who answered + total_W{i}=nansum(w(intersect(index_nomiss{i}, index_W{i}))); %total # of white students who answered + total_B{i}=nansum(w(intersect(index_nomiss{i}, index_B{i}))); %total # of black students who answered + total_H{i}=nansum(w(intersect(index_nomiss{i}, index_H{i}))); %total # of hispanic students who answered + total_O{i}=nansum(w(intersect(index_nomiss{i}, index_O{i}))); %total # of "other" students who answered + total_Wb(i)=nansum(w(intersect(index_total_b{i},index_W{i}))); + total_Wg(i)=nansum(w(intersect(index_total_g{i},index_W{i}))); + total_Bb(i)=nansum(w(intersect(index_total_b{i},index_B{i}))); + total_Bg(i)=nansum(w(intersect(index_total_g{i},index_B{i}))); + total_Hb(i)=nansum(w(intersect(index_total_b{i},index_H{i}))); + total_Hg(i)=nansum(w(intersect(index_total_g{i},index_H{i}))); + total_Ob(i)=nansum(w(intersect(index_total_b{i},index_O{i}))); + total_Og(i)=nansum(w(intersect(index_total_g{i},index_O{i}))); + total_9(i)=nansum(w(intersect((index_9{i}),index_nomiss{i}))); + total_10(i)=nansum(w(intersect((index_10{i}),index_nomiss{i}))); + total_11(i)=nansum(w(intersect((index_11{i}),index_nomiss{i}))); + total_12(i)=nansum(w(intersect((index_12{i}),index_nomiss{i}))); + total_9G(i)=nansum(w(intersect(index_9{i},index_total_g{i}))); + total_10G(i)=nansum(w(intersect(index_10{i},index_total_g{i}))); + total_11G(i)=nansum(w(intersect(index_11{i},index_total_g{i}))); + total_12G(i)=nansum(w(intersect(index_12{i},index_total_g{i}))); + total_9B(i)=nansum(w(intersect(index_9{i},index_total_b{i}))); + total_10B(i)=nansum(w(intersect(index_10{i},index_total_b{i}))); + total_11B(i)=nansum(w(intersect(index_11{i},index_total_b{i}))); + total_12B(i)=nansum(w(intersect(index_12{i},index_total_b{i}))); + + %make n_mat + n_mat(1,i)=total_ans(i); + n_mat(2,i)=total_girls(i); + n_mat(3,i)=total_boys(i); + n_mat(4,i)=total_W{i}; + n_mat(5,i)=total_B{i}; + n_mat(6,i)=total_H{i}; + n_mat(7,i)=total_O{i}; + n_mat(8,i)=total_Wb(i); + n_mat(9,i)= total_Wg(i); + n_mat(10,i)=total_Bb(i); + n_mat(11,i)=total_Bg(i); + n_mat(12,i)=total_Hb(i); + n_mat(13,i)=total_Hg(i); + n_mat(14,i)=total_Ob(i); + n_mat(15,i)=total_Og(i); + n_mat(16,i)=total_9(i); + n_mat(17,i)=total_9B(i); + n_mat(18,i)=total_9G(i); + n_mat(19,i)=total_10(i); + n_mat(20,i)=total_10B(i); + n_mat(21,i)=total_10G(i); + n_mat(22,i)=total_11(i); + n_mat(23,i)=total_11B(i); + n_mat(24,i)=total_11G(i); + n_mat(25,i)=total_12(i); + n_mat(26,i)=total_12B(i); + n_mat(27,i)=total_12G(i); + + + index_yesgirls{i}=intersect(index_yes{i},index_girls{i}); + index_yesboys{i}=intersect(index_yes{i},index_boys{i}); + yes_girls(i)=nansum(w(index_yesgirls{i})); + yes_boys(i)=nansum(w(index_yesboys{i})); + yes_W(i)=nansum(w(intersect(index_yes{i}, index_W{i}))); + yes_B(i)=nansum(w(intersect(index_yes{i}, index_B{i}))); + yes_H(i)=nansum(w(intersect(index_yes{i}, index_H{i}))); + yes_O(i)=nansum(w(intersect(index_yes{i}, index_O{i}))); + yes_WG(i)=nansum(w(intersect(index_yesgirls{i},index_W{i}))); + yes_BG(i)=nansum(w(intersect(index_yesgirls{i},index_B{i}))); + yes_HG(i)=nansum(w(intersect(index_yesgirls{i},index_H{i}))); + yes_OG(i)=nansum(w(intersect(index_yesgirls{i},index_O{i}))); + yes_WB(i)=nansum(w(intersect(index_yesboys{i},index_W{i}))); + yes_BB(i)=nansum(w(intersect(index_yesboys{i},index_B{i}))); + yes_HB(i)=nansum(w(intersect(index_yesboys{i},index_H{i}))); + yes_OB(i)=nansum(w(intersect(index_yesboys{i},index_O{i}))); + total_yes(i)=nansum(w(index_yes{i})); + yes_9(i)=nansum(w(intersect(index_yes{i},index_9{i}))); + yes_10(i)=nansum(w(intersect(index_yes{i},index_10{i}))); + yes_11(i)=nansum(w(intersect(index_yes{i},index_11{i}))); + yes_12(i)=nansum(w(intersect(index_yes{i},index_12{i}))); + yes_9B(i)=nansum(w(intersect(index_yesboys{i},index_9{i}))); + yes_10B(i)=nansum(w(intersect(index_yesboys{i},index_10{i}))); + yes_11B(i)=nansum(w(intersect(index_yesboys{i},index_11{i}))); + yes_12B(i)=nansum(w(intersect(index_yesboys{i},index_12{i}))); + yes_9G(i)=nansum(w(intersect(index_yesgirls{i},index_9{i}))); + yes_10G(i)=nansum(w(intersect(index_yesgirls{i},index_10{i}))); + yes_11G(i)=nansum(w(intersect(index_yesgirls{i},index_11{i}))); + yes_12G(i)=nansum(w(intersect(index_yesgirls{i},index_12{i}))); + total_w(i)=total_W{i}; + total_b(i)=total_B{i}; + total_h(i)=total_H{i}; + total_o(i)=total_O{i}; + + + %make x_mat + x_mat(1,i)=total_yes(i); + x_mat(2,i)=yes_boyss(i); + x_mat(3,i)=yes_girls(i); + x_mat(4,i)=yes_W(i); + x_mat(5,i)=yes_B(i); + x_mat(6,i)=yes_H(i); + x_mat(7,i)=yes_O(i); + x_mat(8,i)=yes_WB(i); + x_mat(9,i)= yes_WG(i); + x_mat(10,i)=yes_BB(i); + x_mat(11,i)=yes_BG(i); + x_mat(12,i)=yes_HB(i); + x_mat(13,i)=yes_HG(i); + x_mat(14,i)=yes_OB(i); + x_mat(15,i)=yes_OG(i); + x_mat(16,i)=yes_9(i); + x_mat(17,i)=yes_9B(i); + x_mat(18,i)=yes_9G(i); + x_mat(19,i)=yes_10(i); + x_mat(20,i)=yes_10B(i); + x_mat(21,i)=yes_10G(i); + x_mat(22,i)=yes_11(i); + x_mat(23,i)=yes_11B(i); + x_mat(24,i)=yes_11G(i); + x_mat(25,i)=yes_12(i); + x_mat(26,i)=yes_12B(i); + x_mat(27,i)=yes_12G(i); + +end + +%put them all into a matrix as percent values: +per_mat = zeros(16,r); +for i=1:r + per_mat(1,i)=total_yes(i)/total_ans(i)*100; %total + per_mat(2,i)=yes_boys(i)/total_boys(i)*100; %boys + per_mat(3,i)=yes_girls(i)/total_girls(i)*100; %girls + per_mat(4,i)=yes_W(i)/total_w(i)*100; %whites + per_mat(5,i)=yes_B(i)/total_b(i)*100; %blacks + per_mat(6,i)=yes_H(i)/total_h(i)*100; %hispanics + per_mat(7,i)=yes_O(i)/total_o(i)*100; %other + per_mat(8, i)=yes_WB(i)/total_Wb(i)*100; %WB + per_mat(9, i)=yes_WG(i)/total_Wg(i)*100; %WG + per_mat(10, i)=yes_BB(i)/total_Bb(i)*100; %BB + per_mat(11, i)=yes_BG(i)/total_Bg(i)*100; %BG + per_mat(12, i)=yes_HB(i)/total_Hb(i)*100; %HB + per_mat(13, i)=yes_HG(i)/total_Hg(i)*100; %HG + per_mat(14, i)=yes_OB(i)/total_Ob(i)*100; %OB + per_mat(15, i)=yes_OG(i)/total_Og(i)*100; %OG + per_mat(16, i)=yes_9(i)/total_9(i)*100; + per_mat(17, i)=yes_9B(i)/total_9B(i)*100; + per_mat(18, i)=yes_9G(i)/total_9G(i)*100; + per_mat(19, i)=yes_10(i)/total_10(i)*100; + per_mat(20, i)=yes_10B(i)/total_10B(i)*100; + per_mat(21, i)=yes_10G(i)/total_10G(i)*100; + per_mat(22, i)=yes_11(i)/total_11(i)*100; + per_mat(23, i)=yes_11B(i)/total_11B(i)*100; + per_mat(24, i)=yes_11G(i)/total_11G(i)*100; + per_mat(25, i)=yes_12(i)/total_12(i)*100; + per_mat(26, i)=yes_12B(i)/total_12B(i)*100; + per_mat(27, i)=yes_12G(i)/total_12G(i)*100; +end + +%per_mat=flipud(per_mat); + + label_year={'2009','2011', '2013'}; + label_cell2={'Total', 'Boys', 'Girls', 'W', 'B', 'H', 'O', 'W Boys', 'W Girls', 'B Boys', 'B Girls', 'H Boys', 'H Girls', 'O Boys', 'O Girls', '9th', '9th-Boys', '9th-Girls', '10th','10th-Boys', '10th-Girls', '11th', '11th-Boys', '11th-Girls', '12th', '12th-Boys', '12th-Boys'}; + %per_mat_map(1:15,1:r)=per_mat(1:15,1:r); + %per_mat_map=flipdim(per_mat_map,1); + max_mat=max(max(per_mat)); + if max_mat>75 + M=100; + elseif max_mat>50 + M=75; + elseif max_mat>25 + M=50; + else + M=25; + end + M=50 + %get rid of deimals + per_mat=per_mat*10; + per_mat=round(per_mat); + per_mat=per_mat/10; + h=figure; + title1={'During your life, how many times have you taken a prescription drug'; '(such as OxyContin, Percocet, Vicodin, codeine, Adderall, Ritalin, or Xanax)'; 'without a doctor’s prescription?'}; + [hImage]=heatmap_rb(per_mat, label_year, label_cell2, 1, M, 0, 'Colormap','money', 'UseLogColormap', false, 'ShowAllTicks',true, 'Colorbar',true,'TextColor','k', 'FontSize', 12); + title (title1, 'FontSize', 12, 'fontWeight','bold'); + set (gca, 'FontSize',12); + + + saveas (gcf, 'PO_heatmap.fig'); %can make pdf, jnp, or jpg + print (gcf, '-dpdf', 'PO_heatmap.pdf'); + + close all + +z=1.96; +[r,c]=size(n_mat); +for i=1:r + count=1; + for j=1:c + x=x_mat(i,j); + n=n_mat(i,j); + p=x/n; %x is the number of subjects saying "yes", n is the total subjects + upper=((p+z*sqrt(p*(1-p)/n))*100); + lower=((p-z*sqrt(p*(1-p)/n))*100); + upper=sprintf('%0.1f',round(upper*10)/10); + lower=sprintf('%0.1f',round(lower*10)/10); + conf_mat{i+1,count}=[lower ', ' upper]; + count=count+1; + end +end + diff --git a/prescriptiondrugs/heroin_freqv3.m b/prescriptiondrugs/heroin_freqv3.m new file mode 100644 index 0000000..e029cb7 --- /dev/null +++ b/prescriptiondrugs/heroin_freqv3.m @@ -0,0 +1,262 @@ + +cd .. +cd .. +cd data +cd Controls_061514 +sex=importdata('sex-NaN.txt', '\t'); +race=importdata('race-NaN.txt', '\t'); +weight=importdata('weights-NaN.txt','\t'); +grade=importdata('grade-NaN.txt','\t'); +weight=weight(5:7,:); +race=race(5:7,:); +sex=sex(5:7,:); +grade=grade(5:7,:); +cd .. +cd results_091614 +cd NaN +question_mat=importdata('Q28--NaN.txt', '\t'); +[r,c]=size(question_mat); +%question_mat=question_mat(:,2:c); +question_mat(:,1)=9; +question_mat=question_mat(5:7,:); +cd .. +cd .. +cd .. + +cd programs +cd prescriptiondrugs +cd results + +[r,c]=size(question_mat); +conf_mat=cell.empty; +n_mat=double.empty; +x_mat=double.empty; + +for i=1:r +% total(i)=TOTAL(i,1); + index_yes{i}=find(question_mat(i,:)==1); + index_girls{i}=find(sex(i,:)==1); + index_boys{i}=find(sex(i,:)==2); + index_W{i}=find(race(i,:)== 1 ); + index_B{i}=find(race(i,:)== 2 ); + index_H{i}=find(race(i,:)== 3 ); + index_O{i}=find(race(i,:)== 4 ); + index_9{i}=find(grade(i,:)== 1 ); + index_10{i}=find(grade(i,:)== 2 ); + index_11{i}=find(grade(i,:)== 3 ); + index_12{i}=find(grade(i,:)== 4 ); + + index_missQ{i}=find(question_mat(i,:)==9); %students who didn't answer the Q + index_nomiss{i}=find(question_mat(i,:)==0 | question_mat(i,:)==1); %answers that were NOT missing (ie. 0's and 1's / no's and yes's) + + missQ(i)=length(index_missQ{i}); %number of students who answered the question each year + index_total_b{i}=intersect(index_nomiss{i},index_boys{i}); %index of all boys who answered + index_total_g{i}=intersect(index_nomiss{i},index_girls{i}); %index of all girls who answered + + w=weight(i,:)'; + total_ans(i)=nansum(w(index_nomiss{i})); + total_girls(i)=nansum(w(index_total_g{i})); %total # of girls who answered + total_boys(i)=nansum(w(index_total_b{i})); %total number of boys who answered + total_W{i}=nansum(w(intersect(index_nomiss{i}, index_W{i}))); %total # of white students who answered + total_B{i}=nansum(w(intersect(index_nomiss{i}, index_B{i}))); %total # of black students who answered + total_H{i}=nansum(w(intersect(index_nomiss{i}, index_H{i}))); %total # of hispanic students who answered + total_O{i}=nansum(w(intersect(index_nomiss{i}, index_O{i}))); %total # of "other" students who answered + total_Wb(i)=nansum(w(intersect(index_total_b{i},index_W{i}))); + total_Wg(i)=nansum(w(intersect(index_total_g{i},index_W{i}))); + total_Bb(i)=nansum(w(intersect(index_total_b{i},index_B{i}))); + total_Bg(i)=nansum(w(intersect(index_total_g{i},index_B{i}))); + total_Hb(i)=nansum(w(intersect(index_total_b{i},index_H{i}))); + total_Hg(i)=nansum(w(intersect(index_total_g{i},index_H{i}))); + total_Ob(i)=nansum(w(intersect(index_total_b{i},index_O{i}))); + total_Og(i)=nansum(w(intersect(index_total_g{i},index_O{i}))); + total_9(i)=nansum(w(intersect((index_9{i}),index_nomiss{i}))); + total_10(i)=nansum(w(intersect((index_10{i}),index_nomiss{i}))); + total_11(i)=nansum(w(intersect((index_11{i}),index_nomiss{i}))); + total_12(i)=nansum(w(intersect((index_12{i}),index_nomiss{i}))); + total_9G(i)=nansum(w(intersect(index_9{i},index_total_g{i}))); + total_10G(i)=nansum(w(intersect(index_10{i},index_total_g{i}))); + total_11G(i)=nansum(w(intersect(index_11{i},index_total_g{i}))); + total_12G(i)=nansum(w(intersect(index_12{i},index_total_g{i}))); + total_9B(i)=nansum(w(intersect(index_9{i},index_total_b{i}))); + total_10B(i)=nansum(w(intersect(index_10{i},index_total_b{i}))); + total_11B(i)=nansum(w(intersect(index_11{i},index_total_b{i}))); + total_12B(i)=nansum(w(intersect(index_12{i},index_total_b{i}))); + + %make n_mat + n_mat(1,i)=total_ans(i); + n_mat(2,i)=total_girls(i); + n_mat(3,i)=total_boys(i); + n_mat(4,i)=total_W{i}; + n_mat(5,i)=total_B{i}; + n_mat(6,i)=total_H{i}; + n_mat(7,i)=total_O{i}; + n_mat(8,i)=total_Wb(i); + n_mat(9,i)= total_Wg(i); + n_mat(10,i)=total_Bb(i); + n_mat(11,i)=total_Bg(i); + n_mat(12,i)=total_Hb(i); + n_mat(13,i)=total_Hg(i); + n_mat(14,i)=total_Ob(i); + n_mat(15,i)=total_Og(i); + n_mat(16,i)=total_9(i); + n_mat(17,i)=total_9B(i); + n_mat(18,i)=total_9G(i); + n_mat(19,i)=total_10(i); + n_mat(20,i)=total_10B(i); + n_mat(21,i)=total_10G(i); + n_mat(22,i)=total_11(i); + n_mat(23,i)=total_11B(i); + n_mat(24,i)=total_11G(i); + n_mat(25,i)=total_12(i); + n_mat(26,i)=total_12B(i); + n_mat(27,i)=total_12G(i); + + + index_yesgirls{i}=intersect(index_yes{i},index_girls{i}); + index_yesboys{i}=intersect(index_yes{i},index_boys{i}); + yes_girls(i)=nansum(w(index_yesgirls{i})); + yes_boys(i)=nansum(w(index_yesboys{i})); + yes_W(i)=nansum(w(intersect(index_yes{i}, index_W{i}))); + yes_B(i)=nansum(w(intersect(index_yes{i}, index_B{i}))); + yes_H(i)=nansum(w(intersect(index_yes{i}, index_H{i}))); + yes_O(i)=nansum(w(intersect(index_yes{i}, index_O{i}))); + yes_WG(i)=nansum(w(intersect(index_yesgirls{i},index_W{i}))); + yes_BG(i)=nansum(w(intersect(index_yesgirls{i},index_B{i}))); + yes_HG(i)=nansum(w(intersect(index_yesgirls{i},index_H{i}))); + yes_OG(i)=nansum(w(intersect(index_yesgirls{i},index_O{i}))); + yes_WB(i)=nansum(w(intersect(index_yesboys{i},index_W{i}))); + yes_BB(i)=nansum(w(intersect(index_yesboys{i},index_B{i}))); + yes_HB(i)=nansum(w(intersect(index_yesboys{i},index_H{i}))); + yes_OB(i)=nansum(w(intersect(index_yesboys{i},index_O{i}))); + total_yes(i)=nansum(w(index_yes{i})); + yes_9(i)=nansum(w(intersect(index_yes{i},index_9{i}))); + yes_10(i)=nansum(w(intersect(index_yes{i},index_10{i}))); + yes_11(i)=nansum(w(intersect(index_yes{i},index_11{i}))); + yes_12(i)=nansum(w(intersect(index_yes{i},index_12{i}))); + yes_9B(i)=nansum(w(intersect(index_yesboys{i},index_9{i}))); + yes_10B(i)=nansum(w(intersect(index_yesboys{i},index_10{i}))); + yes_11B(i)=nansum(w(intersect(index_yesboys{i},index_11{i}))); + yes_12B(i)=nansum(w(intersect(index_yesboys{i},index_12{i}))); + yes_9G(i)=nansum(w(intersect(index_yesgirls{i},index_9{i}))); + yes_10G(i)=nansum(w(intersect(index_yesgirls{i},index_10{i}))); + yes_11G(i)=nansum(w(intersect(index_yesgirls{i},index_11{i}))); + yes_12G(i)=nansum(w(intersect(index_yesgirls{i},index_12{i}))); + total_w(i)=total_W{i}; + total_b(i)=total_B{i}; + total_h(i)=total_H{i}; + total_o(i)=total_O{i}; + + + %make x_mat + x_mat(1,i)=total_yes(i); + x_mat(2,i)=yes_boys(i); + x_mat(3,i)=yes_girls(i); + x_mat(4,i)=yes_W(i); + x_mat(5,i)=yes_B(i); + x_mat(6,i)=yes_H(i); + x_mat(7,i)=yes_O(i); + x_mat(8,i)=yes_WB(i); + x_mat(9,i)= yes_WG(i); + x_mat(10,i)=yes_BB(i); + x_mat(11,i)=yes_BG(i); + x_mat(12,i)=yes_HB(i); + x_mat(13,i)=yes_HG(i); + x_mat(14,i)=yes_OB(i); + x_mat(15,i)=yes_OG(i); + x_mat(16,i)=yes_9(i); + x_mat(17,i)=yes_9B(i); + x_mat(18,i)=yes_9G(i); + x_mat(19,i)=yes_10(i); + x_mat(20,i)=yes_10B(i); + x_mat(21,i)=yes_10G(i); + x_mat(22,i)=yes_11(i); + x_mat(23,i)=yes_11B(i); + x_mat(24,i)=yes_11G(i); + x_mat(25,i)=yes_12(i); + x_mat(26,i)=yes_12B(i); + x_mat(27,i)=yes_12G(i); + +end + +%put them all into a matrix as percent values: +per_mat = zeros(16,r); +for i=1:r + per_mat(1,i)=total_yes(i)/total_ans(i)*100; %total + per_mat(2,i)=yes_boys(i)/total_boys(i)*100; %boys + per_mat(3,i)=yes_girls(i)/total_girls(i)*100; %girls + per_mat(4,i)=yes_W(i)/total_w(i)*100; %whites + per_mat(5,i)=yes_B(i)/total_b(i)*100; %blacks + per_mat(6,i)=yes_H(i)/total_h(i)*100; %hispanics + per_mat(7,i)=yes_O(i)/total_o(i)*100; %other + per_mat(8, i)=yes_WB(i)/total_Wb(i)*100; %WB + per_mat(9, i)=yes_WG(i)/total_Wg(i)*100; %WG + per_mat(10, i)=yes_BB(i)/total_Bb(i)*100; %BB + per_mat(11, i)=yes_BG(i)/total_Bg(i)*100; %BG + per_mat(12, i)=yes_HB(i)/total_Hb(i)*100; %HB + per_mat(13, i)=yes_HG(i)/total_Hg(i)*100; %HG + per_mat(14, i)=yes_OB(i)/total_Ob(i)*100; %OB + per_mat(15, i)=yes_OG(i)/total_Og(i)*100; %OG + per_mat(16, i)=yes_9(i)/total_9(i)*100; + per_mat(17, i)=yes_9B(i)/total_9B(i)*100; + per_mat(18, i)=yes_9G(i)/total_9G(i)*100; + per_mat(19, i)=yes_10(i)/total_10(i)*100; + per_mat(20, i)=yes_10B(i)/total_10B(i)*100; + per_mat(21, i)=yes_10G(i)/total_10G(i)*100; + per_mat(22, i)=yes_11(i)/total_11(i)*100; + per_mat(23, i)=yes_11B(i)/total_11B(i)*100; + per_mat(24, i)=yes_11G(i)/total_11G(i)*100; + per_mat(25, i)=yes_12(i)/total_12(i)*100; + per_mat(26, i)=yes_12B(i)/total_12B(i)*100; + per_mat(27, i)=yes_12G(i)/total_12G(i)*100; +end + +%per_mat=flipud(per_mat); + + label_year={'2009','2011', '2013'}; + label_cell2={'Total', 'Boys', 'Girls', 'W', 'B', 'H', 'O', 'W Boys', 'W Girls', 'B Boys', 'B Girls', 'H Boys', 'H Girls', 'O Boys', 'O Girls', '9th', '9th-Boys', '9th-Girls', '10th','10th-Boys', '10th-Girls', '11th', '11th-Boys', '11th-Girls', '12th', '12th-Boys', '12th-Boys'}; + %per_mat_map(1:15,1:r)=per_mat(1:15,1:r); + %per_mat_map=flipdim(per_mat_map,1); + max_mat=max(max(per_mat)); + if max_mat>75 + M=100; + elseif max_mat>50 + M=75; + elseif max_mat>25 + M=50; + else + M=25; + end + M=50 + %get rid of deimals + per_mat=per_mat*10; + per_mat=round(per_mat); + per_mat=per_mat/10; + h=figure; + title1={'During your life, how many times have you taken a prescription drug'; '(such as OxyContin, Percocet, Vicodin, codeine, Adderall, Ritalin, or Xanax)'; 'without a doctor’s prescription?'}; + [hImage]=heatmap_rb(per_mat, label_year, label_cell2, 1, M, 0, 'Colormap','money', 'UseLogColormap', false, 'ShowAllTicks',true, 'Colorbar',true,'TextColor','k', 'FontSize', 12); + title (title1, 'FontSize', 12, 'fontWeight','bold'); + set (gca, 'FontSize',12); + + + saveas (gcf, 'PO_heatmap.fig'); %can make pdf, jnp, or jpg + print (gcf, '-dpdf', 'PO_heatmap.pdf'); + + close all + +z=1.96; +[r,c]=size(n_mat); +for i=1:r + count=1; + for j=1:c + x=x_mat(i,j); + n=n_mat(i,j); + p=x/n; %x is the number of subjects saying "yes", n is the total subjects + upper=((p+z*sqrt(p*(1-p)/n))*100); + lower=((p-z*sqrt(p*(1-p)/n))*100); + upper=sprintf('%0.1f',round(upper*10)/10); + lower=sprintf('%0.1f',round(lower*10)/10); + conf_mat{i+1,count}=[lower ', ' upper]; + count=count+1; + end +end + diff --git a/prescriptiondrugs/injected_freqv3.m b/prescriptiondrugs/injected_freqv3.m new file mode 100644 index 0000000..1da4620 --- /dev/null +++ b/prescriptiondrugs/injected_freqv3.m @@ -0,0 +1,262 @@ + +cd .. +cd .. +cd data +cd Controls_061514 +sex=importdata('sex-NaN.txt', '\t'); +race=importdata('race-NaN.txt', '\t'); +weight=importdata('weights-NaN.txt','\t'); +grade=importdata('grade-NaN.txt','\t'); +weight=weight(5:7,:); +race=race(5:7,:); +sex=sex(5:7,:); +grade=grade(5:7,:); +cd .. +cd results_091614 +cd NaN +question_mat=importdata('Q31--NaN.txt', '\t'); +[r,c]=size(question_mat); +%question_mat=question_mat(:,2:c); +question_mat(:,1)=9; +question_mat=question_mat(5:7,:); +cd .. +cd .. +cd .. + +cd programs +cd prescriptiondrugs +cd results + +[r,c]=size(question_mat); +conf_mat=cell.empty; +n_mat=double.empty; +x_mat=double.empty; + +for i=1:r +% total(i)=TOTAL(i,1); + index_yes{i}=find(question_mat(i,:)==1); + index_girls{i}=find(sex(i,:)==1); + index_boys{i}=find(sex(i,:)==2); + index_W{i}=find(race(i,:)== 1 ); + index_B{i}=find(race(i,:)== 2 ); + index_H{i}=find(race(i,:)== 3 ); + index_O{i}=find(race(i,:)== 4 ); + index_9{i}=find(grade(i,:)== 1 ); + index_10{i}=find(grade(i,:)== 2 ); + index_11{i}=find(grade(i,:)== 3 ); + index_12{i}=find(grade(i,:)== 4 ); + + index_missQ{i}=find(question_mat(i,:)==9); %students who didn't answer the Q + index_nomiss{i}=find(question_mat(i,:)==0 | question_mat(i,:)==1); %answers that were NOT missing (ie. 0's and 1's / no's and yes's) + + missQ(i)=length(index_missQ{i}); %number of students who answered the question each year + index_total_b{i}=intersect(index_nomiss{i},index_boys{i}); %index of all boys who answered + index_total_g{i}=intersect(index_nomiss{i},index_girls{i}); %index of all girls who answered + + w=weight(i,:)'; + total_ans(i)=nansum(w(index_nomiss{i})); + total_girls(i)=nansum(w(index_total_g{i})); %total # of girls who answered + total_boys(i)=nansum(w(index_total_b{i})); %total number of boys who answered + total_W{i}=nansum(w(intersect(index_nomiss{i}, index_W{i}))); %total # of white students who answered + total_B{i}=nansum(w(intersect(index_nomiss{i}, index_B{i}))); %total # of black students who answered + total_H{i}=nansum(w(intersect(index_nomiss{i}, index_H{i}))); %total # of hispanic students who answered + total_O{i}=nansum(w(intersect(index_nomiss{i}, index_O{i}))); %total # of "other" students who answered + total_Wb(i)=nansum(w(intersect(index_total_b{i},index_W{i}))); + total_Wg(i)=nansum(w(intersect(index_total_g{i},index_W{i}))); + total_Bb(i)=nansum(w(intersect(index_total_b{i},index_B{i}))); + total_Bg(i)=nansum(w(intersect(index_total_g{i},index_B{i}))); + total_Hb(i)=nansum(w(intersect(index_total_b{i},index_H{i}))); + total_Hg(i)=nansum(w(intersect(index_total_g{i},index_H{i}))); + total_Ob(i)=nansum(w(intersect(index_total_b{i},index_O{i}))); + total_Og(i)=nansum(w(intersect(index_total_g{i},index_O{i}))); + total_9(i)=nansum(w(intersect((index_9{i}),index_nomiss{i}))); + total_10(i)=nansum(w(intersect((index_10{i}),index_nomiss{i}))); + total_11(i)=nansum(w(intersect((index_11{i}),index_nomiss{i}))); + total_12(i)=nansum(w(intersect((index_12{i}),index_nomiss{i}))); + total_9G(i)=nansum(w(intersect(index_9{i},index_total_g{i}))); + total_10G(i)=nansum(w(intersect(index_10{i},index_total_g{i}))); + total_11G(i)=nansum(w(intersect(index_11{i},index_total_g{i}))); + total_12G(i)=nansum(w(intersect(index_12{i},index_total_g{i}))); + total_9B(i)=nansum(w(intersect(index_9{i},index_total_b{i}))); + total_10B(i)=nansum(w(intersect(index_10{i},index_total_b{i}))); + total_11B(i)=nansum(w(intersect(index_11{i},index_total_b{i}))); + total_12B(i)=nansum(w(intersect(index_12{i},index_total_b{i}))); + + %make n_mat + n_mat(1,i)=total_ans(i); + n_mat(2,i)=total_girls(i); + n_mat(3,i)=total_boys(i); + n_mat(4,i)=total_W{i}; + n_mat(5,i)=total_B{i}; + n_mat(6,i)=total_H{i}; + n_mat(7,i)=total_O{i}; + n_mat(8,i)=total_Wb(i); + n_mat(9,i)= total_Wg(i); + n_mat(10,i)=total_Bb(i); + n_mat(11,i)=total_Bg(i); + n_mat(12,i)=total_Hb(i); + n_mat(13,i)=total_Hg(i); + n_mat(14,i)=total_Ob(i); + n_mat(15,i)=total_Og(i); + n_mat(16,i)=total_9(i); + n_mat(17,i)=total_9B(i); + n_mat(18,i)=total_9G(i); + n_mat(19,i)=total_10(i); + n_mat(20,i)=total_10B(i); + n_mat(21,i)=total_10G(i); + n_mat(22,i)=total_11(i); + n_mat(23,i)=total_11B(i); + n_mat(24,i)=total_11G(i); + n_mat(25,i)=total_12(i); + n_mat(26,i)=total_12B(i); + n_mat(27,i)=total_12G(i); + + + index_yesgirls{i}=intersect(index_yes{i},index_girls{i}); + index_yesboys{i}=intersect(index_yes{i},index_boys{i}); + yes_girls(i)=nansum(w(index_yesgirls{i})); + yes_boys(i)=nansum(w(index_yesboys{i})); + yes_W(i)=nansum(w(intersect(index_yes{i}, index_W{i}))); + yes_B(i)=nansum(w(intersect(index_yes{i}, index_B{i}))); + yes_H(i)=nansum(w(intersect(index_yes{i}, index_H{i}))); + yes_O(i)=nansum(w(intersect(index_yes{i}, index_O{i}))); + yes_WG(i)=nansum(w(intersect(index_yesgirls{i},index_W{i}))); + yes_BG(i)=nansum(w(intersect(index_yesgirls{i},index_B{i}))); + yes_HG(i)=nansum(w(intersect(index_yesgirls{i},index_H{i}))); + yes_OG(i)=nansum(w(intersect(index_yesgirls{i},index_O{i}))); + yes_WB(i)=nansum(w(intersect(index_yesboys{i},index_W{i}))); + yes_BB(i)=nansum(w(intersect(index_yesboys{i},index_B{i}))); + yes_HB(i)=nansum(w(intersect(index_yesboys{i},index_H{i}))); + yes_OB(i)=nansum(w(intersect(index_yesboys{i},index_O{i}))); + total_yes(i)=nansum(w(index_yes{i})); + yes_9(i)=nansum(w(intersect(index_yes{i},index_9{i}))); + yes_10(i)=nansum(w(intersect(index_yes{i},index_10{i}))); + yes_11(i)=nansum(w(intersect(index_yes{i},index_11{i}))); + yes_12(i)=nansum(w(intersect(index_yes{i},index_12{i}))); + yes_9B(i)=nansum(w(intersect(index_yesboys{i},index_9{i}))); + yes_10B(i)=nansum(w(intersect(index_yesboys{i},index_10{i}))); + yes_11B(i)=nansum(w(intersect(index_yesboys{i},index_11{i}))); + yes_12B(i)=nansum(w(intersect(index_yesboys{i},index_12{i}))); + yes_9G(i)=nansum(w(intersect(index_yesgirls{i},index_9{i}))); + yes_10G(i)=nansum(w(intersect(index_yesgirls{i},index_10{i}))); + yes_11G(i)=nansum(w(intersect(index_yesgirls{i},index_11{i}))); + yes_12G(i)=nansum(w(intersect(index_yesgirls{i},index_12{i}))); + total_w(i)=total_W{i}; + total_b(i)=total_B{i}; + total_h(i)=total_H{i}; + total_o(i)=total_O{i}; + + + %make x_mat + x_mat(1,i)=total_yes(i); + x_mat(2,i)=yes_boys(i); + x_mat(3,i)=yes_girls(i); + x_mat(4,i)=yes_W(i); + x_mat(5,i)=yes_B(i); + x_mat(6,i)=yes_H(i); + x_mat(7,i)=yes_O(i); + x_mat(8,i)=yes_WB(i); + x_mat(9,i)= yes_WG(i); + x_mat(10,i)=yes_BB(i); + x_mat(11,i)=yes_BG(i); + x_mat(12,i)=yes_HB(i); + x_mat(13,i)=yes_HG(i); + x_mat(14,i)=yes_OB(i); + x_mat(15,i)=yes_OG(i); + x_mat(16,i)=yes_9(i); + x_mat(17,i)=yes_9B(i); + x_mat(18,i)=yes_9G(i); + x_mat(19,i)=yes_10(i); + x_mat(20,i)=yes_10B(i); + x_mat(21,i)=yes_10G(i); + x_mat(22,i)=yes_11(i); + x_mat(23,i)=yes_11B(i); + x_mat(24,i)=yes_11G(i); + x_mat(25,i)=yes_12(i); + x_mat(26,i)=yes_12B(i); + x_mat(27,i)=yes_12G(i); + +end + +%put them all into a matrix as percent values: +per_mat = zeros(16,r); +for i=1:r + per_mat(1,i)=total_yes(i)/total_ans(i)*100; %total + per_mat(2,i)=yes_boys(i)/total_boys(i)*100; %boys + per_mat(3,i)=yes_girls(i)/total_girls(i)*100; %girls + per_mat(4,i)=yes_W(i)/total_w(i)*100; %whites + per_mat(5,i)=yes_B(i)/total_b(i)*100; %blacks + per_mat(6,i)=yes_H(i)/total_h(i)*100; %hispanics + per_mat(7,i)=yes_O(i)/total_o(i)*100; %other + per_mat(8, i)=yes_WB(i)/total_Wb(i)*100; %WB + per_mat(9, i)=yes_WG(i)/total_Wg(i)*100; %WG + per_mat(10, i)=yes_BB(i)/total_Bb(i)*100; %BB + per_mat(11, i)=yes_BG(i)/total_Bg(i)*100; %BG + per_mat(12, i)=yes_HB(i)/total_Hb(i)*100; %HB + per_mat(13, i)=yes_HG(i)/total_Hg(i)*100; %HG + per_mat(14, i)=yes_OB(i)/total_Ob(i)*100; %OB + per_mat(15, i)=yes_OG(i)/total_Og(i)*100; %OG + per_mat(16, i)=yes_9(i)/total_9(i)*100; + per_mat(17, i)=yes_9B(i)/total_9B(i)*100; + per_mat(18, i)=yes_9G(i)/total_9G(i)*100; + per_mat(19, i)=yes_10(i)/total_10(i)*100; + per_mat(20, i)=yes_10B(i)/total_10B(i)*100; + per_mat(21, i)=yes_10G(i)/total_10G(i)*100; + per_mat(22, i)=yes_11(i)/total_11(i)*100; + per_mat(23, i)=yes_11B(i)/total_11B(i)*100; + per_mat(24, i)=yes_11G(i)/total_11G(i)*100; + per_mat(25, i)=yes_12(i)/total_12(i)*100; + per_mat(26, i)=yes_12B(i)/total_12B(i)*100; + per_mat(27, i)=yes_12G(i)/total_12G(i)*100; +end + +%per_mat=flipud(per_mat); + + label_year={'2009','2011', '2013'}; + label_cell2={'Total', 'Boys', 'Girls', 'W', 'B', 'H', 'O', 'W Boys', 'W Girls', 'B Boys', 'B Girls', 'H Boys', 'H Girls', 'O Boys', 'O Girls', '9th', '9th-Boys', '9th-Girls', '10th','10th-Boys', '10th-Girls', '11th', '11th-Boys', '11th-Girls', '12th', '12th-Boys', '12th-Boys'}; + %per_mat_map(1:15,1:r)=per_mat(1:15,1:r); + %per_mat_map=flipdim(per_mat_map,1); + max_mat=max(max(per_mat)); + if max_mat>75 + M=100; + elseif max_mat>50 + M=75; + elseif max_mat>25 + M=50; + else + M=25; + end + M=50 + %get rid of deimals + per_mat=per_mat*10; + per_mat=round(per_mat); + per_mat=per_mat/10; + h=figure; + title1={'During your life, how many times have you taken a prescription drug'; '(such as OxyContin, Percocet, Vicodin, codeine, Adderall, Ritalin, or Xanax)'; 'without a doctor’s prescription?'}; + [hImage]=heatmap_rb(per_mat, label_year, label_cell2, 1, M, 0, 'Colormap','money', 'UseLogColormap', false, 'ShowAllTicks',true, 'Colorbar',true,'TextColor','k', 'FontSize', 12); + title (title1, 'FontSize', 12, 'fontWeight','bold'); + set (gca, 'FontSize',12); + + + saveas (gcf, 'PO_heatmap.fig'); %can make pdf, jnp, or jpg + print (gcf, '-dpdf', 'PO_heatmap.pdf'); + + close all + +z=1.96; +[r,c]=size(n_mat); +for i=1:r + count=1; + for j=1:c + x=x_mat(i,j); + n=n_mat(i,j); + p=x/n; %x is the number of subjects saying "yes", n is the total subjects + upper=((p+z*sqrt(p*(1-p)/n))*100); + lower=((p-z*sqrt(p*(1-p)/n))*100); + upper=sprintf('%0.1f',round(upper*10)/10); + lower=sprintf('%0.1f',round(lower*10)/10); + conf_mat{i+1,count}=[lower ', ' upper]; + count=count+1; + end +end + diff --git a/sleep/sleep_boys_girls_2013_CI_FINAL.m b/sleep/sleep_boys_girls_2013_CI_FINAL.m new file mode 100644 index 0000000..310a372 --- /dev/null +++ b/sleep/sleep_boys_girls_2013_CI_FINAL.m @@ -0,0 +1,769 @@ + +cd .. +cd .. +cd data +cd Controls_061514 +sex=importdata('sex-NaN.txt', '\t'); +race=importdata('race-NaN.txt', '\t'); +weight=importdata('weights-NaN.txt','\t'); +grade=importdata('grade-NaN.txt','\t'); +[r,c]=size(sex); +weight=weight(4:7,2:c); +race=race(4:7,2:c); +sex=sex(4:7,2:c); +grade=grade(4:7,2:c); +cd .. +cd results_061514 +cd cat +question_mat=importdata('Q80-cat-NaN.txt', '\t'); +[r,c]=size(question_mat); +question_mat=question_mat(:,2:c); +cd .. +cd .. +cd .. +cd programs +cd sleep + +conf_mat=cell(59,9); +conf_mat{1,2}='5hrs or less'; +conf_mat{1,3}='6 hrs'; +conf_mat{1,4}='7 hrs'; +conf_mat{1,5}='8 hrs'; +conf_mat{1,6}='9hrs or more'; +conf_mat{1,7}='5hrs or less'; +conf_mat{1,8}='6 hrs'; +conf_mat{1,9}='7 hrs'; +conf_mat{1,10}='8 hrs'; +conf_mat{1,11}='9hrs or more'; +conf_mat{1,12}='5hrs or less'; +conf_mat{1,13}='6 hrs'; +conf_mat{1,14}='7 hrs'; +conf_mat{1,15}='8 hrs'; +conf_mat{1,16}='9hrs or more'; +conf_mat{1,17}='5hrs or less'; +conf_mat{1,18}='6 hrs'; +conf_mat{1,19}='7 hrs'; +conf_mat{1,20}='8 hrs'; +conf_mat{1,21}='9hrs or more'; +conf_mat{2,1}='total'; +conf_mat{3,1}='girls'; +conf_mat{4,1}='boys'; +conf_mat{5,1}='Wg'; +conf_mat{6,1}='Wb'; +conf_mat{7,1}='Bg'; +conf_mat{8,1}='Bb'; +conf_mat{9,1}='Hg'; +conf_mat{10,1}='Hb'; +conf_mat{11,1}='Og'; +conf_mat{12,1}='Ob'; +conf_mat{13,1}='W'; +conf_mat{14,1}='B'; +conf_mat{15,1}='H'; +conf_mat{16,1}='O'; +conf_mat{17,1}='9'; +conf_mat{18,1}='10'; +conf_mat{19,1}='11'; +conf_mat{20,1}='12'; +conf_mat{21,1}='9g'; +conf_mat{22,1}='9b'; +conf_mat{23,1}='10g'; +conf_mat{24,1}='10b'; +conf_mat{25,1}='11g'; +conf_mat{26,1}='11b'; +conf_mat{27,1}='12g'; +conf_mat{28,1}='12b'; + +conf_mat{29,1}='H9g'; +conf_mat{30,1}='H10g'; +conf_mat{31,1}='H11g'; +conf_mat{32,1}='H12g'; +conf_mat{33,1}='H9b'; +conf_mat{34,1}='H10b'; +conf_mat{35,1}='H11b'; +conf_mat{36,1}='H12b'; +conf_mat{37,1}='W9g'; +conf_mat{38,1}='W10g'; +conf_mat{39,1}='W11g'; +conf_mat{40,1}='W12g'; +conf_mat{41,1}='W9b'; +conf_mat{42,1}='W10b'; +conf_mat{43,1}='W11b'; +conf_mat{44,1}='W12b'; + +conf_mat{45,1}='B9g'; +conf_mat{46,1}='B10g'; +conf_mat{47,1}='B11g'; +conf_mat{48,1}='B12g'; +conf_mat{49,1}='B9b'; +conf_mat{50,1}='B10b'; +conf_mat{51,1}='B11b'; +conf_mat{52,1}='B12b'; +conf_mat{53,1}='O9g'; +conf_mat{54,1}='O10g'; +conf_mat{55,1}='O11g'; +conf_mat{56,1}='O12g'; +conf_mat{57,1}='O9b'; +conf_mat{58,1}='O10b'; +conf_mat{59,1}='O11b'; +conf_mat{60,1}='O12b'; + +n_mat=zeros(59,r); +x_mat=zeros(59,5,r); + +boys=double.empty; +girls=double.empty; +total=double.empty; +c=1; + + +%sleep key A(1)=4 hours or less, B(2)=5 hours, C(3)=6 hours D(4)=7 hours +%E(5)=8 hours, %F(6)=9 hours, %G(7)=10 hours or more +for i=1:r +% total(i)=TOTAL(i,1); + for j=1:7 + n=zeros(59,1); + x=zeros(59,5); + + index_yes{i}=find(question_mat(i,:)==j); + index_girls{i}=find(sex(i,:)==1); + index_boys{i}=find(sex(i,:)==2); + index_W{i}=find(race(i,:)== 1 ); + index_B{i}=find(race(i,:)== 2 ); + index_H{i}=find(race(i,:)== 3 ); + index_O{i}=find(race(i,:)== 4 ); + index_9{i}=find(grade(i,:)== 1 ); + index_10{i}=find(grade(i,:)== 2 ); + index_11{i}=find(grade(i,:)== 3 ); + index_12{i}=find(grade(i,:)== 4 ); + + index_W9{i}=intersect(index_9{i},index_W{i}); + index_W10{i}=intersect(index_10{i},index_W{i}); + index_W11{i}=intersect(index_11{i},index_W{i}); + index_W12{i}=intersect(index_12{i},index_W{i}); + + index_B9{i}=intersect(index_9{i},index_B{i}); + index_B10{i}=intersect(index_10{i},index_B{i}); + index_B11{i}=intersect(index_11{i},index_B{i}); + index_B12{i}=intersect(index_12{i},index_B{i}); + + index_H9{i}=intersect(index_9{i},index_H{i}); + index_H10{i}=intersect(index_10{i},index_H{i}); + index_H11{i}=intersect(index_11{i},index_H{i}); + index_H12{i}=intersect(index_12{i},index_H{i}); + + index_O9{i}=intersect(index_9{i},index_O{i}); + index_O10{i}=intersect(index_10{i},index_O{i}); + index_O11{i}=intersect(index_11{i},index_O{i}); + index_O12{i}=intersect(index_12{i},index_O{i}); + + index_missQ{i}=find(question_mat(i,:)== 0); %students who didn't answer the Q + index_nomiss{i}=find(question_mat(i,:)>0); %answers that were NOT missing (ie. 0's and 1's / no's and yes's) + + index_total_b{i}=intersect(index_nomiss{i},index_boys{i}); %index of all boys who answered + index_total_g{i}=intersect(index_nomiss{i},index_girls{i}); %index of all girls who answered + + w=weight(i,:)'; + total_ans(i)=nansum(w(index_nomiss{i})); + total_girls(i)=nansum(w(index_total_g{i})); %total # of girls who answered + total_boys(i)=nansum(w(index_total_b{i})); %total number of boys who answered + total_W{i}=nansum(w(intersect(index_nomiss{i}, index_W{i}))); %total # of white students who answered + total_B{i}=nansum(w(intersect(index_nomiss{i}, index_B{i}))); %total # of black students who answered + total_H{i}=nansum(w(intersect(index_nomiss{i}, index_H{i}))); %total # of hispanic students who answered + total_O{i}=nansum(w(intersect(index_nomiss{i}, index_O{i}))); %total # of "other" students who answered + + total_w(i)=total_W{i}; + total_b(i)=total_B{i}; + total_h(i)=total_H{i}; + total_o(i)=total_O{i}; + + total_Wb(i)=nansum(w(intersect(index_total_b{i},index_W{i}))); + total_Wg(i)=nansum(w(intersect(index_total_g{i},index_W{i}))); + total_Bb(i)=nansum(w(intersect(index_total_b{i},index_B{i}))); + total_Bg(i)=nansum(w(intersect(index_total_g{i},index_B{i}))); + total_Hb(i)=nansum(w(intersect(index_total_b{i},index_H{i}))); + total_Hg(i)=nansum(w(intersect(index_total_g{i},index_H{i}))); + total_Ob(i)=nansum(w(intersect(index_total_b{i},index_O{i}))); + total_Og(i)=nansum(w(intersect(index_total_g{i},index_O{i}))); + total_9(i)=nansum(w(intersect((index_9{i}),index_nomiss{i}))); + total_10(i)=nansum(w(intersect((index_10{i}),index_nomiss{i}))); + total_11(i)=nansum(w(intersect((index_11{i}),index_nomiss{i}))); + total_12(i)=nansum(w(intersect((index_12{i}),index_nomiss{i}))); + + total_9G(i)=nansum(w(intersect(index_9{i},index_total_g{i}))); + total_10G(i)=nansum(w(intersect(index_10{i},index_total_g{i}))); + total_11G(i)=nansum(w(intersect(index_11{i},index_total_g{i}))); + total_12G(i)=nansum(w(intersect(index_12{i},index_total_g{i}))); + + total_9B(i)=nansum(w(intersect(index_9{i},index_total_b{i}))); + total_10B(i)=nansum(w(intersect(index_10{i},index_total_b{i}))); + total_11B(i)=nansum(w(intersect(index_11{i},index_total_b{i}))); + total_12B(i)=nansum(w(intersect(index_12{i},index_total_b{i}))); + + total_9G_W(i)=nansum(w(intersect(index_W9{i},index_total_g{i}))); + total_9B_W(i)=nansum(w(intersect(index_W9{i},index_total_b{i}))); + total_9G_B(i)=nansum(w(intersect(index_B9{i},index_total_g{i}))); + total_9B_B(i)=nansum(w(intersect(index_B9{i},index_total_b{i}))); + + total_9G_H(i)=nansum(w(intersect(index_H9{i},index_total_g{i}))); + total_9B_H(i)=nansum(w(intersect(index_H9{i},index_total_b{i}))); + total_9G_O(i)=nansum(w(intersect(index_O9{i},index_total_g{i}))); + total_9B_O(i)=nansum(w(intersect(index_O9{i},index_total_b{i}))); + + total_10G_W(i)=nansum(w(intersect(index_W10{i},index_total_g{i}))); + total_10B_W(i)=nansum(w(intersect(index_W10{i},index_total_b{i}))); + total_10G_B(i)=nansum(w(intersect(index_B10{i},index_total_g{i}))); + total_10B_B(i)=nansum(w(intersect(index_B10{i}, index_total_b{i}))); + + total_10G_H(i)=nansum(w(intersect(index_H10{i},index_total_g{i}))); + total_10B_H(i)=nansum(w(intersect(index_H10{i},index_total_b{i}))); + total_10G_O(i)=nansum(w(intersect(index_O10{i},index_total_g{i}))); + total_10B_O(i)=nansum(w(intersect(index_O10{i},index_total_b{i}))); + + total_11G_W(i)=nansum(w(intersect(index_W11{i},index_total_g{i}))); + total_11B_W(i)=nansum(w(intersect(index_W11{i},index_total_b{i}))); + total_11G_B(i)=nansum(w(intersect(index_B11{i},index_total_g{i}))); + total_11B_B(i)=nansum(w(intersect(index_B11{i},index_total_b{i}))); + + total_11G_H(i)=nansum(w(intersect(index_H11{i},index_total_g{i}))); + total_11B_H(i)=nansum(w(intersect(index_H11{i},index_total_b{i}))); + total_11G_O(i)=nansum(w(intersect(index_O11{i},index_total_g{i}))); + total_11B_O(i)=nansum(w(intersect(index_O11{i},index_total_b{i}))); + + total_12G_W(i)=nansum(w(intersect(index_W12{i},index_total_g{i}))); + total_12B_W(i)=nansum(w(intersect(index_W12{i},index_total_b{i}))); + total_12G_B(i)=nansum(w(intersect(index_B12{i},index_total_g{i}))); + total_12B_B(i)=nansum(w(intersect(index_B12{i},index_total_b{i}))); + + total_12G_H(i)=nansum(w(intersect(index_H12{i},index_total_g{i}))); + total_12B_H(i)=nansum(w(intersect(index_H12{i},index_total_b{i}))); + total_12G_O(i)=nansum(w(intersect(index_O12{i},index_total_g{i}))); + total_12B_O(i)=nansum(w(intersect(index_O12{i},index_total_b{i}))); + + total_9_W(i)=nansum(w(intersect(index_nomiss{i},index_W9{i}))); + total_9_B(i)=nansum(w(intersect(index_nomiss{i},index_B9{i}))); + total_9_H(i)=nansum(w(intersect(index_nomiss{i},index_H9{i}))); + total_9_O(i)=nansum(w(intersect(index_nomiss{i},index_O9{i}))); + + total_10_W(i)=nansum(w(intersect(index_nomiss{i},index_W10{i}))); + total_10_B(i)=nansum(w(intersect(index_nomiss{i},index_B10{i}))); + total_10_H(i)=nansum(w(intersect(index_nomiss{i},index_H10{i}))); + total_10_O(i)=nansum(w(intersect(index_nomiss{i},index_O10{i}))); + + total_11_W(i)=nansum(w(intersect(index_nomiss{i},index_W11{i}))); + total_11_B(i)=nansum(w(intersect(index_nomiss{i},index_B11{i}))); + total_11_H(i)=nansum(w(intersect(index_nomiss{i},index_H11{i}))); + total_11_O(i)=nansum(w(intersect(index_nomiss{i},index_O11{i}))); + + total_12_W(i)=nansum(w(intersect(index_nomiss{i},index_W12{i}))); + total_12_B(i)=nansum(w(intersect(index_nomiss{i},index_B12{i}))); + total_12_H(i)=nansum(w(intersect(index_nomiss{i},index_H12{i}))); + total_12_O(i)=nansum(w(intersect(index_nomiss{i},index_O12{i}))); + + w=weight(i,:)'; + index_yesgirls{i}=intersect(index_yes{i},index_girls{i}); + index_yesboys{i}=intersect(index_yes{i},index_boys{i}); + yes_girls(i)=nansum(w(index_yesgirls{i})); + yes_boys(i)=nansum(w(index_yesboys{i})); + total_yes(i)=nansum(w(index_yes{i})); + + yes_W(i)=nansum(w(intersect(index_yes{i}, index_W{i}))); + yes_B(i)=nansum(w(intersect(index_yes{i}, index_B{i}))); + yes_H(i)=nansum(w(intersect(index_yes{i}, index_H{i}))); + yes_O(i)=nansum(w(intersect(index_yes{i}, index_O{i}))); + yes_WG(i)=nansum(w(intersect(index_yesgirls{i},index_W{i}))); + yes_BG(i)=nansum(w(intersect(index_yesgirls{i},index_B{i}))); + yes_HG(i)=nansum(w(intersect(index_yesgirls{i},index_H{i}))); + yes_OG(i)=nansum(w(intersect(index_yesgirls{i},index_O{i}))); + yes_WB(i)=nansum(w(intersect(index_yesboys{i},index_W{i}))); + yes_BB(i)=nansum(w(intersect(index_yesboys{i},index_B{i}))); + yes_HB(i)=nansum(w(intersect(index_yesboys{i},index_H{i}))); + yes_OB(i)=nansum(w(intersect(index_yesboys{i},index_O{i}))); + yes_9(i)=nansum(w(intersect(index_yes{i},index_9{i}))); + yes_10(i)=nansum(w(intersect(index_yes{i},index_10{i}))); + yes_11(i)=nansum(w(intersect(index_yes{i},index_11{i}))); + yes_12(i)=nansum(w(intersect(index_yes{i},index_12{i}))); + yes_9b(i)=nansum(w(intersect(index_yesboys{i},index_9{i}))); + yes_10b(i)=nansum(w(intersect(index_yesboys{i},index_10{i}))); + yes_11b(i)=nansum(w(intersect(index_yesboys{i},index_11{i}))); + yes_12b(i)=nansum(w(intersect(index_yesboys{i},index_12{i}))); + yes_9g(i)=nansum(w(intersect(index_yesgirls{i},index_9{i}))); + yes_10g(i)=nansum(w(intersect(index_yesgirls{i},index_10{i}))); + yes_11g(i)=nansum(w(intersect(index_yesgirls{i},index_11{i}))); + yes_12g(i)=nansum(w(intersect(index_yesgirls{i},index_12{i}))); + + + yes_9WB(i)=nansum(w(intersect(index_yesboys{i},index_W9{i}))); + yes_10WB(i)=nansum(w(intersect(index_yesboys{i},index_W10{i}))); + yes_11WB(i)=nansum(w(intersect(index_yesboys{i},index_W11{i}))); + yes_12WB(i)=nansum(w(intersect(index_yesboys{i},index_W12{i}))); + yes_9WG(i)=nansum(w(intersect(index_yesgirls{i},index_W9{i}))); + yes_10WG(i)=nansum(w(intersect(index_yesgirls{i},index_W10{i}))); + yes_11WG(i)=nansum(w(intersect(index_yesgirls{i},index_W11{i}))); + yes_12WG(i)=nansum(w(intersect(index_yesgirls{i},index_W12{i}))); + + yes_9W(i)=nansum(w(intersect(index_yes{i},index_W9{i}))); + yes_10W(i)=nansum(w(intersect(index_yes{i},(index_W10{i})))); + yes_11W(i)=nansum(w(intersect(index_yes{i},(index_W11{i})))); + yes_12W(i)=nansum(w(intersect(index_yes{i},(index_W12{i})))); + + yes_9B(i)=nansum(w(intersect(index_yes{i},(index_B9{i})))); + yes_10B(i)=nansum(w(intersect(index_yes{i},(index_B10{i})))); + yes_11B(i)=nansum(w(intersect(index_yes{i},(index_B11{i})))); + yes_12B(i)=nansum(w(intersect(index_yes{i},(index_B12{i})))); + + yes_9H(i)=nansum(w(intersect(index_yes{i},(index_H9{i})))); + yes_10H(i)=nansum(w(intersect(index_yes{i},(index_H10{i})))); + yes_11H(i)=nansum(w(intersect(index_yes{i},(index_H11{i})))); + yes_12H(i)=nansum(w(intersect(index_yes{i},(index_H12{i})))); + + yes_9O(i)=nansum(w(intersect(index_yes{i},(index_O9{i})))); + yes_10O(i)=nansum(w(intersect(index_yes{i},(index_O10{i})))); + yes_11O(i)=nansum(w(intersect(index_yes{i},(index_O11{i})))); + yes_12O(i)=nansum(w(intersect(index_yes{i},(index_O12{i})))); + + yes_9BB(i)=nansum(w(intersect(index_yesboys{i},index_B9{i}))); + yes_10BB(i)=nansum(w(intersect(index_yesboys{i},index_B10{i}))); + yes_11BB(i)=nansum(w(intersect(index_yesboys{i},index_B11{i}))); + yes_12BB(i)=nansum(w(intersect(index_yesboys{i},index_B12{i}))); + yes_9BG(i)=nansum(w(intersect(index_yesgirls{i},index_B9{i}))); + yes_10BG(i)=nansum(w(intersect(index_yesgirls{i},index_B10{i}))); + yes_11BG(i)=nansum(w(intersect(index_yesgirls{i},index_B11{i}))); + yes_12BG(i)=nansum(w(intersect(index_yesgirls{i},index_B12{i}))); + + yes_9HB(i)=nansum(w(intersect(index_yesboys{i},index_H9{i}))); + yes_10HB(i)=nansum(w(intersect(index_yesboys{i},index_H10{i}))); + yes_11HB(i)=nansum(w(intersect(index_yesboys{i},index_H11{i}))); + yes_12HB(i)=nansum(w(intersect(index_yesboys{i},index_H12{i}))); + yes_9HG(i)=nansum(w(intersect(index_yesgirls{i},index_H9{i}))); + yes_10HG(i)=nansum(w(intersect(index_yesgirls{i},index_H10{i}))); + yes_11HG(i)=nansum(w(intersect(index_yesgirls{i},index_H11{i}))); + yes_12HG(i)=nansum(w(intersect(index_yesgirls{i},index_H12{i}))); + + yes_9OB(i)=nansum(w(intersect(index_yesboys{i},index_O9{i}))); + yes_10OB(i)=nansum(w(intersect(index_yesboys{i},index_O10{i}))); + yes_11OB(i)=nansum(w(intersect(index_yesboys{i},index_O11{i}))); + yes_12OB(i)=nansum(w(intersect(index_yesboys{i},index_O12{i}))); + yes_9OG(i)=nansum(w(intersect(index_yesgirls{i},index_O9{i}))); + yes_10OG(i)=nansum(w(intersect(index_yesgirls{i},index_O10{i}))); + yes_11OG(i)=nansum(w(intersect(index_yesgirls{i},index_O11{i}))); + yes_12OG(i)=nansum(w(intersect(index_yesgirls{i},index_O12{i}))); + + girls(1, c)=yes_girls(i)/total_girls(i)*100; %girls + girls(2, c)=yes_WG(i)/total_Wg(i)*100; %WG + girls(3, c)=yes_BG(i)/total_Bg(i)*100; %BG + girls(4, c)=yes_HG(i)/total_Hg(i)*100; %HG + girls(5, c)=yes_OG(i)/total_Og(i)*100; %OG + girls(6, c)=yes_9g(i)/total_9G(i)*100; + girls(7, c)=yes_10g(i)/total_10G(i)*100; + girls(8, c)=yes_11g(i)/total_11G(i)*100; + girls(9, c)=yes_12g(i)/total_12G(i)*100; + girls(10, c)=yes_9WG(i)/total_9G_W(i)*100; + girls(11, c)=yes_10WG(i)/total_10G_W(i)*100; + girls(12, c)=yes_11WG(i)/total_11G_W(i)*100; + girls(13, c)=yes_12WG(i)/total_12G_W(i)*100; + girls(14, c)=yes_9BG(i)/total_9G_B(i)*100; + girls(15, c)=yes_10BG(i)/total_10G_B(i)*100; + girls(16, c)=yes_11BG(i)/total_11G_B(i)*100; + girls(17, c)=yes_12BG(i)/total_12G_B(i)*100; + girls(18, c)=yes_9HG(i)/total_9G_H(i)*100; + girls(19, c)=yes_10HG(i)/total_10G_H(i)*100; + girls(20, c)=yes_11HG(i)/total_11G_H(i)*100; + girls(21, c)=yes_12HG(i)/total_12G_H(i)*100; + girls(22, c)=yes_9OG(i)/total_9G_O(i)*100; + girls(23, c)=yes_10OG(i)/total_10G_O(i)*100; + girls(24, c)=yes_11OG(i)/total_11G_O(i)*100; + girls(25, c)=yes_12OG(i)/total_12G_O(i)*100; + + boys(1, c)=yes_boys(i)/total_boys(i)*100; %boys + boys(2, c)=yes_WB(i)/total_Wb(i)*100; %WB + boys (3, c)=yes_BB(i)/total_Bb(i)*100; %BB + boys(4, c)=yes_HB(i)/total_Hb(i)*100; %HB + boys(5, c)=yes_OB(i)/total_Ob(i)*100; %OB + boys(6, c)=yes_9b(i)/total_9B(i)*100; + boys(7, c)=yes_10b(i)/total_10B(i)*100; + boys(8, c)=yes_11b(i)/total_11B(i)*100; + boys(9, c)=yes_12b(i)/total_12B(i)*100; + boys(10, c)=yes_9WB(i)/total_9B_W(i)*100; + boys(11, c)=yes_10WB(i)/total_10B_W(i)*100; + boys(12, c)=yes_11WB(i)/total_11B_W(i)*100; + boys(13, c)=yes_12WB(i)/total_12B_W(i)*100; + boys(14, c)=yes_9BB(i)/total_9B_B(i)*100; + boys(15, c)=yes_10BB(i)/total_10B_B(i)*100; + boys(16, c)=yes_11BB(i)/total_11B_B(i)*100; + boys(17, c)=yes_12BB(i)/total_12B_B(i)*100; + boys(18, c)=yes_9HB(i)/total_9B_H(i)*100; + boys(19, c)=yes_10HB(i)/total_10B_H(i)*100; + boys(20, c)=yes_11HB(i)/total_11B_H(i)*100; + boys(21, c)=yes_12HB(i)/total_12B_H(i)*100; + boys(22, c)=yes_9OB(i)/total_9B_O(i)*100; + boys(23, c)=yes_10OB(i)/total_10B_O(i)*100; + boys(24, c)=yes_11OB(i)/total_11B_O(i)*100; + boys(25, c)=yes_12OB(i)/total_12B_O(i)*100; + + total(1,c)=total_yes(i)/total_ans(i)*100; %total + total(2,c)=yes_boys(i)/total_boys(i)*100; %boys + total(3,c)=yes_girls(i)/total_girls(i)*100; %girls + total(4,c)=yes_W(i)/total_w(i)*100; %whites + total(5,c)=yes_B(i)/total_b(i)*100; %blacks + total(6,c)=yes_H(i)/total_h(i)*100; %hispanics + total(7,c)=yes_O(i)/total_o(i)*100; %other + total(8,c)=yes_9(i)/total_9(i)*100; + total(9,c)=yes_10(i)/total_10(i)*100; + total(10,c)=yes_11(i)/total_11(i)*100; + total(11,c)=yes_12(i)/total_12(i)*100; + total(12, c)=yes_9W(i)/total_9_W(i)*100; + total(13, c)=yes_10W(i)/total_10_W(i)*100; + total(14, c)=yes_11W(i)/total_11_W(i)*100; + total(15, c)=yes_12W(i)/total_12_W(i)*100; + total(16, c)=yes_9B(i)/total_9_B(i)*100; + total(17, c)=yes_10B(i)/total_10_B(i)*100; + total(18, c)=yes_11B(i)/total_11_B(i)*100; + total(19, c)=yes_12B(i)/total_12_B(i)*100; + total(20, c)=yes_9H(i)/total_9_H(i)*100; + total(21, c)=yes_10H(i)/total_10_H(i)*100; + total(22, c)=yes_11H(i)/total_11_H(i)*100; + total(23, c)=yes_12H(i)/total_12_H(i)*100; + total(24, c)=yes_9O(i)/total_9_O(i)*100; + total(25, c)=yes_10O(i)/total_10_O(i)*100; + total(26, c)=yes_11O(i)/total_11_O(i)*100; + total(27, c)=yes_12O(i)/total_12_O(i)*100; + + c=c+1; + + %for stats + n_mat (1,i)= total_ans(i); + n_mat (2,i)=total_girls(i); + n_mat (3,i)=total_boys(i); + n_mat (4,i)=total_Wg(i); + n_mat (5,i)=total_Wb(i); + n_mat (6,i)=total_Bg(i); + n_mat (7,i)=total_Bb(i); + n_mat (8,i)=total_Hg(i); + n_mat (9,i)=total_Hb(i); + n_mat (10,i)=total_Og(i); + n_mat (11,i)=total_Ob(i); + n_mat (12,i)=total_w(i); + n_mat (13,i)=total_b(i); + n_mat (14,i)=total_h(i); + n_mat (15,i)=total_o(i); + n_mat (16,i)=total_9(i); + n_mat (17,i)=total_10(i); + n_mat (18,i)=total_11(i); + n_mat (19,i)=total_12(i); + n_mat (20,i)=total_9G(i); + n_mat (21,i)=total_9B(i); + n_mat (22,i)=total_10G(i); + n_mat (23,i)=total_10B(i); + n_mat (24,i)=total_11G(i); + n_mat (25,i)=total_11B(i); + n_mat (26,i)=total_12G(i); + n_mat (27,i)=total_12B(i); + + n_mat (28,i)=total_9G_H(i); + n_mat (29,i)=total_10G_H(i); + n_mat (30,i)=total_11G_H(i); + n_mat (31,i)=total_12G_H(i); + n_mat (32,i)=total_9B_H(i); + n_mat (33,i)=total_10B_H(i); + n_mat (34,i)=total_11B_H(i); + n_mat (35,i)=total_12B_H(i); + + n_mat (36,i)=total_9G_W(i); + n_mat (37,i)=total_10G_W(i); + n_mat (38,i)=total_11G_W(i); + n_mat (39,i)=total_12G_W(i); + n_mat (40,i)=total_9B_W(i); + n_mat (41,i)=total_10B_W(i); + n_mat (42,i)=total_11B_W(i); + n_mat (43,i)=total_12B_W(i); + + n_mat (44,i)=total_9G_B(i); + n_mat (45,i)=total_10G_B(i); + n_mat (46,i)=total_11G_B(i); + n_mat (47,i)=total_12G_B(i); + n_mat (48,i)=total_9B_B(i); + n_mat (49,i)=total_10B_B(i); + n_mat (50,i)=total_11B_B(i); + n_mat (51,i)=total_12B_B(i); + + n_mat (52,i)=total_9G_O(i); + n_mat (53,i)=total_10G_O(i); + n_mat (54,i)=total_11G_O(i); + n_mat (55,i)=total_12G_O(i); + n_mat (56,i)=total_9B_O(i); + n_mat (57,i)=total_10B_O(i); + n_mat (58,i)=total_11B_O(i); + n_mat (59,i)=total_12B_O(i); + + if (j<3) %5 hours or less + x(1,1)=total_yes(i); + x(2,1)=yes_girls(i); + x(3,1)=yes_boys(i); + x(4,1)=yes_WG(i); + x(5,1)=yes_WB(i); + x(6,1)=yes_BG(i); + x(7,1)=yes_BB(i); + x(8,1)=yes_HG(i); + x(9,1)=yes_HB(i); + x(10,1)=yes_OG(i); + x(11,1)=yes_OB(i); + x(12,1)=yes_W(i); + x(13,1)=yes_B(i); + x(14,1)=yes_H(i); + x(15,1)=yes_O(i); + x(16,1)=yes_9(i); + x(17,1)=yes_10(i); + x(18,1)=yes_11(i); + x(19,1)=yes_12(i); + x(20,1)=yes_9g(i); + x(21,1)=yes_9b(i); + x(22,1)=yes_10g(i); + x(23,1)=yes_10b(i); + x(24,1)=yes_11g(i); + x(25,1)=yes_11b(i); + x(26,1)=yes_12g(i); + x(27,1)=yes_12b(i); + + x(28,1)=yes_9HG(i); + x(29, 1)=yes_10HG(i); + x(30, 1)=yes_11HG(i); + x(31, 1)=yes_12HG(i); + x(32, 1)=yes_9HB(i); + x(33, 1)=yes_10HB(i); + x(34, 1)=yes_11HB(i); + x(35, 1)=yes_12HB(i); + + x(36, 1)=yes_9WG(i); + x(37, 1)=yes_10WG(i); + x(38, 1)=yes_11WG(i); + x(39, 1)=yes_12WG(i); + x(40, 1)=yes_9WB(i); + x(41, 1)=yes_10WB(i); + x(42, 1)=yes_11WB(i); + x(43, 1)=yes_12WB(i); + + x(44, 1)=yes_9BG(i); + x(45, 1)=yes_10BG(i); + x(46, 1)=yes_11BG(i); + x(47, 1)=yes_12BG(i); + x(48, 1)=yes_9BB(i); + x(49, 1)=yes_10BB(i); + x(50, 1)=yes_11BB(i); + x(51, 1)=yes_12BB(i); + + x(52, 1)=yes_9OG(i); + x(53, 1)=yes_10OG(i); + x(54, 1)=yes_11OG(i); + x(55, 1)=yes_12OG(i); + x(56, 1)=yes_9OB(i); + x(57, 1)=yes_10OB(i); + x(58, 1)=yes_11OB(i); + x(59, 1)=yes_12OB(i); + + x_mat(:,1, i)=x_mat(:, 1, i)+x(:,1); + elseif (j>5) %9 hours or more + x(1,5)=total_yes(i); + x(2,5)=yes_girls(i); + x(3,5)=yes_boys(i); + x(4,5)=yes_WG(i); + x(5,5)=yes_WB(i); + x(6,5)=yes_BG(i); + x(7,5)=yes_BB(i); + x(8,5)=yes_HG(i); + x(9,5)=yes_HB(i); + x(10,5)=yes_OG(i); + x(11,5)=yes_OB(i); + x(12,5)=yes_W(i); + x(13,5)=yes_B(i); + x(14,5)=yes_H(i); + x(15,5)=yes_O(i); + x(16,5)=yes_9(i); + x(17,5)=yes_10(i); + x(18,5)=yes_11(i); + x(19,5)=yes_12(i); + x(20,5)=yes_9g(i); + x(21,5)=yes_9b(i); + x(22,5)=yes_10g(i); + x(23,5)=yes_10b(i); + x(24,5)=yes_11g(i); + x(25,5)=yes_11b(i); + x(26,5)=yes_12g(i); + x(27,5)=yes_12b(i); + + x(28,5)=yes_9HG(i); + x(29, 5)=yes_10HG(i); + x(30, 5)=yes_11HG(i); + x(31, 5)=yes_12HG(i); + x(32, 5)=yes_9HB(i); + x(33, 5)=yes_10HB(i); + x(34, 5)=yes_11HB(i); + x(35, 5)=yes_12HB(i); + + x(36, 5)=yes_9WG(i); + x(37, 5)=yes_10WG(i); + x(38, 5)=yes_11WG(i); + x(39, 5)=yes_12WG(i); + x(40, 5)=yes_9WB(i); + x(41, 5)=yes_10WB(i); + x(42, 5)=yes_11WB(i); + x(43, 5)=yes_12WB(i); + + x(44, 5)=yes_9BG(i); + x(45, 5)=yes_10BG(i); + x(46, 5)=yes_11BG(i); + x(47, 5)=yes_12BG(i); + x(48, 5)=yes_9BB(i); + x(49, 5)=yes_10BB(i); + x(50, 5)=yes_11BB(i); + x(51, 5)=yes_12BB(i); + + x(52, 5)=yes_9OG(i); + x(53, 5)=yes_10OG(i); + x(54, 5)=yes_11OG(i); + x(55, 5)=yes_12OG(i); + x(56, 5)=yes_9OB(i); + x(57, 5)=yes_10OB(i); + x(58, 5)=yes_11OB(i); + x(59, 5)=yes_12OB(i); + + x_mat(:,5, i)=x_mat(:,5, i)+x(:,5); + else + + x_mat(1,j-1, i)=total_yes(i); + x_mat(2,j-1, i)=yes_girls(i); + x_mat(3,j-1, i)=yes_boys(i); + x_mat(4,j-1, i)=yes_WG(i); + x_mat(5,j-1, i)=yes_WB(i); + x_mat(6,j-1, i)=yes_BG(i); + x_mat(7,j-1, i)=yes_BB(i); + x_mat(8,j-1, i)=yes_HG(i); + x_mat(9,j-1, i)=yes_HB(i); + x_mat(10,j-1, i)=yes_OG(i); + x_mat(11,j-1, i)=yes_OB(i); + x_mat(12,j-1, i)=yes_W(i); + x_mat(13,j-1, i)=yes_B(i); + x_mat(14,j-1, i)=yes_H(i); + x_mat(15,j-1, i)=yes_O(i); + x_mat(16,j-1, i)=yes_9(i); + x_mat(17,j-1, i)=yes_10(i); + x_mat(18,j-1, i)=yes_11(i); + x_mat(19,j-1, i)=yes_12(i); + x_mat(20,j-1, i)=yes_9g(i); + x_mat(21,j-1, i)=yes_9b(i); + x_mat(22,j-1, i)=yes_10g(i); + x_mat(23,j-1, i)=yes_10b(i); + x_mat(24,j-1, i)=yes_11g(i); + x_mat(25,j-1, i)=yes_11b(i); + x_mat(26,j-1, i)=yes_12g(i); + x_mat(27,j-1, i)=yes_12b(i); + + x_mat(28,j-1, i)=yes_9HG(i); + x_mat(29, j-1, i)=yes_10HG(i); + x_mat(30, j-1, i)=yes_11HG(i); + x_mat(31, j-1, i)=yes_12HG(i); + x_mat(32, j-1, i)=yes_9HB(i); + x_mat(33, j-1, i)=yes_10HB(i); + x_mat(34, j-1, i)=yes_11HB(i); + x_mat(35, j-1, i)=yes_12HB(i); + + x_mat(36, j-1, i)=yes_9WG(i); + x_mat(37, j-1, i)=yes_10WG(i); + x_mat(38, j-1, i)=yes_11WG(i); + x_mat(39, j-1, i)=yes_12WG(i); + x_mat(40, j-1, i)=yes_9WB(i); + x_mat(41, j-1, i)=yes_10WB(i); + x_mat(42, j-1, i)=yes_11WB(i); + x_mat(43, j-1, i)=yes_12WB(i); + + x_mat(44, j-1, i)=yes_9BG(i); + x_mat(45, j-1, i)=yes_10BG(i); + x_mat(46, j-1, i)=yes_11BG(i); + x_mat(47, j-1, i)=yes_12BG(i); + x_mat(48, j-1, i)=yes_9BB(i); + x_mat(49, j-1, i)=yes_10BB(i); + x_mat(50, j-1, i)=yes_11BB(i); + x_mat(51, j-1, i)=yes_12BB(i); + + x_mat(52, j-1, i)=yes_9OG(i); + x_mat(53, j-1, i)=yes_10OG(i); + x_mat(54, j-1, i)=yes_11OG(i); + x_mat(55, j-1, i)=yes_12OG(i); + x_mat(56, j-1, i)=yes_9OB(i); + x_mat(57, j-1, i)=yes_10OB(i); + x_mat(58, j-1, i)=yes_11OB(i); + x_mat(59, j-1, i)=yes_12OB(i); + + end + + + end +end + +c=1; +c2=1; +%sleep key A(1)=4 hours or less, B(2)=5 hours, C(3)=6 hours D(4)=7 hours +%E(5)=8 hours, %F(6)=9 hours, %G(7)=10 hours or more +final_boys=double.empty; + +for i=1:4 + final_boys(:,c)=boys(:,c2)+boys(:,c2+1); + final_boys(:,c+1)=boys(:,c2+2); + final_boys(:,c+2)=boys(:,c2+3); + final_boys(:,c+3)=boys(:,c2+4); + final_boys(:,c+4)=boys(:,c2+5) + boys(:,c2+6); + c2=c2+7; + c=c+5; +end + +c=1; +c2=1; +%sleep key A(1)=4 hours or less, B(2)=5 hours, C(3)=6 hours D(4)=7 hours +%E(5)=8 hours, %F(6)=9 hours, %G(7)=10 hours or more +final_girls=double.empty; +for i=1:4 + final_girls(:,c)=girls(:,c2)+girls(:,c2+1); + final_girls(:,c+1)=girls(:,c2+2); + final_girls(:,c+2)=girls(:,c2+3); + final_girls(:,c+3)=girls(:,c2+4); + final_girls(:,c+4)=girls(:,c2+5) + girls(:,c2+6); + c2=c2+7; + c=c+5; +end + +c=1; +c2=1; +%sleep key A(1)=4 hours or less, B(2)=5 hours, C(3)=6 hours D(4)=7 hours +%E(5)=8 hours, %F(6)=9 hours, %G(7)=10 hours or more +final_total=double.empty; + +for i=1:4 + final_total(:,c)=total(:,c2)+total(:,c2+1); + final_total(:,c+1)=total(:,c2+2); + final_total(:,c+2)=total(:,c2+3); + final_total(:,c+3)=total(:,c2+4); + final_total(:,c+4)=total(:,c2+5) + total(:,c2+6); + c2=c2+7; + c=c+5; +end + +%confidence interval + +z=1.96; +for i=1:59 + count=2; + for j=1:r + n=n_mat(i,j); + for k=1:5 + x=x_mat(i,k, j); %x_mat=zeros(59,5,r); + p=x/n; %x is the number of subjects saying "yes", n is the total subjects + upper=((p+z*sqrt(p*(1-p)/n))*100); + lower=((p-z*sqrt(p*(1-p)/n))*100); + upper=sprintf('%0.1f',round(upper*10)/10); + lower=sprintf('%0.1f',round(lower*10)/10); + conf_mat{i+1,count}=[lower ', ' upper]; + count=count+1; + end + end +end + + diff --git a/sleep/sleep_boys_girls_2013_CI_v2.m b/sleep/sleep_boys_girls_2013_CI_v2.m new file mode 100644 index 0000000..a4ec777 --- /dev/null +++ b/sleep/sleep_boys_girls_2013_CI_v2.m @@ -0,0 +1,262 @@ + +cd .. +cd .. +cd data +cd Controls_061514 +sex=importdata('sex-NaN.txt', '\t'); +race=importdata('race-NaN.txt', '\t'); +weight=importdata('weights-NaN.txt','\t'); +grade=importdata('grade-NaN.txt','\t'); +weight=weight(5:7,:); +race=race(5:7,:); +sex=sex(5:7,:); +grade=grade(5:7,:); +cd .. +cd results_091614 +cd cat +question_mat=importdata('Q80-cat-NaN.txt', '\t'); +[r,c]=size(question_mat); +%question_mat=question_mat(:,2:c); +question_mat(:,1)=9; +cd .. +cd .. +cd .. + +cd programs +cd prescriptiondrugs +cd results + +conf_mat=cell.empty; +n_mat=double.empty; +x_mat=double.empty; + +for i=1:r +% total(i)=TOTAL(i,1); + for j=1:7 + index_yes{i}=find(question_mat(i,:)==1); + index_girls{i}=find(sex(i,:)==1); + index_boys{i}=find(sex(i,:)==2); + index_W{i}=find(race(i,:)== 1 ); + index_B{i}=find(race(i,:)== 2 ); + index_H{i}=find(race(i,:)== 3 ); + index_O{i}=find(race(i,:)== 4 ); + index_9{i}=find(grade(i,:)== 1 ); + index_10{i}=find(grade(i,:)== 2 ); + index_11{i}=find(grade(i,:)== 3 ); + index_12{i}=find(grade(i,:)== 4 ); + + index_missQ{i}=find(question_mat(i,:)==9); %students who didn't answer the Q + index_nomiss{i}=find(question_mat(i,:)==0 | question_mat(i,:)==1); %answers that were NOT missing (ie. 0's and 1's / no's and yes's) + + missQ(i)=length(index_missQ{i}); %number of students who answered the question each year + index_total_b{i}=intersect(index_nomiss{i},index_boys{i}); %index of all boys who answered + index_total_g{i}=intersect(index_nomiss{i},index_girls{i}); %index of all girls who answered + + w=weight(i,:)'; + total_ans(i)=nansum(w(index_nomiss{i})); + total_girls(i)=nansum(w(index_total_g{i})); %total # of girls who answered + total_boys(i)=nansum(w(index_total_b{i})); %total number of boys who answered + total_W{i}=nansum(w(intersect(index_nomiss{i}, index_W{i}))); %total # of white students who answered + total_B{i}=nansum(w(intersect(index_nomiss{i}, index_B{i}))); %total # of black students who answered + total_H{i}=nansum(w(intersect(index_nomiss{i}, index_H{i}))); %total # of hispanic students who answered + total_O{i}=nansum(w(intersect(index_nomiss{i}, index_O{i}))); %total # of "other" students who answered + total_Wb(i)=nansum(w(intersect(index_total_b{i},index_W{i}))); + total_Wg(i)=nansum(w(intersect(index_total_g{i},index_W{i}))); + total_Bb(i)=nansum(w(intersect(index_total_b{i},index_B{i}))); + total_Bg(i)=nansum(w(intersect(index_total_g{i},index_B{i}))); + total_Hb(i)=nansum(w(intersect(index_total_b{i},index_H{i}))); + total_Hg(i)=nansum(w(intersect(index_total_g{i},index_H{i}))); + total_Ob(i)=nansum(w(intersect(index_total_b{i},index_O{i}))); + total_Og(i)=nansum(w(intersect(index_total_g{i},index_O{i}))); + total_9(i)=nansum(w(intersect((index_9{i}),index_nomiss{i}))); + total_10(i)=nansum(w(intersect((index_10{i}),index_nomiss{i}))); + total_11(i)=nansum(w(intersect((index_11{i}),index_nomiss{i}))); + total_12(i)=nansum(w(intersect((index_12{i}),index_nomiss{i}))); + total_9G(i)=nansum(w(intersect(index_9{i},index_total_g{i}))); + total_10G(i)=nansum(w(intersect(index_10{i},index_total_g{i}))); + total_11G(i)=nansum(w(intersect(index_11{i},index_total_g{i}))); + total_12G(i)=nansum(w(intersect(index_12{i},index_total_g{i}))); + total_9B(i)=nansum(w(intersect(index_9{i},index_total_b{i}))); + total_10B(i)=nansum(w(intersect(index_10{i},index_total_b{i}))); + total_11B(i)=nansum(w(intersect(index_11{i},index_total_b{i}))); + total_12B(i)=nansum(w(intersect(index_12{i},index_total_b{i}))); + + %make n_mat + n_mat(1,i)=total_ans(i); + n_mat(2,i)=total_girls(i); + n_mat(3,i)=total_boys(i); + n_mat(4,i)=total_W{i}; + n_mat(5,i)=total_B{i}; + n_mat(6,i)=total_H{i}; + n_mat(7,i)=total_O{i}; + n_mat(8,i)=total_Wb(i); + n_mat(9,i)= total_Wg(i); + n_mat(10,i)=total_Bb(i); + n_mat(11,i)=total_Bg(i); + n_mat(12,i)=total_Hb(i); + n_mat(13,i)=total_Hg(i); + n_mat(14,i)=total_Ob(i); + n_mat(15,i)=total_Og(i); + n_mat(16,i)=total_9(i); + n_mat(17,i)=total_9B(i); + n_mat(18,i)=total_9G(i); + n_mat(19,i)=total_10(i); + n_mat(20,i)=total_10B(i); + n_mat(21,i)=total_10G(i); + n_mat(22,i)=total_11(i); + n_mat(23,i)=total_11B(i); + n_mat(24,i)=total_11G(i); + n_mat(25,i)=total_12(i); + n_mat(26,i)=total_12B(i); + n_mat(27,i)=total_12G(i); + + + index_yesgirls{i}=intersect(index_yes{i},index_girls{i}); + index_yesboys{i}=intersect(index_yes{i},index_boys{i}); + yes_girls(i)=nansum(w(index_yesgirls{i})); + yes_boys(i)=nansum(w(index_yesboys{i})); + yes_W(i)=nansum(w(intersect(index_yes{i}, index_W{i}))); + yes_B(i)=nansum(w(intersect(index_yes{i}, index_B{i}))); + yes_H(i)=nansum(w(intersect(index_yes{i}, index_H{i}))); + yes_O(i)=nansum(w(intersect(index_yes{i}, index_O{i}))); + yes_WG(i)=nansum(w(intersect(index_yesgirls{i},index_W{i}))); + yes_BG(i)=nansum(w(intersect(index_yesgirls{i},index_B{i}))); + yes_HG(i)=nansum(w(intersect(index_yesgirls{i},index_H{i}))); + yes_OG(i)=nansum(w(intersect(index_yesgirls{i},index_O{i}))); + yes_WB(i)=nansum(w(intersect(index_yesboys{i},index_W{i}))); + yes_BB(i)=nansum(w(intersect(index_yesboys{i},index_B{i}))); + yes_HB(i)=nansum(w(intersect(index_yesboys{i},index_H{i}))); + yes_OB(i)=nansum(w(intersect(index_yesboys{i},index_O{i}))); + total_yes(i)=nansum(w(index_yes{i})); + yes_9(i)=nansum(w(intersect(index_yes{i},index_9{i}))); + yes_10(i)=nansum(w(intersect(index_yes{i},index_10{i}))); + yes_11(i)=nansum(w(intersect(index_yes{i},index_11{i}))); + yes_12(i)=nansum(w(intersect(index_yes{i},index_12{i}))); + yes_9B(i)=nansum(w(intersect(index_yesboys{i},index_9{i}))); + yes_10B(i)=nansum(w(intersect(index_yesboys{i},index_10{i}))); + yes_11B(i)=nansum(w(intersect(index_yesboys{i},index_11{i}))); + yes_12B(i)=nansum(w(intersect(index_yesboys{i},index_12{i}))); + yes_9G(i)=nansum(w(intersect(index_yesgirls{i},index_9{i}))); + yes_10G(i)=nansum(w(intersect(index_yesgirls{i},index_10{i}))); + yes_11G(i)=nansum(w(intersect(index_yesgirls{i},index_11{i}))); + yes_12G(i)=nansum(w(intersect(index_yesgirls{i},index_12{i}))); + total_w(i)=total_W{i}; + total_b(i)=total_B{i}; + total_h(i)=total_H{i}; + total_o(i)=total_O{i}; + + + %make x_mat + x_mat(1,i)=total_yes(i); + x_mat(2,i)=yes_boyss(i); + x_mat(3,i)=yes_girls(i); + x_mat(4,i)=yes_W(i); + x_mat(5,i)=yes_B(i); + x_mat(6,i)=yes_H(i); + x_mat(7,i)=yes_O(i); + x_mat(8,i)=yes_WB(i); + x_mat(9,i)= yes_WG(i); + x_mat(10,i)=yes_BB(i); + x_mat(11,i)=yes_BG(i); + x_mat(12,i)=yes_HB(i); + x_mat(13,i)=yes_HG(i); + x_mat(14,i)=yes_OB(i); + x_mat(15,i)=yes_OG(i); + x_mat(16,i)=yes_9(i); + x_mat(17,i)=yes_9B(i); + x_mat(18,i)=yes_9G(i); + x_mat(19,i)=yes_10(i); + x_mat(20,i)=yes_10B(i); + x_mat(21,i)=yes_10G(i); + x_mat(22,i)=yes_11(i); + x_mat(23,i)=yes_11B(i); + x_mat(24,i)=yes_11G(i); + x_mat(25,i)=yes_12(i); + x_mat(26,i)=yes_12B(i); + x_mat(27,i)=yes_12G(i); + + end + + %put them all into a matrix as percent values: + per_mat = zeros(16,r); + for i=1:r + per_mat(1,i)=total_yes(i)/total_ans(i)*100; %total + per_mat(2,i)=yes_boys(i)/total_boys(i)*100; %boys + per_mat(3,i)=yes_girls(i)/total_girls(i)*100; %girls + per_mat(4,i)=yes_W(i)/total_w(i)*100; %whites + per_mat(5,i)=yes_B(i)/total_b(i)*100; %blacks + per_mat(6,i)=yes_H(i)/total_h(i)*100; %hispanics + per_mat(7,i)=yes_O(i)/total_o(i)*100; %other + per_mat(8, i)=yes_WB(i)/total_Wb(i)*100; %WB + per_mat(9, i)=yes_WG(i)/total_Wg(i)*100; %WG + per_mat(10, i)=yes_BB(i)/total_Bb(i)*100; %BB + per_mat(11, i)=yes_BG(i)/total_Bg(i)*100; %BG + per_mat(12, i)=yes_HB(i)/total_Hb(i)*100; %HB + per_mat(13, i)=yes_HG(i)/total_Hg(i)*100; %HG + per_mat(14, i)=yes_OB(i)/total_Ob(i)*100; %OB + per_mat(15, i)=yes_OG(i)/total_Og(i)*100; %OG + per_mat(16, i)=yes_9(i)/total_9(i)*100; + per_mat(17, i)=yes_9B(i)/total_9B(i)*100; + per_mat(18, i)=yes_9G(i)/total_9G(i)*100; + per_mat(19, i)=yes_10(i)/total_10(i)*100; + per_mat(20, i)=yes_10B(i)/total_10B(i)*100; + per_mat(21, i)=yes_10G(i)/total_10G(i)*100; + per_mat(22, i)=yes_11(i)/total_11(i)*100; + per_mat(23, i)=yes_11B(i)/total_11B(i)*100; + per_mat(24, i)=yes_11G(i)/total_11G(i)*100; + per_mat(25, i)=yes_12(i)/total_12(i)*100; + per_mat(26, i)=yes_12B(i)/total_12B(i)*100; + per_mat(27, i)=yes_12G(i)/total_12G(i)*100; + end +end + +%per_mat=flipud(per_mat); + + label_year={'2009','2011', '2013'}; + label_cell2={'Total', 'Boys', 'Girls', 'W', 'B', 'H', 'O', 'W Boys', 'W Girls', 'B Boys', 'B Girls', 'H Boys', 'H Girls', 'O Boys', 'O Girls', '9th', '9th-Boys', '9th-Girls', '10th','10th-Boys', '10th-Girls', '11th', '11th-Boys', '11th-Girls', '12th', '12th-Boys', '12th-Boys'}; + %per_mat_map(1:15,1:r)=per_mat(1:15,1:r); + %per_mat_map=flipdim(per_mat_map,1); + max_mat=max(max(per_mat)); + if max_mat>75 + M=100; + elseif max_mat>50 + M=75; + elseif max_mat>25 + M=50; + else + M=25; + end + M=50 + %get rid of deimals + per_mat=per_mat*10; + per_mat=round(per_mat); + per_mat=per_mat/10; + h=figure; + title1={'During your life, how many times have you taken a prescription drug'; '(such as OxyContin, Percocet, Vicodin, codeine, Adderall, Ritalin, or Xanax)'; 'without a doctor’s prescription?'}; + [hImage]=heatmap_rb(per_mat, label_year, label_cell2, 1, M, 0, 'Colormap','money', 'UseLogColormap', false, 'ShowAllTicks',true, 'Colorbar',true,'TextColor','k', 'FontSize', 12); + title (title1, 'FontSize', 12, 'fontWeight','bold'); + set (gca, 'FontSize',12); + + + saveas (gcf, 'PO_heatmap.fig'); %can make pdf, jnp, or jpg + print (gcf, '-dpdf', 'PO_heatmap.pdf'); + + close all + +z=1.96; +[r,c]=size(n_mat); +for i=1:r + count=1; + for j=1:c + x=x_mat(i,j); + n=n_mat(i,j); + p=x/n; %x is the number of subjects saying "yes", n is the total subjects + upper=((p+z*sqrt(p*(1-p)/n))*100); + lower=((p-z*sqrt(p*(1-p)/n))*100); + upper=sprintf('%0.1f',round(upper*10)/10); + lower=sprintf('%0.1f',round(lower*10)/10); + conf_mat{i+1,count}=[lower ', ' upper]; + count=count+1; + end +end + diff --git a/sleep/sleep_comparisons.m b/sleep/sleep_comparisons.m index 06e7670..b04f069 100644 --- a/sleep/sleep_comparisons.m +++ b/sleep/sleep_comparisons.m @@ -14,7 +14,7 @@ sex=sex(:,2:c); grade=grade(:,2:c); cd .. -cd results_091614 +cd results_103114 cd cat question_mat=importdata('Q80-cat-NaN.txt', '\t'); [r,c]=size(question_mat); diff --git a/sleep/sleep_comparisonsv2.m b/sleep/sleep_comparisonsv2.m new file mode 100644 index 0000000..a95c545 --- /dev/null +++ b/sleep/sleep_comparisonsv2.m @@ -0,0 +1,177 @@ + +GRADE=input('What grade are you interested in? (0=all, 1=9th, 2=10th, 3=11th, 4=12th): '); +SEX=input('What sex are you interested in? (0=all, 1=girls, 2=boys): '); +RACE=input('What race are you interested in? (0=all, 1=white, 2=black, 3=hispanic, 4=other): '); + +cd .. +cd .. +cd data +cd Controls_061514 +sex=importdata('sex-NaN.txt', '\t'); +race=importdata('race-NaN.txt', '\t'); +weight=importdata('weights-NaN.txt','\t'); +grade=importdata('grade-NaN.txt','\t'); +[r,c]=size(sex); +xlabel_w=weight(:,1); +weight=weight(:,2:c); +race=race(:,2:c); +sex=sex(:,2:c); +grade=grade(:,2:c); +cd .. +cd results_103114 +cd cat +question_mat=importdata('Q80-cat-NaN.txt', '\t'); +[r,c]=size(question_mat); + +%Q59: texting, "YES">=3 +%Q06: been in a fight "YES">=2 +%Q04: felt unsafe at school "YES">=2 +%Q74:bullied at school "YES"==1 +%Q12: considered suicide "YES"==1 +%Q13: made a plan for suicide "YES"==1 +%Q16: attempted suicide "YES">=2 +%Q81: physical active 5 of past 7 days "YES">=6 +%Q35: watched TV 3 or more hours "YES">=5 + +others={'Q59', 'Q06', 'Q04', 'Q74', 'Q12', 'Q13', 'Q16', 'Q81', 'Q35'}; +other_mat=[3, 2, 2, 1, 1, 1, 2, 6, 5]; +other_do=[1, 1, 1, 0, 0, 0, 1, 1, 1]; +other_total=[1, 0, 0, 0, 0, 0, 0, 0, 0, 0]; %if denominator is different than ALL +conf_mat=cell(9,r); +conf_mat(:,1)=others; +total=zeros(9,7,7); +n_mat=zeros(9,7); +x5_mat=zeros(9,7); +x9_mat=zeros(9,7); +xlabel_all=[2001, 2003, 2005, 2007, 2009, 2011, 2013]; +%sleep key A(1)=4 hours or less, B(2)=5 hours, C(3)=6 hours D(4)=7 hours +%E(5)=8 hours, %F(6)=9 hours, %G(7)=10 hours or more +%split by <=6 hours and >=8 hours +xlabel1=question_mat(:,1); +question_mat=question_mat(:,2:c); +years=cell.empty; + +for i=1:numel(xlabel_all); + year=xlabel_all(i); + indx1=find(year==xlabel1); + indx_w=find(year==xlabel_w); + %find demographics for that year------------------------- + [rg,cg]=size(grade); + grade_=grade(i,2:cg); + [rs,cs]=size(sex); + sex_=sex(i,2:cs); + [rr,cr]=size(race); + race_=race(i,2:cr); + %look at each other question for that year----------------------- + for k=1:numel(others) + question_mat2=importdata([others{k} '-cat-NaN.txt'], '\t'); + [r,c2]=size(question_mat2); + xlabel2=question_mat2(:,1); + indx2=find(year==xlabel2); + question_mat2=question_mat2(:,2:c2); + + if numel(indx1)>0 && numel(indx2)>0 + years{i}=year; + for j=1:7 + q1=question_mat(indx1,:); + q2=question_mat2(indx2,:); + + [r1,c1]=size(question_mat); + [r2,c2]=size(question_mat2); + min_c=min(c1,c2); + q1_=q1(1,1:min_c); + q2_=q2(1,1:min_c); + w=weight(indx_w,1:min_c); + indx_final=1:min_c; %start with everything + %look at indices for race, sex and grade + if GRADE>0 + indx_g=find(grade_==GRADE); + indx_final=intersect(indx_g, indx_final); + end + if SEX >0 + indx_s=find(sex_==SEX); + indx_final=intersect(indx_s, indx_final); + end + if RACE > 0 + indx_r=find(race_==RACE); + indx_final=intersect(indx_r, indx_final); + end + + w_final=w(indx_final); + q1_final=q1_(indx_final); + q2_final=q2_(indx_final); + index_yes=find(q1_final==j); + if (other_do(k)==1) + index_yes2=find(q2_final>=other_mat(k)); + else + index_yes2=find(q2_final==other_mat(k)); + end + + index_missQ=find(q1_final== 0 | q2_final==0); %students who didn't answer the Q + index_nomiss=find(q1_final>0 & q2_final>other_total(k)); + index_overlap=intersect(index_yes,index_yes2); %index of all all who participated in both behaviors + index_overlap2=intersect(index_overlap,index_nomiss); + total_ans=nansum(w(index_nomiss)); + yes_overlap=nansum(w(index_overlap2)); + n=total_ans; + n_mat (k,i)=n; + if (j<=3) %6 hours or less + x5=yes_overlap; + x5_mat(k,i)=x5_mat(k,i)+x5; + end + + if (j>=5) %6 hours or less + x9=yes_overlap; + x9_mat(k,i)=x9_mat(k,i)+x9; + end + total(k,j,i)=yes_overlap/total_ans*100; %total + end + end + end +end + +c=1; + +c2=1; +%sleep key A(1)=4 hours or less, B(2)=5 hours, C(3)=6 hours D(4)=7 hours +%E(5)=8 hours, %F(6)=9 hours, %G(7)=10 hours or more + final_total=double.empty; +for i=1:7 + final_total(:,c)=total(:,c2,i)+total(:,c2+1,i) + total(:,c2+2,i) ; + final_total(:,c+1)=total(:,c2+4,i) + total(:,c2+5,i) + total(:,c2+6,i); + c=c+2; +end + + +z=1.96; +[r,c]=size(n_mat); +for i=1:r + count=2; + for j=1:c + x=x5_mat(i,j); + n=n_mat(i,j); + p=x/n; %x is the number of subjects saying "yes", n is the total subjects + upper=((p+z*sqrt(p*(1-p)/n))*100); + lower=((p-z*sqrt(p*(1-p)/n))*100); + upper=sprintf('%0.1f',round(upper*10)/10); + lower=sprintf('%0.1f',round(lower*10)/10); + conf_mat{i+1,count}=[lower ', ' upper]; + x=x9_mat(i,j); + n=n_mat(i,j); + p=x/n; %x is the number of subjects saying "yes", n is the total subjects + upper=((p+z*sqrt(p*(1-p)/n))*100); + lower=((p-z*sqrt(p*(1-p)/n))*100); + upper=sprintf('%0.1f',round(upper*10)/10); + lower=sprintf('%0.1f',round(lower*10)/10); + conf_mat{i+1,count+1}=[lower ', ' upper]; + count=count+2; + end +end + +final_mat=cell.empty; +for i=7:14 + for j=1:9 + temp=sprintf('%0.1f',round(final_total(j,i)*10)/10); + final_mat{j,i}=[temp ' (' conf_mat{j+1,i+1} ')']; + end +end \ No newline at end of file