-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats_corr.R
executable file
·89 lines (76 loc) · 2.6 KB
/
stats_corr.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
#!/usr/bin/Rscript
getwd()
setwd('~/git/covid_analysis/')
getwd()
############################################################
# TASK: Pairwise correaltion and P-values: T1
############################################################
# source data
source("read_data.R")
# clear unwanted variables
rm(my_data)
############################################################
#=============
# Output
#=============
# corr analysis
my_spearman_corr = paste0(outdir_stats, "corr_spearman_t1_v3.csv")
my_pvals = paste0(outdir_stats, "corr_pvalues_t1_v3.csv")
############################################################
# data assignment for stats
wf = wf_data
lf = lf_data
########################################################################
# Pairwise correaltions and analyses
########################################################################
head(wf$outcomes)
wf <- wf[order(wf$outcomes),]
# subset t1 data
wf_t1 = cbind(wf[c(1:3)], wf %>% dplyr:: select(grep("_t1", names(wf))))
colnames(wf_t1)
# assign nice column names
my_colnames = c("id"
, "studygroup"
, "outcomes"
#, "idcol"
, "Angiopoietin2"
, "PF"
, "PSelectin"
, "sESelectin"
, "sICAM1"
, "sRAGE"
, "sVCAM1")
if (length(my_colnames) == length(my_colnames)){
print("PASS: Reassigning column names...")
colnames(wf_t1) = my_colnames
} else{
cat(paste0("FAIL:Cannot assign column names, length mismatch"
, "\nExpected length: ", length(orig_colanmes)
, "\nGot:", length(my_colnames)))
quit()
}
print('formatted colnames are:'); print(colnames(wf_t1))
# inspect
class(wf_t1); str(wf_t1)
# Compute a matrix of correlation p-values
start_med = which(colnames(wf_t1) == "Angiopoietin2")
end_med = which(colnames(wf_t1) == "sVCAM1")
#---------------
# Data for corr analysis
#---------------
corr_M = wf_t1[start_med:end_med]
my_corr1 = cor(corr_M
, method = "spearman"
, use = "pairwise.complete.obs")
my_corr = psych::corr.test(corr_M
, method = "spearman"
, use = "pairwise.complete.obs")$r
my_pval = psych::corr.test(corr_M
, method = "spearman"
, adjust = "none"
, use = "pairwise.complete.obs")$p
#******************
# write output file: correlations and pvalues
#******************
write.csv(my_corr, my_spearman_corr, row.names = TRUE)
write.csv(my_pval, my_pvals, row.names = TRUE)