User Tools

Site Tools


neuroimagen:adni_dr_av45

Correlation between Amyloid burden and Delay Recall on Memory (from ADNI data)

Con Florbetapir

library("ADNIMERGE")
library(psych)
dxmci=dxsum[dxsum[, "DXMDUE"] == "MCI due to Alzheimer's Disease" & !is.na(dxsum$DXMDUE) & dxsum[, "DXMDES"] == "MCI - Memory features (amnestic)" & !is.na(dxsum$DXMDES),]
mcimerged0 <- merge(dxmci, adnimerge, by=c("RID", "VISCODE"))
mcimerged1 <- merge(mcimerged0, neurobat, by=c("RID", "VISCODE"))
mcimerged2 <- merge(mcimerged1, adas, by=c("RID", "VISCODE"))
mciwav <- mcimerged2[!is.na(mcimerged2$AV45) &  mcimerged2[, "VISCODE"] == "bl" ,]
#mcif1 <- mciwav[mciwav[, "AVDEL30MIN"] < 4 & !is.na(mciwav$AVDEL30MIN),]
#mcif1a <- mcif1[mcif1[, "Q4SCORE"] > 6 & !is.na(mcif1$Q4SCORE),]
#mcif2 <- mcif1a[mcif1a[, "AVDELTOT"] < 11 & !is.na(mcif1a$AVDELTOT),]
#mcif2 <- mciwav[!is.na(mciwav$Q8SCORE) & !is.na(mciwav$Q4SCORE) & !is.na(mciwav$AVDELTOT) &!is.na(mciwav$AVDEL30MIN) & !is.na(mciwav$Q4SCORE)& mciwav[, "VISCODE"] == "bl" & mciwav[, "AGE"] > 65 & mciwav[, "AVDEL30MIN"] < 4 & mciwav[, "AVDELTOT"] < 11 & mciwav[, "Q4SCORE"] > 6 & mciwav[, "Q8SCORE"] > 6,]
mcif2 <- mciwav[!is.na(mciwav$Q4SCORE) &!is.na(mciwav$AVDEL30MIN) & mciwav[, "VISCODE"] == "bl",]
mcif2$zAVD = (mcif2$AVDEL30MIN - mean(mcif2$AVDEL30MIN))/sd(mcif2$AVDEL30MIN)
mcif2$zDR = (mean(mcif2$Q4SCORE) - mcif2$Q4SCORE)/sd(mcif2$Q4SCORE)
gfam <- data.frame(mcif2$zAVD, mcif2$zDR)
famod <- fa(gfam, scores="regression")
mcif2$cs <- famod$scores
mcif2$cAGE = mcif2$AGE + mcif2$Years
a <- lm(mcif2$cs ~ mcif2$AV45.bl + mcif2$PTGENDER + mcif2$PTEDUCAT + mcif2$AGE)
summary(a)
y.data <- data.frame(mcif2["cs"], mcif2["AV45.bl"], mcif2["PTGENDER"], mcif2["PTEDUCAT"], mcif2["AGE"])
y.data$Gender <- as.integer(factor(y.data$PTGENDER, levels=c("Male","Female"), labels=c(0,1)))
pcv <- pcor.test(y.data["AV45.bl"], y.data["cs"], y.data[, c("Gender", "PTEDUCAT", "AGE")])
pcv

Con PiB

