meeting date: 2019-03-13
days until:
last run: 2019-03-25
link: http://rpubs.com/janderz8/469731
This week I have looked at the updated information from the baseline PACt-MD dataset. Previously, using the provisional diagnoses, I had analyzed 183 individuals. Using the updated baseline information, We now have access to 283 individuals. Five of those individuals have no current consensus diagnosis “sub-CMH0100009” “sub-CMH3060027” “sub-CMHH3060187” “sub-CMH3070023” “sub-CMH3070112”, and one individual does not appear in the Excel files “sub-CMH0350083”. I have included the five subjects without confirmed diagnoses by substituting in their preliminary diagnosis - I can exclude these individuals later if necessary.
I am currently in the process of updating the PLS and univariate analyses and will include descriptive statistics for the included sample here as well.
Finally, I have spoken to Jerry about pushing the NODDI metrics into surface space using CIFTIFY since the grey matter skeletons are fairly poor quality & smoothing on the surface has the advantage of increasing power & not smearing across sulci/gyri.
It may be useful to quantify overall level of free water using fslmeants since free water may not be distributed similarly by group.
0 = Normal 1 = MCI 2 = MDD-MCI 3 = MDD+MCI 4 = Dementia
NOTE: sub-CMH0350083 was missing from the most recent release of the data. I have preprocessed their MRI images, but don’t have a diagnosis. Follow up with Neda.
first look at the control subjects
Check DOB for PAC01_CMH_0950016_01, is likely supposed to be May 1925 Now the patients
Now to join the controls and the patients & then subset them by to include only those with MRI scans…
Imputing missing data using the MICE package:
drop the one person’s MoCA score of 0 (they had an MMSE of 26) - follow up with this person PAC01_CMH_0950019_01
describeBy(completedData, group="Diagnosis", skew=FALSE, range=FALSE,quant=NULL, IQR=FALSE)
##
## Descriptive statistics by group
## group: HC
## vars n mean sd se
## demo_id* 1 25 NaN NA NA
## MRI* 2 25 NaN NA NA
## Diagnosis* 3 25 1.00 0.00 0.00
## all_dx* 4 25 1.00 0.00 0.00
## cc_mci_a2_cog_d_lm* 5 25 1.12 0.33 0.07
## demo_gender 6 25 1.64 0.49 0.10
## sdemo_country_birth* 7 25 NaN NA NA
## sdemo_age_immigration 8 25 9.56 15.95 3.19
## sdemo_prime_language* 9 25 NaN NA NA
## sdemo_employment 10 25 1.72 1.67 0.33
## sdemo_marital_status 11 25 2.28 1.10 0.22
## sdemo_children 12 25 1.28 0.46 0.09
## sdemo_religion 13 25 2.56 1.39 0.28
## sdemo_sbjct_highest_ed 14 25 6.24 0.88 0.18
## sdemo_sbjct_highest_occ 15 25 7.52 1.29 0.26
## sdemo_father_ed 16 25 4.84 1.89 0.38
## sdemo_father_highest_occ 17 25 5.40 2.36 0.47
## sdemo_mother_ed 18 25 3.64 1.75 0.35
## sdemo_mother_highest_occ 19 25 4.20 2.61 0.52
## moca_total_score 20 25 27.80 1.35 0.27
## age 21 25 69.73 6.02 1.20
## --------------------------------------------------------
## group: NonAmnestic_MCI
## vars n mean sd se
## demo_id* 1 35 NaN NA NA
## MRI* 2 35 NaN NA NA
## Diagnosis* 3 35 2.00 0.00 0.00
## all_dx* 4 35 2.00 0.00 0.00
## cc_mci_a2_cog_d_lm* 5 35 1.00 0.00 0.00
## demo_gender 6 35 1.57 0.50 0.08
## sdemo_country_birth* 7 35 NaN NA NA
## sdemo_age_immigration 8 35 13.71 14.90 2.52
## sdemo_prime_language* 9 35 NaN NA NA
## sdemo_employment 10 35 1.71 1.86 0.31
## sdemo_marital_status 11 35 2.40 1.24 0.21
## sdemo_children 12 35 1.26 0.44 0.07
## sdemo_religion 13 35 3.14 1.91 0.32
## sdemo_sbjct_highest_ed 14 35 6.00 1.00 0.17
## sdemo_sbjct_highest_occ 15 35 7.09 1.36 0.23
## sdemo_father_ed 16 35 4.71 1.67 0.28
## sdemo_father_highest_occ 17 35 5.97 1.93 0.33
## sdemo_mother_ed 18 35 3.80 1.86 0.31
## sdemo_mother_highest_occ 19 35 4.37 2.73 0.46
## moca_total_score 20 35 24.66 2.10 0.35
## age 21 35 71.73 6.48 1.09
## --------------------------------------------------------
## group: MDD-MCI
## vars n mean sd se
## demo_id* 1 48 NaN NA NA
## MRI* 2 48 NaN NA NA
## Diagnosis* 3 48 3.00 0.00 0.00
## all_dx* 4 48 3.00 0.00 0.00
## cc_mci_a2_cog_d_lm* 5 48 1.27 0.45 0.06
## demo_gender 6 48 1.67 0.48 0.07
## sdemo_country_birth* 7 48 NaN NA NA
## sdemo_age_immigration 8 48 8.98 14.62 2.11
## sdemo_prime_language* 9 48 NaN NA NA
## sdemo_employment 10 48 1.42 1.18 0.17
## sdemo_marital_status 11 48 2.67 1.24 0.18
## sdemo_children 12 48 1.33 0.48 0.07
## sdemo_religion 13 48 3.52 1.54 0.22
## sdemo_sbjct_highest_ed 14 48 6.02 1.12 0.16
## sdemo_sbjct_highest_occ 15 48 7.10 1.29 0.19
## sdemo_father_ed 16 48 3.79 1.98 0.29
## sdemo_father_highest_occ 17 48 5.69 2.21 0.32
## sdemo_mother_ed 18 48 3.81 1.79 0.26
## sdemo_mother_highest_occ 19 48 4.19 2.48 0.36
## moca_total_score 20 48 27.54 1.95 0.28
## age 21 48 70.55 4.96 0.72
## --------------------------------------------------------
## group: NonAmnestic_MDD+MCI
## vars n mean sd se
## demo_id* 1 28 NaN NA NA
## MRI* 2 28 NaN NA NA
## Diagnosis* 3 28 4.00 0.00 0.00
## all_dx* 4 28 3.96 0.19 0.04
## cc_mci_a2_cog_d_lm* 5 28 1.00 0.00 0.00
## demo_gender 6 28 1.71 0.46 0.09
## sdemo_country_birth* 7 28 NaN NA NA
## sdemo_age_immigration 8 28 16.64 20.93 3.95
## sdemo_prime_language* 9 28 NaN NA NA
## sdemo_employment 10 28 1.50 1.04 0.20
## sdemo_marital_status 11 28 2.64 1.34 0.25
## sdemo_children 12 28 1.36 0.49 0.09
## sdemo_religion 13 28 3.36 1.54 0.29
## sdemo_sbjct_highest_ed 14 28 6.11 0.83 0.16
## sdemo_sbjct_highest_occ 15 28 7.29 1.30 0.25
## sdemo_father_ed 16 28 4.54 2.08 0.39
## sdemo_father_highest_occ 17 28 6.46 2.30 0.43
## sdemo_mother_ed 18 28 3.36 2.08 0.39
## sdemo_mother_highest_occ 19 28 4.25 2.41 0.46
## moca_total_score 20 28 25.57 2.71 0.51
## age 21 28 70.93 4.77 0.90
## --------------------------------------------------------
## group: Dementia
## vars n mean sd se
## demo_id* 1 2 NaN NA NA
## MRI* 2 2 NaN NA NA
## Diagnosis* 3 2 5.00 0.00 0.0
## all_dx* 4 2 5.00 0.00 0.0
## cc_mci_a2_cog_d_lm* 5 2 2.00 0.00 0.0
## demo_gender 6 2 2.00 0.00 0.0
## sdemo_country_birth* 7 2 NaN NA NA
## sdemo_age_immigration 8 2 0.00 0.00 0.0
## sdemo_prime_language* 9 2 NaN NA NA
## sdemo_employment 10 2 1.00 0.00 0.0
## sdemo_marital_status 11 2 4.00 0.00 0.0
## sdemo_children 12 2 1.00 0.00 0.0
## sdemo_religion 13 2 5.00 0.00 0.0
## sdemo_sbjct_highest_ed 14 2 5.00 1.41 1.0
## sdemo_sbjct_highest_occ 15 2 7.50 2.12 1.5
## sdemo_father_ed 16 2 1.00 0.00 0.0
## sdemo_father_highest_occ 17 2 7.00 0.00 0.0
## sdemo_mother_ed 18 2 2.00 1.41 1.0
## sdemo_mother_highest_occ 19 2 5.00 2.83 2.0
## moca_total_score 20 2 16.50 0.71 0.5
## age 21 2 78.25 10.90 7.7
## --------------------------------------------------------
## group: Amnestic_MCI
## vars n mean sd se
## demo_id* 1 94 NaN NA NA
## MRI* 2 94 NaN NA NA
## Diagnosis* 3 94 6.00 0.00 0.00
## all_dx* 4 94 2.02 0.21 0.02
## cc_mci_a2_cog_d_lm* 5 94 1.98 0.15 0.01
## demo_gender 6 94 1.54 0.50 0.05
## sdemo_country_birth* 7 94 NaN NA NA
## sdemo_age_immigration 8 94 10.96 13.65 1.41
## sdemo_prime_language* 9 93 NaN NA NA
## sdemo_employment 10 94 1.79 1.78 0.18
## sdemo_marital_status 11 94 2.78 1.36 0.14
## sdemo_children 12 94 1.20 0.40 0.04
## sdemo_religion 13 94 2.85 1.67 0.17
## sdemo_sbjct_highest_ed 14 94 5.59 1.35 0.14
## sdemo_sbjct_highest_occ 15 94 7.01 1.65 0.17
## sdemo_father_ed 16 94 3.16 2.19 0.23
## sdemo_father_highest_occ 17 94 5.80 2.27 0.23
## sdemo_mother_ed 18 94 2.85 1.94 0.20
## sdemo_mother_highest_occ 19 94 3.78 2.43 0.25
## moca_total_score 20 94 23.02 2.54 0.26
## age 21 94 72.96 7.61 0.78
## --------------------------------------------------------
## group: Amnestic_MDD+MCI
## vars n mean sd se
## demo_id* 1 50 NaN NA NA
## MRI* 2 50 NaN NA NA
## Diagnosis* 3 50 7.00 0.00 0.00
## all_dx* 4 50 4.00 0.00 0.00
## cc_mci_a2_cog_d_lm* 5 50 1.98 0.14 0.02
## demo_gender 6 50 1.52 0.50 0.07
## sdemo_country_birth* 7 50 NaN NA NA
## sdemo_age_immigration 8 50 14.08 15.37 2.17
## sdemo_prime_language* 9 50 NaN NA NA
## sdemo_employment 10 50 1.40 1.16 0.16
## sdemo_marital_status 11 50 2.52 1.05 0.15
## sdemo_children 12 50 1.24 0.43 0.06
## sdemo_religion 13 50 3.12 1.85 0.26
## sdemo_sbjct_highest_ed 14 50 5.66 1.12 0.16
## sdemo_sbjct_highest_occ 15 50 6.54 1.45 0.20
## sdemo_father_ed 16 50 3.30 2.05 0.29
## sdemo_father_highest_occ 17 50 4.92 2.58 0.36
## sdemo_mother_ed 18 50 3.46 1.82 0.26
## sdemo_mother_highest_occ 19 50 4.08 2.41 0.34
## moca_total_score 20 50 24.00 2.64 0.37
## age 21 50 71.51 4.60 0.65
To do this, I will need to calculate the residual of every variable of interest from age, standardize them, and then feed them into a factor model.
library(psych)
library(GPArotation)
data_for_factor <- subset(completedData, select=c("age","sdemo_sbjct_highest_ed","sdemo_sbjct_highest_occ", "sdemo_father_ed", "sdemo_mother_ed","sdemo_father_highest_occ","sdemo_mother_highest_occ")) %>% scale()
#after running this once, only education and occupation scores covaried). Gender, marital status, religion and age of immigration were dropped ,"sdemo_marital_status","sdemo_religion","sdemo_children","sdemo_age_immigration","demo_gender",
age_factor <- data_for_factor[,1]
data_for_factor <- data_for_factor[,-1]
#residualize age from the above...
age_resids <- lm(as.matrix(data_for_factor[,1:6]) ~ age_factor)$resid
heatmap(cor(age_resids))
parallel <- fa.parallel(age_resids, fm = 'ml', fa = 'fa')
## Parallel analysis suggests that the number of factors = 3 and the number of components = NA
two <- fa(age_resids,nfactors = 2,rotate = "varimax",fm="ml")
print(two)
## Factor Analysis using method = ml
## Call: fa(r = age_resids, nfactors = 2, rotate = "varimax", fm = "ml")
## Standardized loadings (pattern matrix) based upon correlation matrix
## ML2 ML1 h2 u2 com
## sdemo_sbjct_highest_ed 0.11 0.99 1.00 0.005 1.0
## sdemo_sbjct_highest_occ 0.13 0.53 0.30 0.700 1.1
## sdemo_father_ed 0.61 0.23 0.43 0.570 1.3
## sdemo_mother_ed 0.84 0.16 0.73 0.275 1.1
## sdemo_father_highest_occ 0.44 0.09 0.20 0.799 1.1
## sdemo_mother_highest_occ 0.63 0.03 0.40 0.602 1.0
##
## ML2 ML1
## SS loadings 1.70 1.35
## Proportion Var 0.28 0.23
## Cumulative Var 0.28 0.51
## Proportion Explained 0.56 0.44
## Cumulative Proportion 0.56 1.00
##
## Mean item complexity = 1.1
## Test of the hypothesis that 2 factors are sufficient.
##
## The degrees of freedom for the null model are 15 and the objective function was 1.58 with Chi Square of 439.99
## The degrees of freedom for the model are 4 and the objective function was 0.23
##
## The root mean square of the residuals (RMSR) is 0.07
## The df corrected root mean square of the residuals is 0.14
##
## The harmonic number of observations is 282 with the empirical chi square 47.15 with prob < 1.4e-09
## The total number of observations was 282 with Likelihood Chi Square = 64.06 with prob < 4.1e-13
##
## Tucker Lewis Index of factoring reliability = 0.467
## RMSEA index = 0.233 and the 90 % confidence intervals are 0.183 0.283
## BIC = 41.49
## Fit based upon off diagonal values = 0.95
## Measures of factor score adequacy
## ML2 ML1
## Correlation of (regression) scores with factors 0.89 1.00
## Multiple R square of scores with factors 0.80 0.99
## Minimum correlation of possible factor scores 0.60 0.98
fa.diagram(two)
#now to estimate factor scores per subject
FS <- as.data.frame(factor.scores(age_resids, two, Phi = NULL, method = "Thurstone")$scores)
FS$Cumulative <-FS$ML2 * .31 + FS$ML1*.22
completedData <- cbind(completedData, FS)
#plot "reserve factor by group"
pd <- position_dodge(0.1) # move them .05 to the left and right
completedData$Cumulative <- as.numeric(completedData$Cumulative)
ggplot(completedData, aes(x = factor(all_dx), fill = factor(all_dx), y = Cumulative)) +
geom_dotplot(binaxis = "y", stackdir = "center", position = "dodge",colour="black",size=.5)+facet_grid(.~cc_mci_a2_cog_d_lm)+
stat_summary(fun.y = mean, fun.ymin = mean, fun.ymax = mean,
geom = "crossbar", width = 0.5)
## Warning: Ignoring unknown parameters: size
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
reserve_info <- summarySE(data = subset(completedData, Diagnosis !="Dementia" & Diagnosis !="Amnestic_HC"),measurevar = "Cumulative",groupvars =c("all_dx","cc_mci_a2_cog_d_lm"),na.rm = TRUE)
#reserve_info$all_dx <- factor(reserve_info$all_dx, levels = c("HC", "MDD-MCI", "MCI", "MDD+MCI"))
ggplot(reserve_info,aes(x=all_dx, y=Cumulative, group=all_dx, fill =all_dx))+geom_bar(stat="identity", colour="black")+
geom_errorbar(aes(ymin=Cumulative-se, ymax=Cumulative+se), width=.1, position=pd, colour="black")+labs(title= "Level of Reserve by Group (error bars are +/- 1SE)")+geom_hline(yintercept = 0, colour="black", size = 1)+facet_grid(.~cc_mci_a2_cog_d_lm)
#adding in the one case who is missing from the baseline data so that I have the same number of rows in the dataframe.
missing_mri <- data.frame(MRI="sub-CMH0350083")
completedData <- merge(completedData, missing_mri, by ="MRI", all=TRUE)
completedData <- completedData[order(completedData$MRI),]
completedData$MRI_Name <- paste(paste(completedData$all_dx, completedData$cc_mci_a2_cog_d_lm,"${i}", completedData$MRI,sep="_"),".nii.gz", sep="")
completedData <- subset(completedData, MRI != "sub-CMHH3070015")
write.csv(completedData, "/projects/janderson/PACTMD/data/demographic/PACt-MD_T0_Baseline_Data/Demo_Data_with_Reserve_Score.csv")
cor.test(completedData$Cumulative, completedData$moca_total_score)
##
## Pearson's product-moment correlation
##
## data: completedData$Cumulative and completedData$moca_total_score
## t = 4.4954, df = 279, p-value = 1.019e-05
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.1473510 0.3657719
## sample estimates:
## cor
## 0.2598825
ggplot(completedData, aes(x=Cumulative, y=moca_total_score))+geom_point()+geom_smooth(method="rlm")#+facet_grid(all_dx~cc_mci_a2_cog_d_lm)
## Warning: Removed 1 rows containing non-finite values (stat_smooth).
## Warning: Removed 1 rows containing missing values (geom_point).
cog_reserve_mod <- rlm(moca_total_score ~ Cumulative, data = completedData)
f.robftest(cog_reserve_mod, var = "Cumulative")
##
## robust F-test (as if non-random weights)
##
## data: from rlm(formula = moca_total_score ~ Cumulative, data = completedData)
## F = 20.443, p-value = 9.091e-06
## alternative hypothesis: true Cumulative is not equal to 0
reserve_pred <- subset(completedData, select=c("demo_id","Diagnosis","sdemo_sbjct_highest_ed","sdemo_sbjct_highest_occ", "sdemo_father_ed", "sdemo_mother_ed","sdemo_father_highest_occ","sdemo_mother_highest_occ","Cumulative"))
reserve_out <- subset(completedData, select=c("demo_id","age","moca_total_score"))
reserve_pred_long <- melt(data=reserve_pred, id.vars=c("demo_id","Diagnosis"))
reserve_pred_long <- merge(reserve_pred_long, reserve_out, by.x ="demo_id")
ggplot(reserve_pred_long, aes(x=value, y=moca_total_score))+geom_point()+geom_smooth(method="rlm")+facet_grid(.~variable, scales="free")+labs(title= "prediction of MoCA by various reserve scores")
## Warning: Removed 7 rows containing non-finite values (stat_smooth).
## Warning: Removed 7 rows containing missing values (geom_point).
ggplot(reserve_pred_long, aes(x=value, y=age))+geom_point()+geom_smooth(method="rlm")+facet_grid(.~variable,scales = "free")+labs(title= "prediction of age by various reserve scores")
## Warning: Removed 7 rows containing non-finite values (stat_smooth).
## Warning: Removed 7 rows containing missing values (geom_point).
First let’s take a look at the relationship with age…
library(R.matlab)
library(readxl)
library(ggthemes)
# load in the data here...
# First white matter and age data
wm_CSF_Age_Mat <-("/projects/janderson/PACTMD/pipelines/NODDI_mdt/my_gbss/stats/subset_with_controls/analysis_age_HcDepMciMciDep_CSF_wmskel_HC_STRUCTresult.mat")
wm_ODI_Age_Mat <-("/projects/janderson/PACTMD/pipelines/NODDI_mdt/my_gbss/stats/subset_with_controls/analysis_age_HcDepMciMciDep_ODI_wmskel_HC_STRUCTresult.mat")
wm_NDI_Age_Mat <-("/projects/janderson/PACTMD/pipelines/NODDI_mdt/my_gbss/stats/subset_with_controls/analysis_age_HcDepMciMciDep_NDI_wmskel_HC_STRUCTresult.mat")
# Then grey matter and age data
gm_CSF_Age_Mat <-("/projects/janderson/PACTMD/pipelines/NODDI_mdt/my_gbss/stats/subset_with_controls/analysis_age_HcDepMciMciDep_CSF_gmskel_STRUCTresult.mat")
gm_ODI_Age_Mat <-("/projects/janderson/PACTMD/pipelines/NODDI_mdt/my_gbss/stats/subset_with_controls/analysis_age_HcDepMciMciDep_ODI_gmskel_STRUCTresult.mat")
gm_NDI_Age_Mat <-("/projects/janderson/PACTMD/pipelines/NODDI_mdt/my_gbss/stats/subset_with_controls/analysis_age_HcDepMciMciDep_NDI_gmskel_STRUCTresult.mat")
# Now white matter data
wm_CSF_Mat <-("/projects/janderson/PACTMD/pipelines/NODDI_mdt/my_gbss/stats/subset_with_controls/Analysis_Group_wmskel_BOTH_CSF_STRUCTresult.mat")
wm_ODI_Mat <-("/projects/janderson/PACTMD/pipelines/NODDI_mdt/my_gbss/stats/subset_with_controls/Analysis_Group_wmskel_BOTH_ODI_STRUCTresult.mat")
wm_NDI_Mat <-("/projects/janderson/PACTMD/pipelines/NODDI_mdt/my_gbss/stats/subset_with_controls/Analysis_Group_wmskel_BOTH_NDI_STRUCTresult.mat")
# Now grey matter data
gm_CSF_Mat <-("/projects/janderson/PACTMD/pipelines/NODDI_mdt/my_gbss/stats/subset_with_controls/Analysis_Group_gmskel_BOTH_CSF_STRUCTresult.mat")
gm_ODI_Mat <-("/projects/janderson/PACTMD/pipelines/NODDI_mdt/my_gbss/stats/subset_with_controls/Analysis_Group_gmskel_BOTH_ODI_STRUCTresult.mat")
gm_NDI_Mat <-("/projects/janderson/PACTMD/pipelines/NODDI_mdt/my_gbss/stats/subset_with_controls/Analysis_Group_gmskel_BOTH_NDI_STRUCTresult.mat")
descriptives <- read_excel("/projects/janderson/PACTMD/pipelines/NODDI_mdt/my_gbss/stats/subset_with_controls/descriptives.xls")
## readxl works best with a newer version of the tibble package.
## You currently have tibble v1.4.2.
## Falling back to column name repair from tibble <= v1.4.2.
## Message displays once per session.
#function to pull data from Mean Behavioural PLS outputs...
Beh_PLS_Result <- function(x, LV, label, Invert){
input <- readMat(x)
res <- input$result
boot_result <- res[[14]]
orig_cors <- as.data.frame(boot_result[[6]][,LV])
upper <- as.data.frame(boot_result[[7]][,LV])
lower <- as.data.frame(boot_result[[8]][,LV])
bar <- cbind(orig_cors, upper, lower)
colnames(bar) <- c("Correlation", "upper","lower")
bar$Correlation <- bar$Correlation * Invert
bar$upper <- bar$upper * Invert
bar$lower <- bar$lower * Invert
bar$upper_adj <- abs(bar$upper - bar$Correlation)
bar$lower_adj <- abs(bar$Correlation - bar$lower)
group <- c("HC", "Dep", "MCI", "MCI+Dep")
#Amnesia <- c("Non Amnestic","Non Amnestic","Non Amnestic","Amnestic","Amnestic")
Label <- c(label, label, label, label)
bar <- cbind(Label, group, bar)
bar$group <- factor(bar$group, levels = c("HC", "Dep", "MCI", "MCI+Dep"))
#bar$Amnesia <- factor(bar$Amnesia, levels = c("Non Amnestic", "Amnestic"))
age <- as.data.frame(res[[10]])
subs <- as.data.frame(res[[11]])
brain_score <- as.data.frame(res[[8]][,1])
return(bar)
}
#Now creating the wm_age datamats
wm_CSF_Age_Dat <- Beh_PLS_Result(wm_CSF_Age_Mat,1,"CSF",1)
wm_NDI_Age_Dat <- Beh_PLS_Result(wm_NDI_Age_Mat,1,"NDI",1)
wm_ODI_Age_Dat <- Beh_PLS_Result(wm_ODI_Age_Mat,1,"ODI",1)
#Now creating the gm_age datamats
gm_CSF_Age_Dat <- Beh_PLS_Result(gm_CSF_Age_Mat,3,"CSF",1)
gm_NDI_Age_Dat <- Beh_PLS_Result(gm_NDI_Age_Mat,3,"NDI",1)
gm_ODI_Age_Dat <- Beh_PLS_Result(gm_ODI_Age_Mat,3,"ODI",1)
wm_age <- rbind(wm_ODI_Age_Dat,wm_NDI_Age_Dat,wm_CSF_Age_Dat)
gm_age <- rbind(gm_ODI_Age_Dat,gm_NDI_Age_Dat,gm_CSF_Age_Dat)
bar_age_wm <- ggplot(wm_age, aes(x = group, y = Correlation, fill= group))+geom_bar(stat = "identity")+
geom_errorbar(aes(ymin=Correlation-lower_adj, ymax=Correlation + upper_adj), width=0,
position=position_dodge(.9), colour="black") + facet_wrap(~Label)+ geom_hline(yintercept = 0, colour="black")+theme_gdocs() + scale_fill_gdocs()
bar_age_gm <- ggplot(gm_age, aes(x = group, y = Correlation, fill= group))+geom_bar(stat = "identity")+
geom_errorbar(aes(ymin=Correlation-lower_adj, ymax=Correlation + upper_adj), width=0,
position=position_dodge(.9), colour="black") + facet_wrap(~Label)+ geom_hline(yintercept = 0, colour="black")+theme_gdocs() + scale_fill_gdocs()
#################################################
# Plot the Mean Centered (Group Comparisons)
#################################################
#function to pull data from Mean Centered PLS outputs...
MC_PLS_Result <- function(x, LV, label, Invert, groups){
input <- readMat(x)
res <- input$result
boot_result <- res[[11]]
orig_usc <- as.data.frame(boot_result[[7]][,LV])
upper <- as.data.frame(boot_result[[8]][,LV])
lower <- as.data.frame(boot_result[[9]][,LV])
bar <- cbind(orig_usc, upper, lower)
colnames(bar) <- c("BSR", "upper","lower")
bar$BSR <- bar$BSR * Invert
bar$upper <- bar$upper * Invert
bar$lower <- bar$lower * Invert
bar$upper_adj <- bar$upper - bar$BSR
bar$lower_adj <- bar$BSR - bar$lower
group <- seq(1:groups)
#Amnesia <- c("Non Amnestic","Non Amnestic","Non Amnestic","Amnestic","Amnestic")
Label <- c(label, label, label, label)
bar <- cbind(Label, group, bar)
bar$group <- factor(bar$group)
#bar$Amnesia <- factor(bar$Amnesia, levels = c("Non Amnestic", "Amnestic"))
return(bar)
}
#wm data
wm_CSF_Dat <- MC_PLS_Result(wm_CSF_Mat,1,"CSF",1, 4)
wm_NDI_Dat <- MC_PLS_Result(wm_NDI_Mat,1,"NDI",1, 4)
wm_ODI_Dat <- MC_PLS_Result(wm_ODI_Mat,1,"ODI",1, 4)
#gm data
gm_CSF_Dat <- MC_PLS_Result(gm_CSF_Mat,1,"CSF",1, 4)
gm_NDI_Dat <- MC_PLS_Result(gm_NDI_Mat,1,"NDI",1, 4)
gm_ODI_Dat <- MC_PLS_Result(gm_ODI_Mat,1,"ODI",1, 4)
#age <- as.data.frame(res[[10]])
#subs <- as.data.frame(res[[11]])
#brain_score <- as.data.frame(res[[8]][,1])
#toplot <- cbind(descriptives, brain_score)
#toplot$Group <- factor(toplot$Group, levels = c("HC", "Dep", "MCI", "MCI+Dep"))
#scatter_age_csf <- ggplot(toplot, aes(x=Age, y=`res[[8]][, 1]`, group=Group, fill=Group,colour=Group))+geom_point()+geom_smooth(method="rlm")+facet_grid(.~Group) + ylab("Brain Score /n Free Water")
age_csf_brain <-ggdraw() + draw_image("/projects/janderson/PACTMD/pipelines/NODDI_mdt/my_gbss/stats/Figures/Age_by_CSF.png")
#combining the brain figure with the PLS data
##################################################
# Now looking at the boostrapped correlations
##################################################
#plot_grid(age_csf_brain,bar_age_csf, scatter_age_csf, labels ="AUTO", nrow = 3, ncol =1)
## Parsed with column specification:
## cols(
## ODI = col_double(),
## NDI = col_double(),
## CSF = col_double(),
## label = col_character()
## )
## Joining, by = "label"
## Joining, by = "label"
Now look at surface correlations with age and with reserve…
## Parsed with column specification:
## cols(
## ODI = col_double(),
## NDI = col_double(),
## CSF = col_double(),
## label = col_character()
## )
## Joining, by = "label"
## Joining, by = "label"