/
connectivity_analysis.Rmd
139 lines (107 loc) · 4.11 KB
/
connectivity_analysis.Rmd
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
---
title: "connectivity_analysis"
output: html_notebook
author: ruonan jia
time: 6.18.2019
---
---
load packages
```{r}
library(ggplot2)
library(ez)
library(psych)
library(lme4)
```
---
functions
```{r}
data_summary <- function(data, varname, groupnames){
# Function to calculate the mean and the standard error
# for each group
#+++++++++++++++++++++++++
# data : a data frame
# varname : the name of a column containing the variable
#to be summariezed
# groupnames : vector of column names to be used as
# grouping variables
require(plyr)
summary_func <- function(x, col){
c(mean = mean(x[[col]], na.rm=TRUE),
sd = sd(x[[col]], na.rm=TRUE)/sqrt(length(x[[col]])))
}
data_sum<-ddply(data, groupnames, .fun=summary_func,
varname)
data_sum <- rename(data_sum, c("mean" = varname))
return(data_sum)
}
```
---
load data
```{r}
behav_path <- "D:/Ruonan/Projects in the lab/VA_RA_PTB/Clinical and behavioral"
image_path <- "D:/Ruonan/Projects in the lab/VA_RA_PTB/Imaging analysis/Imaging_anallysis_082018"
setwd(behav_path)
# load('data_all_noFemale_05122019.rda')
# load('data_all_noPCA_04092019.rda')
load("data_all_noFemale_day1day2_05122019.rda")
# load("data_all_day1day2_04082019.rda")
pcl <- read.csv('pcl.csv',header = TRUE)
demo <- read.csv('ed_income.csv', header = TRUE)
demo$education <- factor(demo$education, order = TRUE, levels = c(1,2,3,4,5,6))
demo$income <- factor(demo$income, order = TRUE, levels = c(1,2,3,4,5,6,7,8,9,10))
setwd(image_path)
conn <- read.csv('connectivity_capsvmPFC_GilaieDotanrPPC.csv', header = TRUE)
```
---
merge data
```{r}
tball_pcl <- merge(tball, pcl, by = 'id')
tb_all <- merge(tball_pcl, demo, by = 'id')
tb = tb_all[tb_all$isExcluded_imaging==0 & tball$isMale==1,]
conn_tb <- merge(conn, tb, by = 'id')
```
---
plot correlation
```{r}
#x2plot = 'pcl5_total'
x2plot = 'total_pm'
y2plot <- 'conn'
conn_plot <- conn_tb[conn_tb$isDay1 == 1 & conn_tb$isGain == 1 & !conn_tb$group == 'R' & conn_tb$isMal==1 & conn_tb$isExcluded_imaging == 0, ]
ggplot(conn_plot, aes(x=eval(parse(text = x2plot)), y=eval(parse(text = y2plot)))) +
geom_point(size=5) +
geom_smooth(method=lm, se=TRUE, linetype="dashed", color = "black") +
scale_x_continuous(breaks = c(0, 20, 40, 60, 80, 100, 120), limits = c(0,120)) +
#scale_y_continuous(limits = c(-0.6,0.4)) +
theme_classic() +
theme(text = element_text(size=20),
axis.line = element_line(size = 1.5)) +
xlab(x2plot) + ylab(y2plot)
test <- corr.test(x=conn_plot$total_pm,
y=conn_plot$conn,
use = "pairwise",
method = "spearman",
adjust = "none",
alpha=.05
)
test
```
---
plot group difference
```{r}
conn_plot <- data.frame(conn_tb$id, conn_tb$isGain, conn_tb$isExcluded_imaging, conn_tb$isMale, conn_tb$group, conn_tb$conn)
names(conn_plot) <- c('id', 'isGain', 'isExcluded_imaging', 'isMale', 'group', 'conn')
y2plot = "conn"
x2plot = "total_pm"
tb2plot <- data_summary(conn_plot[conn_plot$isGain == 0 & conn_plot$isExcluded_imaging == 0 & conn_plot$isMale == 1 & !conn_plot$group == 'R',],varname= y2plot,groupnames=c("group"))
# group
ggplot(data=tb2plot,aes(x=group, y=eval(parse(text = y2plot)), fill=group)) +
geom_bar(stat="identity", position=position_dodge()) +
geom_errorbar(aes(ymin=eval(parse(text = y2plot))-sd, ymax=eval(parse(text = y2plot))+sd), width=0.2, position=position_dodge(0.9)) +
scale_fill_manual(values = c('#228B22', '#FF8C00'), labels = c('Control', 'PTSD')) +
theme_classic() +
scale_x_discrete(name = 'Group', limits=c("C", "P"), labels=c("Control","PTSD")) +
labs(title=paste('SV',y2plot), y = "Connectivity")
```
Add a new chunk by clicking the *Insert Chunk* button on the toolbar or by pressing *Ctrl+Alt+I*.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the *Preview* button or press *Ctrl+Shift+K* to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike *Knit*, *Preview* does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.