library("ADNIMERGE")
library(psych)
dxmci=dxsum[dxsum[, "DXMDUE"] == "MCI due to Alzheimer's Disease" & !is.na(dxsum$DXMDUE) & dxsum[, "DXMDES"] == "MCI - Memory features (amnestic)" & !is.na(dxsum$DXMDES),]
mcimerged0 <- merge(dxmci, adnimerge, by=c("RID", "VISCODE"))
mcimerged1 <- merge(mcimerged0, neurobat, by=c("RID", "VISCODE"))
mcimerged2 <- merge(mcimerged1, adas, by=c("RID", "VISCODE"))
mciwav <- mcimerged2[!is.na(mcimerged2$PIB.bl) & mcimerged2[, "VISCODE"] == "bl",]
mcif2 <- mciwav[!is.na(mciwav$Q4SCORE) &!is.na(mciwav$AVDEL30MIN),]
mcif2$zAVD = (mcif2$AVDEL30MIN - mean(mcif2$AVDEL30MIN))/sd(mcif2$AVDEL30MIN)
mcif2$zDR = (mean(mcif2$Q4SCORE) - mcif2$Q4SCORE)/sd(mcif2$Q4SCORE)
gfam <- data.frame(mcif2$zAVD, mcif2$zDR)
famod <- fa(gfam, scores="regression")
mcif2$cs <- famod$scores
a <- lm(mcif2$cs ~ mcif2$PIB.bl + mcif2$PTGENDER + mcif2$PTEDUCAT + mcif2$AGE)
summary(a)
y.data <- data.frame(mcif2["cs"], mcif2["PIB.bl"], mcif2["PTGENDER"], mcif2["PTEDUCAT"], mcif2["AGE"])
y.data$Gender <- as.integer(factor(y.data$PTGENDER, levels=c("Male","Female"), labels=c(0,1)))
pcv <- pcor.test(y.data["PIB.bl"], y.data["cs"], y.data[, c("Gender", "PTEDUCAT", "AGE")])
pcv

Doing it right

PiB

library("ADNIMERGE")
library(psych)
library(ppcor)
zscore <- function(x, inv=FALSE){ 
	if (!inv) {
		result <- (x - mean(x))/sd(x)
	} else {
		result <- (mean(x) - x)/sd(x)}; 
	return(result) 
}
dxmci=dxsum[dxsum[, "DXMDUE"] == "MCI due to Alzheimer's Disease" & !is.na(dxsum$DXMDUE) & dxsum[, "DXMDES"] == "MCI - Memory features (amnestic)" & !is.na(dxsum$DXMDES),]
mcimerged0 <- merge(dxmci, adnimerge, by=c("RID", "VISCODE"))
mcimerged1 <- merge(mcimerged0, neurobat, by=c("RID", "VISCODE"))
mcimerged2 <- merge(mcimerged1, adas, by=c("RID", "VISCODE"))
mciwav <- mcimerged2[!is.na(mcimerged2$PIB),]
mcif1 <- mciwav[!is.na(mciwav$Q4SCORE) &!is.na(mciwav$AVDEL30MIN),]
mcif1[!duplicated(mcif1$RID),] -> mcif2
mcif2$zAVD = zscore(mcif2$AVDEL30MIN)
mcif2$zDR = zscore(mcif2$Q4SCORE, TRUE)
gfam <- data.frame(mcif2$zAVD, mcif2$zDR)
famod <- fa(gfam, scores="regression")
mcif2$cs <- zscore(famod$scores)
mcif2$cAGE = mcif2$AGE + mcif2$Years
y.data <- data.frame(mcif2["RID"], mcif2["cs"], mcif2["PIB"], mcif2["PTGENDER"], mcif2["PTEDUCAT"], mcif2["cAGE"], mcif2["VISCODE"])
y.data$Gender <- as.integer(factor(y.data$PTGENDER, levels=c("Male","Female"), labels=c(0,1)))
y.data$visit <- as.integer(factor(y.data$VISCODE, levels=c("bl","m12","m24","m36","m48"), labels=c(0,1,2,3,4)))
pcv <- pcor.test(y.data["PIB"], y.data["cs"], y.data[, c("Gender", "PTEDUCAT", "cAGE")])
pcv

for(i in 1:length(mcif2$RID)){
   tmp <- adnimerge[adnimerge$RID==mcif2$RID[i],]
   if(i == 1){
       mcihist <- tmp
   } else {
       mcihist <- rbind(mcihist, tmp)
   }
}
mcihist[mcihist$DX == "MCI to Dementia" & !is.na(mcihist$DX),] -> mciconv
data.frame(mciconv$RID, mciconv$VISCODE, mciconv$DX)[!duplicated(mciconv$RID),] -> mciconv2
colnames(mciconv2) <- c("RID", "CVISCODE", "DX")

