forked from greenelab/chronobiome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVariance_Correlation_Plot.R
1618 lines (1436 loc) · 71.8 KB
/
Variance_Correlation_Plot.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
################################################
# Amy Campbell 2016-2017
#
# Plots variability explained by variables in activity, communication,
# energy, and blood pressure/heart rate data
#
# Cluster subjects by lm-fit p-values and draw dendrograms
#
# Makes scatterplots of each combination of activity, communication,
# blood pressure/heart rate, and energy
################################################
#NOTE ABOUT 4MONTH DATA WITHOUT ENERGY EXPENDITURE:
# For these analyses we want to stick with the full dataset, which includes the
# energy expenditure data. I'll keep the code processing the 4-month data without
# energy expenditure for legacy/reference purposes, but I'm commenting it out.
###############
# Load Packages
###############
# Read date of snapshot to use
args = commandArgs(TRUE)
checkpoint_date = args[1]
# Use checkpoint created by install script
library("checkpoint")
checkpoint(snapshotDate=checkpoint_date, checkpointLocation='.')
library("ggplot2")
library("Hmisc")
library("reshape2")
library("stats")
library("readr")
library("chron")
library("grid")
library("gridExtra")
`%>%` <- magrittr::`%>%`
##################
# Define functions
##################
GetR2 <- function(var1, var2, return_pvalue=FALSE) {
# Generates a simple linear regression model of var1~var2, and returns
# R-squared for that model to represent proportion of V1 explained by V2
# :param: var1 - Variable to 'be explained' by var2
# :param: var2 - Variable to 'explain' var1
# :param: return_pvalue - boolean indicating whether or not function returns
# p-value for the fit of the estimated linear model
# to the data, instead of the R-squared value:
# FALSE (default) - return R-sqaured value.
# TRUE - return p-value from fit.
Var1name <- colnames(var1)[1]
Var2name <- colnames(var2)[1]
model <- lm(as.numeric(var1) ~ as.numeric(var2))
ret_value = summary(model)$r.squared
if(return_pvalue) {
#Calculate the p-value using F-statistic attributes from linear model
fstats <- summary(model)$fstatistic
ret_value <- NA
#If an f-test was performed successfully
if(!is.null(fstats)) {
pvalue <- pf(fstats[1],fstats[2],fstats[3],lower.tail=F)
attributes(pvalue) <- NULL
ret_value <- pvalue
}
}
return(c(Var1name, Var2name, ret_value))
}
PlotR2s <- function(chrono_df, title, Sequence,
triangle_heatmap=FALSE, add_labels=FALSE,
color_by_pvalue=FALSE, apply_bonferroni=FALSE,
showLegend=FALSE) {
# Generates geom_tile plot of the % variance explained (R2) for each variable
# by each other variable.
# :param: chrono_df - Dataframe to plot, including all variables(activity,
# communication, and in certain time frames,
# blood pressure) to be compared in this geom_tile plot
# note: each variable in the dataframe will be compared
# to each other variable in the dataframe (and itself);
# because these will be compared using R-squared values
# yielded from simple linear regression models, they
# must be numeric
# :param: title - title to display on plot
# :param: Sequence - string indicating which order of ints to use to plot
# variables on the variance explained output plot:
# sequence.actcom (just activity/communication variables)
# sequence.actcomBP (activity & communication
# with blood pressure/HR data)
# sequence.energy (for datasets including activity,
# communication, blood pressure,
# and energy data)
# :param: triangle_heatmap - boolean indicating whether to plot just the
# top of the heatmap, above the diagonal. The
# heatmap is mirrored across the diagonal, so
# plotting the full heatmap technically contains
# redundant information.
# :param: add_labels - boolean indicating whether to add text labels to each
# box in the heatmap that list the R-squared values.
# The listed values are rounded to two decimal places.
# :param: color_by_pvalue - boolean indicating whether to color the heatmap
# using p-values from the fit of the lm model,
# instead of the R-squared values. The colors are
# evenly scaled from 0 (dark) and 0.05 (light).
# All p-values above 0.05 are color white. Note,
# this parameter also causes the graph to display
# p-values instead of R-squared values when
# add_labels is set to TRUE.
# FALSE (default) - Color and label plot using
# R-squared values.
# TRUE - Color and label plot using p-values.
#
# :param: apply_bonferroni - boolean indicating whether or not to apply
# a Bonferroni correction to the p-value color
# scale. Note, this parameter has no effect if
# color_by_pvalue is set to FALSE.
# FALSE (default) - p-value colors are scaled
# from 0 to 0.05. All other
# p-values are colored white.
# TRUE - p-value colors are scaled from 0 to
# 0.05 / n, where n is the total number
# of non-reciprocal comparisons (e.g.
# "SMS.Count x Call.Count" and "Call.Count
# x SMS.Count" are reciprocal comparisons)
# performed.
# :param: showLegend - boolean indicating whether or not to display legend.
chrono_df["Subject"] <- NULL
chrono_df["TimeSubjectIndex"] <- NULL
r2Matrix <- c()
for (a in colnames(chrono_df)) {
for (b in colnames(chrono_df)) {
r2Matrix <-
rbind(r2Matrix,
GetR2(as.matrix(chrono_df[a]),
as.matrix(chrono_df[b]),
color_by_pvalue
))
}
}
plot.matrix <- data.frame(r2Matrix)
colnames(plot.matrix) <- c("factor.1", "factor.2", "variability.explained")
plot.matrix$variability.explained <-
as.numeric(as.character(plot.matrix$variability.explained))
# Order variables using their alphabetically-determined level indices such
# that activraphy, actigraphy circadian,
# communication, communication circadian, and biometric variables are
# grouped together in the output chart
# sequence.actcomBP <- c(8, 9, 10, 7, 21, 26, 25, 24, 5, 19, 18, 17, 1,
# 2, 3, 6, 20, 22, 13, 16, 15, 14, 23, 4, 11, 27, 12)
# sequence.actcom <- c(7, 8, 9 , 6, 18, 22, 21, 20, 4, 16, 15, 14, 1,
# 2, 3, 5, 17, 19, 10, 13, 12, 11)
# sequence.energy <- c(8, 9, 10, 7, 23, 28, 27, 26, 5, 21, 20, 18, 1, 2, 3,
# 6, 22, 19, 17, 24, 13, 16, 15, 14, 25, 4, 11, 29, 12)
# sequence.4monthenergy <- c(7, 8, 9, 6, 20, 24, 23, 22, 4, 18, 17, 15, 1, 2,
# 3, 5, 19, 16, 14, 21, 10, 13, 12, 11)
# if (Sequence == "ActCom"){
# f1 <- factor(plot.matrix$factor.1,
# levels(plot.matrix$factor.1)[sequence.actcom])
# f2 <- factor(plot.matrix$factor.2,
# levels(plot.matrix$factor.2)[sequence.actcom])
# } else if (Sequence == "BP") {
# f1 <- factor(plot.matrix$factor.1,
# levels(plot.matrix$factor.1)[sequence.actcomBP])
# f2 <- factor(plot.matrix$factor.2,
# levels(plot.matrix$factor.2)[sequence.actcomBP])
# } else if (Sequence == "energy") {
# f1 <- factor(plot.matrix$factor.1,
# levels(plot.matrix$factor.1)[sequence.energy])
# f2 <- factor(plot.matrix$factor.2,
# levels(plot.matrix$factor.2)[sequence.energy])
# } else {
# f1 <- factor(plot.matrix$factor.1,
# levels(plot.matrix$factor.1)[sequence.4monthenergy])
# f2 <- factor(plot.matrix$factor.2,
# levels(plot.matrix$factor.2)[sequence.4monthenergy])
# }
# Or alternatively, order the variables by explicitly using the names of each
# factor level, rather than the number corresponding to its alphabetical order.
# The factor levels are still hard-coded, but this makes it a little easier
# to incorporate new values.
sequence.actcomBP <- c("Communication.amplitude", "Communication.period",
"Communication.phase", "circadian.signal.com",
"log.signal.com", "sqrt.Interaction.Diversity",
"SMS.Length", "SMS.Count", "Call.Count",
"MobilityRadius.amplitude", "MobilityRadius.period",
"MobilityRadius.phase", "circadian.signal.mobR",
"Mobility.amplitude", "Mobility.period", "Mobility.phase",
"circadian.signal.mob", "Lux.amplitude", "Lux.period",
"Lux.phase", "circadian.signal.lux", "log.Mobility.Radius",
"log.Mobility", "log.Luminosity", "activity.amplitude",
"activity.period", "activity.phase", "circadian.signal.act",
"log.signal.act", "log.Steps", "log.activity.Vector.Magnitude",
"log.Axis3", "log.Axis2", "log.Axis1", "pulse.pressure",
"arterial.pressure", "diastolic.bp", "systolic.bp", "heart.rate",
"sqrt.Sodium", "sqrt.Fat", "sqrt.Protein", "sqrt.Carbohydrates",
"sqrt.KCalories.consumed")
sequence.actcom <- c("Communication.amplitude", "Communication.period",
"Communication.phase", "circadian.signal.com",
"log.signal.com", "sqrt.Interaction.Diversity",
"SMS.Length", "SMS.Count", "Call.Count",
"MobilityRadius.amplitude", "MobilityRadius.period",
"MobilityRadius.phase", "circadian.signal.mobR",
"Mobility.amplitude", "Mobility.period", "Mobility.phase",
"circadian.signal.mob", "Lux.amplitude", "Lux.period",
"Lux.phase", "circadian.signal.lux", "log.Mobility.Radius",
"log.Mobility", "log.Luminosity", "activity.amplitude",
"activity.period", "activity.phase", "circadian.signal.act",
"log.signal.act", "log.Steps", "log.activity.Vector.Magnitude",
"log.Axis3", "log.Axis2", "log.Axis1")
sequence.energy <- c("Communication.amplitude", "Communication.period",
"Communication.phase", "circadian.signal.com",
"log.signal.com", "sqrt.Interaction.Diversity",
"SMS.Length", "SMS.Count", "Call.Count",
"MobilityRadius.amplitude", "MobilityRadius.period",
"MobilityRadius.phase", "circadian.signal.mobR",
"Mobility.amplitude", "Mobility.period", "Mobility.phase",
"circadian.signal.mob", "Lux.amplitude", "Lux.period",
"Lux.phase", "circadian.signal.lux", "log.Mobility.Radius",
"log.Mobility", "log.Luminosity", "activity.amplitude", "activity.period",
"activity.phase", "circadian.signal.act", "log.signal.act",
"log.MET.rate", "log.kcals", "log.Steps",
"log.activity.Vector.Magnitude", "log.Axis3", "log.Axis2",
"log.Axis1", "pulse.pressure", "arterial.pressure",
"diastolic.bp", "systolic.bp", "heart.rate",
"sqrt.Sodium", "sqrt.Fat", "sqrt.Protein", "sqrt.Carbohydrates",
"sqrt.KCalories.consumed")
sequence.4monthenergy <- c("Communication.amplitude", "Communication.period",
"Communication.phase", "circadian.signal.com",
"log.signal.com", "sqrt.Interaction.Diversity",
"SMS.Length", "SMS.Count", "Call.Count",
"MobilityRadius.amplitude", "MobilityRadius.period",
"MobilityRadius.phase", "circadian.signal.mobR",
"Mobility.amplitude", "Mobility.period", "Mobility.phase",
"circadian.signal.mob", "Lux.amplitude", "Lux.period",
"Lux.phase", "circadian.signal.lux", "log.Mobility.Radius",
"log.Mobility", "log.Luminosity", "activity.amplitude", "activity.period",
"activity.phase", "circadian.signal.act", "log.signal.act",
"log.MET.rate", "log.kcals", "log.Steps",
"log.activity.Vector.Magnitude", "log.Axis3", "log.Axis2",
"log.Axis1")
if (Sequence == "ActCom"){
f1 <- factor(plot.matrix$factor.1, sequence.actcom)
f2 <- factor(plot.matrix$factor.2, sequence.actcom)
} else if (Sequence == "BP") {
f1 <- factor(plot.matrix$factor.1, sequence.actcomBP)
f2 <- factor(plot.matrix$factor.2, sequence.actcomBP)
} else if (Sequence == "energy") {
f1 <- factor(plot.matrix$factor.1, sequence.energy)
f2 <- factor(plot.matrix$factor.2, sequence.energy)
} else {
f1 <- factor(plot.matrix$factor.1, sequence.4monthenergy)
f2 <- factor(plot.matrix$factor.2, sequence.4monthenergy)
}
#Update factors with new ordering
plot.matrix$factor.1 = f1
plot.matrix$factor.2 = f2
if(triangle_heatmap) {
#Remove data from lower triangle
plot.matrix <- dcast(plot.matrix, formula = factor.1 ~ factor.2, value.var = "variability.explained")
#Exclude factor.1 labels when determining triangle plot
factor1 = plot.matrix$factor.1
plot.matrix$factor.1 <- NULL
plot.matrix[lower.tri(plot.matrix)] <- NA
plot.matrix$factor.1 = factor1
plot.matrix <- melt(plot.matrix, variable.name = "factor.2",
value.name = "variability.explained",
id.vars = c("factor.1"))
plot.matrix = na.omit(plot.matrix)
}
# generate geom_tile plot
plot <-
ggplot(data = plot.matrix,
aes(x = factor.1, y = factor.2, fill = variability.explained)) +
geom_tile(color = "black")
# Adjust color scale for displaying either R-squared values or p-values.
if(color_by_pvalue) { #Color by p-values
if(apply_bonferroni) { #Apply Bonferroni correction to upper-limit of color scale
#NOTE: This calculation works when the two factors we're comparing are
# identical. However, if there are elements in one factor not present
# in the other, this cutoff will be higher than the true Bonferroni-
# corrected value. There is room to improve this calculation to
# account for this possibility. However, since we're currently only
# using this code to plot matrices mirrored down the diagonal, this
# will suffice.
bf_cutoff = 0.05 / (length(f1) / 2)
plot <- plot + scale_fill_gradientn(name="p-value",
colors = c("darkred","white","white"),
values = c(0,bf_cutoff,1))
} else { #Scale colors between 0 and 0.05
plot <- plot + scale_fill_gradientn(name="p-value",
colors = c("darkred","white","white"),
values = c(0,0.05,1))
}
} else { #Color by R-squared
plot <- plot + scale_fill_gradientn(name="variability\nexplained",
colors = c("white", "steelblue4"),
values = c(0,1))
}
plot <-
plot +
theme(axis.text.x = element_text(angle = 90, size = 8,
hjust = 1, vjust = 0.5),
axis.text.y = element_text(size = 8),
panel.background = element_blank()) +
ggtitle(title) +
xlab("Factor 1") + ylab("Factor 2")
if(add_labels) {
plot <- plot + geom_text(aes(label=sprintf("%0.2f", round(variability.explained, digits = 2))),
size = 1.75)
}
if(!showLegend) {
plot <- plot + theme(legend.position = "none")
}
return(plot)
}
ParseSubject <- function(row, half) {
# Function to be applied to all rows of
# the dataframe in question
# :param: row - the entire row of the dataframe
# :param: half - indicates whether the "subject" information
# is in the first or second half of the string
timesubjectindex <- row["TimeSubjectIndex"]
strlist <- (strsplit(toString(timesubjectindex), "_"))
if (toString(half) == "2") {
return(unlist(strlist)[2])
} else {
return(as.numeric(unlist(strlist)[1]))
}
}
FormatPvalueTableForClustering <- function(pvalue_table) {
# Given a p-value table, remove self comparisons
# (where factor.1 == factor.2) and combine
# reciprocal comparisons (e.g. factor.1=log.Steps
# and factor.2=log.Axis1 vs. factor.1=log.Axis1
# and factor.2=log.Steps).
# :param: pvalue_table - dataframe with the following
# columns: factor.1, factor.2,
# and variability.explained)
formatted.pvalue_table <-
pvalue_table %>%
dplyr::rename(p_value = variability.explained) %>%
#Remove diagonal, since fit is perfect
dplyr::filter(as.character(factor.1) != as.character(factor.2)) %>%
#Combine factor.1 and factor.2, sorting each individual pair in alphabetical order.
#This makes it easy to remove reciprocal comparisons (e.g. log.Steps_log.Axis1 and
#log.Axis1_log.Steps).
dplyr::mutate(comparison.label = ifelse(as.character(factor.1) < as.character(factor.2),
paste0(as.character(factor.1), "_", as.character(factor.2)),
paste0(as.character(factor.2), "_", as.character(factor.1))),
comparison.order = ifelse(as.character(factor.1) < as.character(factor.2),
1,2)) %>%
dplyr::select(comparison.label, comparison.order, p_value) %>%
dplyr::arrange(comparison.label, comparison.order) %>%
#Due to floating-point errors, there can be slight differences between the p-values
#generated by the reciprocal comparisons. While these differences are negligible,
#they are enough to prevent filtering using the distinct() and unique() functions.
#To overcome this, the code below separates the p-values form each reciprocal
#comparison into two separate columns, and only retains the smaller of the two.
dcast(formula = comparison.label ~ comparison.order, value.var = "p_value") %>%
dplyr::mutate(p_value = pmin(`1`, `2`)) %>%
dplyr::select(comparison.label, p_value)
return(formatted.pvalue_table)
}
PlotDendro <- function(pvalue_table, title, subset=NULL) {
# Plots a dendrogram, given a formatted table of
# LM-fit p-values. This version of the function
# uses base R graphics.
# :param: pvalue_table - Dataframe with the following columns:
# Subject, comparison.label, p_value
# :param: title - title to display on plot
# :param: subset - string indicating if only a subset
# of the input data should be used for
# clustering:
# NULL (default) - use all input data
# circadian - just use comparisons between
# the circadian stats (period
# phase, amplitude,
# circadina.signal)
# no_circ - exclude all comparisons
# using circadian stats.
filtered.pvalue_table <- pvalue_table
#If user wants to subset the data
if(!is.null(subset)) {
if(subset == "circadian") {
#Retain circadian stats only
filtered.pvalue_table <-
filtered.pvalue_table %>%
dplyr::filter(grepl("(period|phase|amplitude|circadian).*_.*(period|phase|amplitude|circadian)", comparison.label))
} else if(subset == "no_circ") {
#Exclude circadian stats
filtered.pvalue_table <-
filtered.pvalue_table %>%
dplyr::filter(!grepl("(period|phase|amplitude|circadian)", comparison.label))
}
}
data_for_clustering <-
filtered.pvalue_table %>%
dcast(formula = Subject ~ comparison.label, value.var = "p_value") %>%
tibble::column_to_rownames(var="Subject") %>%
as.matrix()
plot(hclust(dist(data_for_clustering)),
main=title,
sub="",
xlab="",
ylab="Euclidean distance")
}
PlotDendro.w_ggdendro <- function(pvalue_table, title, subset=NULL) {
# Generates a dendrogram as a ggplot object, given a
# formatted table of LM-fit p-values. This function
# is appropriate if the user needs to pass the plot
# as an object, or wishes to leverage ggplot2 function
# and features to further modify the plot.
# :param: pvalue_table - Dataframe with the following columns:
# Subject, comparison.label, p_value
# :param: title - title to display on plot
# :param: subset - string indicating if only a subset
# of the input data should be used for
# clustering:
# NULL (default) - use all input data
# circadian - just use comparisons between
# the circadian stats (period
# phase, amplitude,
# circadina.signal)
# no_circ - exclude all comparisons
# using circadian stats.
filtered.pvalue_table <- pvalue_table
#If user wants to subset the data
if(!is.null(subset)) {
if(subset == "circadian") {
#Retain circadian stats only
filtered.pvalue_table <-
filtered.pvalue_table %>%
dplyr::filter(grepl("(period|phase|amplitude|circadian).*_.*(period|phase|amplitude|circadian)", comparison.label))
} else if(subset == "no_circ") {
#Exclude circadian stats
filtered.pvalue_table <-
filtered.pvalue_table %>%
dplyr::filter(!grepl("(period|phase|amplitude|circadian)", comparison.label))
}
}
data_for_clustering <-
filtered.pvalue_table %>%
dcast(formula = Subject ~ comparison.label, value.var = "p_value") %>%
tibble::column_to_rownames(var="Subject") %>%
as.matrix()
data_for_ggdendro <-
ggdendro::dendro_data(as.dendrogram(hclust(dist(data_for_clustering)),
type="rectangle"))
plot <-
ggplot(ggdendro::segment(data_for_ggdendro)) +
geom_segment(aes(x=x, y=y, xend=xend, yend=yend)) +
scale_x_continuous(breaks = seq_along(data_for_ggdendro$labels$label),
labels = data_for_ggdendro$labels$label) +
ylab("Euclidean distance") +
ggtitle(title) +
theme(plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5),
axis.title.x = element_blank(),
axis.text.y = element_text(angle = 90, hjust = 0.5, vjust = 1),
axis.title.y = element_text(angle = 90, hjust = 0.5),
panel.background = element_blank(),
axis.ticks = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank())
return(plot)
}
###############################
# Heatmap of variance explained
###############################
transformed.communication.activity <-
readr::read_csv("transformed.communication.activity.csv")
transformed.communication.activity["X1"] <- NULL
# Two 48 Hour visits containing measurements of blood pressure, heart rate
BP_HR <- readr::read_csv("heartrate.bp.csv")
BP_HR["X1"] <- NULL
diet <- readr::read_csv("diet.csv")
diet["X1"] <- NULL
act.com.bp.hr.vars4months <- dplyr::full_join(BP_HR, transformed.communication.activity,
by = "TimeSubjectIndex") %>%
dplyr::full_join(diet, by = "TimeSubjectIndex")
bp.HR.com.act <- na.omit(act.com.bp.hr.vars4months)
postscript("Variability.Act.Com.BP.eps")
PlotR2s(bp.HR.com.act[,5:dim(bp.HR.com.act)[2]],
paste0("Variance Explained in Activity,",
"Communication, Biometric Data (Visits 1 and 2)"), "BP",
triangle_heatmap = TRUE)
dev.off()
pdf("Variability.Act.Com.BP.pdf", height=8.5, width=10.5)
PlotR2s(bp.HR.com.act[,5:dim(bp.HR.com.act)[2]],
paste0("Variance Explained in Activity,",
"Communication, Biometric Data (Visits 1 and 2)"), "BP",
triangle_heatmap = TRUE)
dev.off()
#Define spans for visits 1 & 2 in terms of the standardized time units
TimeList_window1 <- c(seq(922, 1232))
TimeList_window2 <- c(seq(1328, 1545))
# 48 hour visit 1
Visit1_bp.HR.com.act <- subset(bp.HR.com.act, Times %in% TimeList_window1)
postscript("Variability.Act.Com.BP.Visit1.eps")
PlotR2s(Visit1_bp.HR.com.act[, 5:dim(Visit1_bp.HR.com.act)[2]],
"Variance Explained in Activity, Communication, Biometric Data(Visit 1)",
"BP", triangle_heatmap = TRUE)
dev.off()
pdf("Variability.Act.Com.BP.Visit1.pdf", height=8.5, width=10.5)
PlotR2s(Visit1_bp.HR.com.act[, 5:dim(Visit1_bp.HR.com.act)[2]],
"Variance Explained in Activity, Communication, Biometric Data(Visit 1)",
"BP", triangle_heatmap = TRUE)
dev.off()
# 48 hour visit 2
Visit2_bp.HR.com.act <- subset(bp.HR.com.act, Times %in% TimeList_window2)
postscript("Variability.Act.Com.BP.Visit2.eps")
PlotR2s(Visit2_bp.HR.com.act[, 5:dim(Visit2_bp.HR.com.act)[2]],
"Variance Explained in Activity, Communication, Biometric Data (Visit 2)", "BP",
triangle_heatmap = TRUE)
dev.off()
pdf("Variability.Act.Com.BP.Visit2.pdf", height=8.5, width=10.5)
PlotR2s(Visit2_bp.HR.com.act[, 5:dim(Visit2_bp.HR.com.act)[2]],
"Variance Explained in Activity, Communication, Biometric Data (Visit 2)", "BP",
triangle_heatmap = TRUE)
dev.off()
energy <- read.csv("energy.csv")
energy["X"] <- NULL
energy["Times"] <- apply(energy, 1, ParseSubject, 1)
Energy.4months <- dplyr::full_join(transformed.communication.activity, energy,
by = "TimeSubjectIndex")
Energy.4months <- na.omit(Energy.4months)
Full.with.energy <- dplyr::full_join(bp.HR.com.act, energy,
by = "TimeSubjectIndex")
Full.with.energy <- na.omit(Full.with.energy)
postscript("Variance_Explained_WithEnergy.eps")
# Plot R^2s excluding Times variable
PlotR2s(Full.with.energy[, 6:dim(Full.with.energy)[2] - 2],
paste0("Variance Explained in Activity, Communication, Blood Pressure,",
" and Energy Variables"),
"energy", triangle_heatmap = TRUE)
dev.off()
pdf("Variance_Explained_WithEnergy.pdf", height=8.5, width=10.5)
PlotR2s(Full.with.energy[, 6:dim(Full.with.energy)[2] - 2],
paste0("Variance Explained in Activity, Communication, Blood Pressure,",
" and Energy Variables"),
"energy", triangle_heatmap = TRUE)
dev.off()
# All four months by subject (no blood pressure/heart rate/ ActCom data)
transformed.communication.activity["Subject"] <-
apply(transformed.communication.activity, 1, ParseSubject, 2)
# # Subject HCR001
# HCR001.4months <- subset(transformed.communication.activity, Subject == "HCR001")
# postscript("HCR001_Variance.4months.eps", width = 480, height = 480)
# PlotR2s(HCR001.4months, "Variance Explained in HCR001 (all 4 months)",
# "ActCom", triangle_heatmap = TRUE)
# dev.off()
#
# # HCR003
# HCR003.4months <- subset(transformed.communication.activity, Subject == "HCR003")
# postscript("HCR003_Variance.4months.eps", width = 480, height = 480)
# PlotR2s(HCR003.4months, "Variance Explained in HCR003 (all 4 months)",
# "ActCom", triangle_heatmap = TRUE)
# dev.off()
#
# # HCR004
# HCR004.4months <- subset(transformed.communication.activity, Subject == "HCR004")
# postscript("HCR004_Variance.4months.eps", width = 480, height = 480)
# PlotR2s(HCR004.4months, "Variance Explained in HCR004 (all 4 months)",
# "ActCom", triangle_heatmap = TRUE)
# dev.off()
#
# # HCR006
# HCR006.4months <- subset(transformed.communication.activity, Subject == "HCR006")
# postscript("HCR006_Variance.4months.eps", width = 480, height = 480)
# PlotR2s(HCR006.4months, "Variance Explained in HCR006 (all 4 months)",
# "ActCom", triangle_heatmap = TRUE)
# dev.off()
#
# # HCR008
# HCR008.4months <- subset(transformed.communication.activity, Subject == "HCR008")
# postscript("HCR008_Variance.4months.eps", width = 480, height = 480)
# PlotR2s(HCR008.4months, "Variance Explained in HCR008 (all 4 months)",
# "ActCom", triangle_heatmap = TRUE)
# dev.off()
#
# # HCR009
# HCR009.4months <- subset(transformed.communication.activity, Subject == "HCR009")
# postscript("HCR009_Variance.4months.eps", width = 480, height = 480)
# PlotR2s(HCR009.4months, "Variance Explained in HCR009 (all 4 months)",
# "ActCom", triangle_heatmap = TRUE)
# dev.off()
#
#
# # All four months (no blood pressure/heart rate data)
# postscript("Variability.Activity.Communication.eps", width = 480, height = 480)
# PlotR2s(transformed.communication.activity,
# "Variance Explained in Activity and Communication Data", "ActCom",
# triangle_heatmap = TRUE)
# dev.off()
######################################
# All four months by subject (with energy)
Energy.4months["Subject"] <- (apply(Energy.4months, 1, ParseSubject, 2))
Energy.4months["X1"] <- NULL
Energy.4months["Times"] <- NULL
# Subject HCR001
HCR001.4months <- subset(Energy.4months, Subject == "HCR001")
postscript("HCR001_Variance.4months_withEnergy.eps",
width = 480, height = 480)
PlotR2s(HCR001.4months, "Variance Explained in HCR001 (all 4 months)",
"4monthenergy", triangle_heatmap = TRUE)
dev.off()
pdf("HCR001_Variance.4months_withEnergy.pdf", height=8.5, width=10.5)
PlotR2s(HCR001.4months, "Variance Explained in HCR001 (all 4 months)",
"4monthenergy", triangle_heatmap = TRUE)
dev.off()
# HCR003
HCR003.4months <- subset(Energy.4months, Subject == "HCR003")
postscript("HCR003_Variance.4months_withEnergy.eps",
width = 480, height = 480)
PlotR2s(HCR003.4months, "Variance Explained in HCR003 (all 4 months)",
"4monthenergy", triangle_heatmap = TRUE)
dev.off()
pdf("HCR003_Variance.4months_withEnergy.pdf", height=8.5, width=10.5)
PlotR2s(HCR003.4months, "Variance Explained in HCR003 (all 4 months)",
"4monthenergy", triangle_heatmap = TRUE)
dev.off()
#HCR003
HCR004.4months <- subset(Energy.4months, Subject == "HCR004")
postscript("HCR004_Variance.4months_withEnergy.eps",
width = 480, height = 480)
PlotR2s(HCR004.4months, "Variance Explained in HCR004 (all 4 months)",
"4monthenergy", triangle_heatmap = TRUE)
dev.off()
pdf("HCR004_Variance.4months_withEnergy.pdf", height=8.5, width=10.5)
PlotR2s(HCR004.4months, "Variance Explained in HCR004 (all 4 months)",
"4monthenergy", triangle_heatmap = TRUE)
dev.off()
# HCR006
HCR006.4months <- subset(Energy.4months, Subject == "HCR006")
postscript("HCR006_Variance.4months_withEnergy.eps", width = 480, height = 480)
PlotR2s(HCR006.4months, "Variance Explained in HCR006 (all 4 months)",
"4monthenergy", triangle_heatmap = TRUE)
dev.off()
pdf("HCR006_Variance.4months_withEnergy.pdf", height=8.5, width=10.5)
PlotR2s(HCR006.4months, "Variance Explained in HCR006 (all 4 months)",
"4monthenergy", triangle_heatmap = TRUE)
dev.off()
# HCR008
HCR008.4months <- subset(Energy.4months, Subject == "HCR008")
postscript("HCR008_Variance.4months_withEnergy.eps", width = 480, height = 480)
PlotR2s(HCR008.4months, "Variance Explained in HCR008 (all 4 months)",
"4monthenergy", triangle_heatmap = TRUE)
dev.off()
pdf("HCR008_Variance.4months_withEnergy.pdf", height=8.5, width=10.5)
PlotR2s(HCR008.4months, "Variance Explained in HCR008 (all 4 months)",
"4monthenergy", triangle_heatmap = TRUE)
dev.off()
# HCR009
HCR009.4months <- subset(Energy.4months, Subject == "HCR009")
postscript("HCR009_Variance.4months_withEnergy.eps", width = 480, height = 480)
PlotR2s(HCR009.4months, "Variance Explained in HCR009 (all 4 months)",
"4monthenergy", triangle_heatmap = TRUE)
dev.off()
pdf("HCR009_Variance.4months_withEnergy.pdf", height=8.5, width=10.5)
PlotR2s(HCR009.4months, "Variance Explained in HCR009 (all 4 months)",
"4monthenergy", triangle_heatmap = TRUE)
dev.off()
postscript("Variability.Activity.Communication_WithEnergy.eps",
width = 480, height = 480)
PlotR2s(Energy.4months,
"Variance Explained in Activity and Communication Data (4 months)",
"4monthenergy", triangle_heatmap = TRUE)
dev.off()
pdf("Variability.Activity.Communication_WithEnergy.pdf", height=8.5, width=10.5)
PlotR2s(Energy.4months,
"Variance Explained in Activity and Communication Data (4 months)",
"4monthenergy", triangle_heatmap = TRUE)
dev.off()
# Both Visits by Subject all variables
Full.with.energy["Subject"] <- (apply(Full.with.energy, 1, ParseSubject, 2))
# Subject HCR001
HCR001.set <- subset(Full.with.energy, Subject == "HCR001")
postscript("HCR001_Variance_BothVisits.eps", width = 480, height = 480)
PlotR2s(HCR001.set[, 6:dim(HCR001.set)[2] - 2], "Variance Explained in HCR001",
"energy", triangle_heatmap = TRUE)
dev.off()
pdf("HCR001_Variance_BothVisits.pdf", height=8.5, width=10.5)
PlotR2s(HCR001.set[, 6:dim(HCR001.set)[2] - 2], "Variance Explained in HCR001",
"energy", triangle_heatmap = TRUE)
dev.off()
# HCR003
HCR003.set <- subset(Full.with.energy, Subject == "HCR003")
postscript("HCR003_Variance_BothVisits.eps", width = 480, height = 480)
PlotR2s(HCR003.set[, 6:dim(HCR003.set)[2] - 2], "Variance Explained in HCR003",
"energy", triangle_heatmap = TRUE)
dev.off()
pdf("HCR003_Variance_BothVisits.pdf", height=8.5, width=10.5)
PlotR2s(HCR003.set[, 6:dim(HCR003.set)[2] - 2], "Variance Explained in HCR003",
"energy", triangle_heatmap = TRUE)
dev.off()
# HCR004
HCR004.set <- subset(Full.with.energy, Subject == "HCR004")
postscript("HCR004_Variance_BothVisits.eps", width = 480, height = 480)
PlotR2s(HCR004.set[, 6:dim(HCR004.set)[2] - 2], "Variance Explained in HCR004",
"energy", triangle_heatmap = TRUE)
dev.off()
pdf("HCR004_Variance_BothVisits.pdf", height=8.5, width=10.5)
PlotR2s(HCR004.set[, 6:dim(HCR004.set)[2] - 2], "Variance Explained in HCR004",
"energy", triangle_heatmap = TRUE)
dev.off()
# HCR006
HCR006.set <- subset(Full.with.energy, Subject == "HCR006")
HCR006.set["Subject"] <- NULL
postscript("HCR006_Variance_BothVisits.eps", width = 480, height = 480)
PlotR2s(HCR006.set[, 6:dim(HCR006.set)[2] - 2], "Variance Explained in HCR006",
"energy", triangle_heatmap = TRUE)
dev.off()
pdf("HCR006_Variance_BothVisits.pdf", height=8.5, width=10.5)
PlotR2s(HCR006.set[, 6:dim(HCR006.set)[2] - 2], "Variance Explained in HCR006",
"energy", triangle_heatmap = TRUE)
dev.off()
# HCR008
HCR008.set <- subset(Full.with.energy, Subject == "HCR008")
postscript("HCR008_Variance_BothVisits.eps", width = 480, height = 480)
PlotR2s(HCR008.set[, 6:dim(HCR008.set)[2] - 2], "Variance Explained in HCR008",
"energy", triangle_heatmap = TRUE)
dev.off()
pdf("HCR008_Variance_BothVisits.pdf", height=8.5, width=10.5)
PlotR2s(HCR008.set[, 6:dim(HCR008.set)[2] - 2], "Variance Explained in HCR008",
"energy", triangle_heatmap = TRUE)
dev.off()
# HCR009
HCR009.set <- subset(Full.with.energy, Subject == "HCR009")
postscript("HCR009_Variance_BothVisits.eps", width = 480, height = 480)
PlotR2s(HCR009.set[, 6:dim(HCR009.set)[2] - 2], "Variance Explained in HCR009",
"energy", triangle_heatmap = TRUE)
dev.off()
pdf("HCR009_Variance_BothVisits.pdf", height=8.5, width=10.5)
PlotR2s(HCR009.set[, 6:dim(HCR009.set)[2] - 2], "Variance Explained in HCR009",
"energy", triangle_heatmap = TRUE)
dev.off()
################################
# VISIT 1
# Subject HCR001
HCR001.set1 <- subset(subset(Full.with.energy, Subject == "HCR001"), Days <= 43)
postscript("HCR001_Variance_visit1.eps", width = 480, height = 480)
PlotR2s(HCR001.set1[, 6:dim(HCR001.set1)[2] - 2],
"Variance Explained in HCR001 (visit 1)", "energy",
triangle_heatmap = TRUE)
dev.off()
pdf("HCR001_Variance_visit1.pdf", height=8.5, width=10.5)
PlotR2s(HCR001.set1[, 6:dim(HCR001.set1)[2] - 2],
"Variance Explained in HCR001 (visit 1)", "energy",
triangle_heatmap = TRUE)
dev.off()
postscript("HCR001_Variance_visit1.with_labels.eps", width = 480, height = 480)
PlotR2s(HCR001.set1[, 6:dim(HCR001.set1)[2] - 2],
"Variance Explained in HCR001 (visit 1)", "energy",
triangle_heatmap = TRUE, add_labels = TRUE)
dev.off()
pdf("HCR001_Variance_visit1.with_labels.pdf", height=8.5, width=10.5)
PlotR2s(HCR001.set1[, 6:dim(HCR001.set1)[2] - 2],
"Variance Explained in HCR001 (visit 1)", "energy",
triangle_heatmap = TRUE, add_labels = TRUE)
dev.off()
# HCR003
HCR003.set1 <- subset(subset(Full.with.energy, Subject == "HCR003"), (Days <= 43))
postscript("HCR003_Variance_visit1.eps", width = 480, height = 480)
PlotR2s(HCR003.set1[, 6:dim(HCR003.set1)[2] - 2],
"Variance Explained in HCR003 (visit 1)", "energy",
triangle_heatmap = TRUE)
dev.off()
pdf("HCR003_Variance_visit1.pdf", height=8.5, width=10.5)
PlotR2s(HCR003.set1[, 6:dim(HCR003.set1)[2] - 2],
"Variance Explained in HCR003 (visit 1)", "energy",
triangle_heatmap = TRUE)
dev.off()
postscript("HCR003_Variance_visit1.with_labels.eps", width = 480, height = 480)
PlotR2s(HCR003.set1[, 6:dim(HCR003.set1)[2] - 2],
"Variance Explained in HCR003 (visit 1)", "energy",
triangle_heatmap = TRUE, add_labels = TRUE)
dev.off()
pdf("HCR003_Variance_visit1.with_labels.pdf", height=8.5, width=10.5)
PlotR2s(HCR003.set1[, 6:dim(HCR003.set1)[2] - 2],
"Variance Explained in HCR003 (visit 1)", "energy",
triangle_heatmap = TRUE, add_labels = TRUE)
dev.off()
# HCR004
HCR004.set1 <- subset(subset(Full.with.energy, Subject == "HCR004"), (Days<=45))
postscript("HCR004_Variance_visit1.eps", width = 480, height = 480)
PlotR2s(HCR004.set1[, 6:dim(HCR004.set1)[2] - 2],
"Variance Explained in HCR004 (visit 1)", "energy",
triangle_heatmap = TRUE)
dev.off()
pdf("HCR004_Variance_visit1.pdf", height=8.5, width=10.5)
PlotR2s(HCR004.set1[, 6:dim(HCR004.set1)[2] - 2],
"Variance Explained in HCR004 (visit 1)", "energy",
triangle_heatmap = TRUE)
dev.off()
postscript("HCR004_Variance_visit1.with_labels.eps", width = 480, height = 480)
PlotR2s(HCR004.set1[, 6:dim(HCR004.set1)[2] - 2],
"Variance Explained in HCR004 (visit 1)", "energy",
triangle_heatmap = TRUE, add_labels = TRUE)
dev.off()
pdf("HCR004_Variance_visit1.with_labels.pdf", height=8.5, width=10.5)
PlotR2s(HCR004.set1[, 6:dim(HCR004.set1)[2] - 2],
"Variance Explained in HCR004 (visit 1)", "energy",
triangle_heatmap = TRUE, add_labels = TRUE)
dev.off()
# HCR006
HCR006.set1 <- subset(subset(Full.with.energy, Subject == "HCR006"), (Days<=44))
postscript("HCR006_Variance_visit1.eps", width = 480, height = 480)
PlotR2s(HCR006.set1[, 6:dim(HCR006.set1)[2] - 2],
"Variance Explained in HCR006 (visit 1)", "energy",
triangle_heatmap = TRUE)
dev.off()
pdf("HCR006_Variance_visit1.pdf", height=8.5, width=10.5)
PlotR2s(HCR006.set1[, 6:dim(HCR006.set1)[2] - 2],
"Variance Explained in HCR006 (visit 1)", "energy",
triangle_heatmap = TRUE)
dev.off()
postscript("HCR006_Variance_visit1.with_labels.eps", width = 480, height = 480)
PlotR2s(HCR006.set1[, 6:dim(HCR006.set1)[2] - 2],
"Variance Explained in HCR006 (visit 1)", "energy",
triangle_heatmap = TRUE, add_labels = TRUE)
dev.off()
pdf("HCR006_Variance_visit1.with_labels.pdf", height=8.5, width=10.5)
PlotR2s(HCR006.set1[, 6:dim(HCR006.set1)[2] - 2],
"Variance Explained in HCR006 (visit 1)", "energy",
triangle_heatmap = TRUE, add_labels = TRUE)
dev.off()
# HCR008
HCR008.set1 <- subset(subset(Full.with.energy, Subject == "HCR008"), Days<=45)
postscript("HCR008_Variance_visit1.eps", width = 480, height = 480)
PlotR2s(HCR008.set1[, 6:dim(HCR008.set1)[2] - 2],
"Variance Explained in HCR008 (visit 1)", "energy",
triangle_heatmap = TRUE)
dev.off()
pdf("HCR008_Variance_visit1.pdf", height=8.5, width=10.5)
PlotR2s(HCR008.set1[, 6:dim(HCR008.set1)[2] - 2],
"Variance Explained in HCR008 (visit 1)", "energy",
triangle_heatmap = TRUE)
dev.off()
postscript("HCR008_Variance_visit1.with_labels.eps", width = 480, height = 480)
PlotR2s(HCR008.set1[, 6:dim(HCR008.set1)[2] - 2],
"Variance Explained in HCR008 (visit 1)", "energy",
triangle_heatmap = TRUE, add_labels = TRUE)
dev.off()
pdf("HCR008_Variance_visit1.with_labels.pdf", height=8.5, width=10.5)
PlotR2s(HCR008.set1[, 6:dim(HCR008.set1)[2] - 2],
"Variance Explained in HCR008 (visit 1)", "energy",
triangle_heatmap = TRUE, add_labels = TRUE)
dev.off()
# HCR009
HCR009.set1 <- subset(subset(Full.with.energy, Subject == "HCR009"), Days <= 51)
postscript("HCR009_Variance_visit1.eps", width = 480, height = 480)
PlotR2s(HCR009.set1[, 6:dim(HCR009.set1)[2] - 2],
"Variance Explained in HCR009 (visit 1)", "energy",
triangle_heatmap = TRUE)
dev.off()
pdf("HCR009_Variance_visit1.pdf", height=8.5, width=10.5)
PlotR2s(HCR009.set1[, 6:dim(HCR009.set1)[2] - 2],
"Variance Explained in HCR009 (visit 1)", "energy",
triangle_heatmap = TRUE)
dev.off()
postscript("HCR009_Variance_visit1.with_labels.eps", width = 480, height = 480)
PlotR2s(HCR009.set1[, 6:dim(HCR009.set1)[2] - 2],
"Variance Explained in HCR009 (visit 1)", "energy",
triangle_heatmap = TRUE, add_labels = TRUE)
dev.off()
pdf("HCR009_Variance_visit1.with_labels.pdf", height=8.5, width=10.5)
PlotR2s(HCR009.set1[, 6:dim(HCR009.set1)[2] - 2],
"Variance Explained in HCR009 (visit 1)", "energy",
triangle_heatmap = TRUE, add_labels = TRUE)
dev.off()
# VISIT 2
# Subject HCR001
HCR001.set2 <- subset(subset(Full.with.energy, Subject == "HCR001"), Days>=55)
postscript("HCR001_Variance_visit2.eps", width = 480, height = 480)
PlotR2s(HCR001.set2[, 6:dim(HCR001.set2)[2] - 2],
"Variance Explained in HCR001 (visit 2)", "energy",
triangle_heatmap = TRUE)
dev.off()
pdf("HCR001_Variance_visit2.pdf", height=8.5, width=10.5)
PlotR2s(HCR001.set2[, 6:dim(HCR001.set2)[2] - 2],
"Variance Explained in HCR001 (visit 2)", "energy",
triangle_heatmap = TRUE)
dev.off()
postscript("HCR001_Variance_visit2.with_labels.eps", width = 480, height = 480)
PlotR2s(HCR001.set2[, 6:dim(HCR001.set2)[2] - 2],
"Variance Explained in HCR001 (visit 2)", "energy",
triangle_heatmap = TRUE, add_labels = TRUE)
dev.off()
pdf("HCR001_Variance_visit2.with_labels.pdf", height=8.5, width=10.5)
PlotR2s(HCR001.set2[, 6:dim(HCR001.set2)[2] - 2],
"Variance Explained in HCR001 (visit 2)", "energy",
triangle_heatmap = TRUE, add_labels = TRUE)
dev.off()
# HCR003
HCR003.set2 <- subset(subset(Full.with.energy, Subject == "HCR003"), Days >= 55)
postscript("HCR003_Variance_visit2.eps", width = 480, height = 480)
PlotR2s(HCR003.set2[, 6:dim(HCR003.set2)[2] - 2],
"Variance Explained in HCR003 (visit 2)", "energy",
triangle_heatmap = TRUE)