# tratare de sacar la ultima visita de cada uno
require(data.table)
data.frame(mcihist$RID, mcihist$VISCODE, mcihist$DX) -> mciallvis
colnames(mciallvis) <- c("RID", "VISCODE", "DX")
visits <- read.csv("viscode.csv", header = FALSE)
mciallvis$visit <- as.integer(factor(mciallvis$VISCODE, levels=visits$V2, labels=visits$V1))
as.data.table(mciallvis) -> mciallvis
mciallvis[mciallvis[, .I[which.max(visit)], by=RID]$V1] -> lastvis

y.data$visit <- as.integer(factor(y.data$VISCODE, levels=visits$V2, labels=visits$V1))
mciconv2$cvisit <- as.integer(factor(mciconv2$CVISCODE, levels=visits$V2, labels=visits$V1))

y.data$cvisit <- NA
y.data$lvisit <- NA

for(i in 1:length(mciconv2$RID)){
   y.data$cvisit[y.data$RID==mciconv2$RID[i]] <- mciconv2$cvisit[i]
}
for(i in 1:length(lastvis$RID)){
   y.data$lvisit[y.data$RID==lastvis$RID[i]] <- lastvis$visit[i]
}

y.data$Conversion <- ifelse(!is.na(y.data$cvisit), 1, 0)
y.data$Seguimiento <- ifelse(!is.na(y.data$cvisit), y.data$cvisit-y.data$visit,y.data$lvisit-y.data$visit)
towrite <- data.frame("RID", "cs", "Conversion", "Seguimiento", "cAGE", "PTGENDER", "PTEDUCAT" )
colnames(towrite) <- c("RID", "cs", "Conversion", "Seguimiento", "Age", "Gender", "Education")

write.csv(towrite, file="adni_conversion.csv", row.names=F)

AV45

library("ADNIMERGE")
library(psych)
library(ppcor)
dxmci=dxsum[dxsum[, "DXMDUE"] == "MCI due to Alzheimer's Disease" & !is.na(dxsum$DXMDUE) & dxsum[, "DXMDES"] == "MCI - Memory features (amnestic)" & !is.na(dxsum$DXMDES),]
mcimerged0 <- merge(dxmci, adnimerge, by=c("RID", "VISCODE"))
mcimerged1 <- merge(mcimerged0, neurobat, by=c("RID", "VISCODE"))
mcimerged2 <- merge(mcimerged1, adas, by=c("RID", "VISCODE"))
mciwav <- mcimerged2[!is.na(mcimerged2$AV45),]
mcif1 <- mciwav[!is.na(mciwav$Q4SCORE) &!is.na(mciwav$AVDEL30MIN),]
mcif1[!duplicated(mcif1$RID),] -> mcif2
mcif2$zAVD = (mcif2$AVDEL30MIN - mean(mcif2$AVDEL30MIN))/sd(mcif2$AVDEL30MIN)
mcif2$zDR = (mean(mcif2$Q4SCORE) - mcif2$Q4SCORE)/sd(mcif2$Q4SCORE)
gfam <- data.frame(mcif2$zAVD, mcif2$zDR)
famod <- fa(gfam, scores="regression")
mcif2$cs <- famod$scores
mcif2$cAGE = mcif2$AGE + mcif2$Years
y.data <- data.frame(mcif2["RID"], mcif2["cs"], mcif2["AV45"], mcif2["PTGENDER"], mcif2["PTEDUCAT"], mcif2["AGE"], mcif2["VISCODE"])
y.data$Gender <- as.integer(factor(y.data$PTGENDER, levels=c("Male","Female"), labels=c(0,1)))
pcv <- pcor.test(y.data["AV45"], y.data["cs"], y.data[, c("Gender", "PTEDUCAT", "AGE")])
pcv
neuroimagen/adni_dr_av45.txt · Last modified: 2020/08/04 10:58 (external edit)