About 2 results: "gsub repo:adni/adni.bitbucket.org"
Page 1 of 1
Filter Results
Sources
Languages
Filter Results
Try Search On

adnimerger.html in adni.bitbucket.org https://bitbucket.org/adni/adni.bitbucket.org.git | 157 lines | HTML
  1.     <h2 id="examples">Examples</h2>
  2.     <pre class="examples"><div class='input'>## <strong>Not run</strong>: # adnimerge <- adnimerger()# # ## The function is currently defined as# function(){#  #-----------------------------------------FUNCTIONS-----------------------------------------------#  #' Score Montreal Cognitive Assessment (MOCA) without Education Adjustment.#  #'#  #' This function scores the MOCA on ADCS dataset with default variable names.#  #'#  #' @param dd data frame to score.#  #' @param qlist: a list of names of variables in each question of MOCA.#  #' @param trueCoding: character string, for binary covariate, the coding for correct answer with 1 point score, default is 'Correct'.#  #' @param delayedRecallTrueCoding: character string, for delayedRecall items, the coding for 1 point score, default is 'Correct with No Cue'.#  #' @param qScore: binary, TRUE means return subitem score such visuo, naming, memory, attention, language, abstraction, delayedRecall, and orientation. #  #' @return#  #' @references \url{http://www.parkinsons.va.gov/consortium/MOCA.asp}#  #' @author Chung-Kai Sun \email{cksun@ucsd.edu}#  #' @examples#  #' #   scoreMOCA <- function(dd, qlist = list(visuo = c(i1 = 'TRAILS', i2 = 'CUBE', #                                                    i3Contour = 'CLOCKCON', #                                                    i3Numbers = 'CLOCKNO', #                                                    iHands = 'CLOCKHAN'), #                                          naming = c(i4Lion = 'LION', #                                                     i4Rhino = 'RHINO', #                                                     i4Camel = 'CAMEL'), #                                          memory = paste('IMMT', rep(1:2, c(5, 5)),#                                                         paste('W', 1:5, sep=''), sep=''), #                                          attention = c(i6ForDigitSpan = 'DIGFOR', #                                                        i6BackDigitSpan = 'DIGBACK', #                                                        i6Vigilance = 'LETTERS', #                                                        i6Serial1 = 'SERIAL1',#                                                        i6Serial2 = 'SERIAL2',#                                                        i6Serial3 = 'SERIAL3', #                                                        i6Serial4 = 'SERIAL4', #                                                        i6Serial5 = 'SERIAL5'), #                                          language = c(i7SentenceReptition = paste('REPEAT', 1:2, #                                                                                   sep=''), #                                                       i8VerbalFluency = 'FFLUENCY'), #                                          abstraction = c(i9Abstraction1 = 'ABSTRAN', #                                                          i9Abstraction2 = 'ABSMEAS'), #                                          delayedRecall = paste('DELW', 1:5, sep=''), #                                          orientation = c(i11Date = 'DATE', i11Month = 'MONTH', #                                                          i11Year = 'YEAR', i11Day = 'DAY',#                                                          i11Place = 'PLACE', i11City = 'CITY')), #                             trueCoding = 'Correct', #                             delayedRecallTrueCoding = 'Correct with No Cue', qScore = TRUE) { # #     if(!is.data.frame(dd)) {#       stop('dd is not a data.frame')  #     } else if (any(!unlist(qlist) %in% colnames(dd))) {#       stop(paste('Check qlist. dd does not contain', setdiff(unlist(qlist), colnames(dd)), sep=''))    #     } else {#       # non Binary variables#       # c('LETTERS', paste('SERIAL', 1:5, sep=''), 'FFLUENCY', paste('DELW', 1:5, sep=''))#       .i6Vigilance <- qlist$attention['i6Vigilance'] #       .i6Serial <- qlist$attention[paste('i6Serial', 1:5, sep='')]#       .i8VerbalFluency <- qlist$language['i8VerbalFluency']#       .delayedRecall <- qlist$delayedRecall# #       .notBinaryVariables <- c(.i6Vigilance, .i6Serial, .i8VerbalFluency, .delayedRecall)#       .binaryVariables <- setdiff(unlist(qlist), .notBinaryVariables)# #       dd[, c(.binaryVariables, .i6Serial)] <-  sapply(dd[, c(.binaryVariables, .i6Serial)], #              function(x) {#              # for binary variables#              # score is one if coding is trueCoding; missing score is NA; other coding is zero #                 x <- ifelse(x %in% trueCoding, 1, #                             ifelse(is.na(x), NA, 0))#                 return(x)                              #              })# #       # i6Vigilance: 1, 0~1 error #       dd[, .i6Vigilance] <- ifelse(dd[, .i6Vigilance] %in% c(0, 1), 1, #                                    ifelse(is.na(dd[, .i6Vigilance]), NA, 0))# #       # i6Serial7:  0, no correct subtractions; 1, 1 correct substraction; #       #             2, 2-3 correct substraction; 3, 4-5 correct substraction.#       .i6SerialScore <- rowSums(dd[, .i6Serial])#       .i6SerialDic <- list(list(ans=0, score=0), list(ans=1, score=1), list(ans=c(2, 3), score=2), #                             list(ans=c(4, 5), score=3))#       for (i in 1:length(.i6SerialDic)) {#          .ans <- .i6SerialDic[[i]]$ans#          .score <- .i6SerialDic[[i]]$score#          .i6SerialScore <- ifelse(.i6SerialScore %in% .ans, .score, .i6SerialScore)#       }#       dd[, 'i6Serial']  <- .i6SerialScore# #       # i8VerbalFluency:  1, generates 11 words or more; otherwise 0#       dd[, .i8VerbalFluency] <- ifelse(is.numeric(dd[, .i8VerbalFluency]) #                                        & dd[, .i8VerbalFluency] >= 11, 1, #                                        ifelse(is.na(dd[, .i8VerbalFluency]), NA, 0))# #       # delayedRecall: 1: Correct with No Cue; #       #                0: No points are allocated for words recalled with a cue.#       dd[, .delayedRecall] <- sapply(dd[, .delayedRecall], #                                      function(x) {#                                         x <- ifelse(x %in% delayedRecallTrueCoding, 1, #                                                     ifelse(is.na(x), NA, 0))#                                         return(x)                              #                                      })# #       if (qScore) {#          dd[, 'visuo'] <- rowSums(dd[, qlist$visuo]) #          dd[, 'naming'] <- rowSums(dd[, qlist$naming])#          # dd[, memory] <- rowSums(dd[, memory])#          dd[, 'attention'] <- rowSums(dd[, c(qlist$attention[1:3], 'i6Serial')])   #          dd[, 'language'] <- rowSums(dd[, qlist$language])#          dd[, 'abstraction'] <- rowSums(dd[, qlist$abstraction])#          dd[, 'delayedRecall'] <- rowSums(dd[, .delayedRecall])#          dd[, 'orientation'] <- rowSums(dd[, qlist$orientation])#          # dd$MOCA1 <- rowSums(dd[, c('visuo', 'naming', 'attention', 'language', 'abstraction',#          #                            'delayedRecall', 'orientation')])#       }# #      dd$MOCA <- rowSums(dd[, c(setdiff(.binaryVariables, qlist$memory), #                                 .i6Vigilance, 'i6Serial', .i8VerbalFluency, .delayedRecall)]) #     return(dd)#     }#  }#  #  #' Score Everyday Cognition E-Cog#  #'#  #' This function scores the ECOG on ADCS dataset with default variable names#  #' following: http://www.sciencedirect.com/science/article/pii/S1552526011000896#  #'#  #' @param x row of data to score#  #' @return scored value#  #' @references \url{http://www.sciencedirect.com/science/article/pii/S1552526011000896}#  #' @author Michael Donohue \email{mdonohue@ucsd.edu}#  #' @examples#  #' #  #  ecog.score <- function(x){ # #    # coded data:#    # 1=1- Better or no change; #    # 2=2- Questionable/occasionally worse; #    # 3=3- Consistently a little worse; #    # 4=4- Consistently much worse; #    # 9=9- I don't know#    #    # coerce to numeric#    x <- as.numeric(unlist(lapply(strsplit(as.character(x), '- ', fixed = TRUE),#                                  FUN = function(x) x[1])))# #    # convert 9s to NA#    x[x == 9] <- NA# #    missing <- sum(is.na(x))#    if(missing/length(x) < 0.5){#      return(mean(x, na.rm = TRUE))#    }else{#      return(NA)#    }#  }# #   # Merge recursively#   # Recursively merge data frames#   ##   # @arguments list of data frames to merge#   # @seealso \code{\link{merge_all}}#   # @keyword internal#   merge_recurse <- function(dfs, ...) {#     getCommonCols <- function(x, y) {#        intersect(colnames(x), colnames(y)) #     }# #     if (length(dfs) == 2) {#       merge(dfs[[1]], dfs[[2]], by = getCommonCols(dfs[[1]], dfs[[2]]), all=TRUE, sort=FALSE, ...)#     } else {#       merge(dfs[[1]], Recall(dfs[-1]), all=TRUE, sort=FALSE, ...)#     }#   }# #   ordered <- function(x) x[with(x, order(RID, EXAMDATE)), ]# #   # Check if data.frame has duplications#   is.duplicated <- function(x, bycols=c('RID', 'EXAMDATE')) {#    .return <- any(duplicated(Reduce(function(x, y) paste(x, y, sep='_'), x[, bycols])))#    if (.return) {#       .dd <- x[duplicated(Reduce(function(x, y) paste(x, y, sep='_'), x[, bycols])), bycols]#       .x <- x[Reduce(function(x, y) paste(x, y, sep='_'), x[, bycols]) %in% #               Reduce(function(x, y) paste(x, y, sep='_'), .dd[, bycols]), ] #       .x <- .x[eval(parse(text=paste('order(', paste('.x$', bycols, collapse=', '), ')', sep=''))), ]#       return(.x)#    } else { #       return(.return)#    }#   }# #   # sort ADNIMERGE datatable and remove duplications#   removeDups.adnimerge <- function(dd) {#      .dd <- dd[order(dd$RID, match(dd$COLPROT, c('ADNI1', 'ADNIGO', 'ADNI2'))), ]#      .dd <- .dd[!duplicated(paste(.dd$RID, .dd$VISCODE, sep='')), ]#      return(.dd) #   }# #   #--------------------------------------END OF FUNCTIONS-------------------------------------------# #   CDRs <- c('CDMEMORY', 'CDORIENT', 'CDJUDGE', 'CDCOMMUN', 'CDHOME', 'CDCARE')#   cdr$CDRSB <- apply(cdr[, CDRs], 1, sum)#   adas$ADAS11 <- adas[, 'TOTSCORE']#   adas$ADAS13 <- adas[, 'TOTAL13']#   mmse$MMSE <- mmse[, 'MMSCORE']#   faq$FAQ <- faq[, 'FAQTOTAL']#   # MOCA Score without Education adjustment#   moca <- scoreMOCA(moca)#   moca <- moca[!is.na(moca$MOCA), ]# #   roster$SITE <- unlist(lapply(strsplit(#                                as.character(roster$PTID), "_S_", fixed = TRUE), #                                function(x){ x[1] }))#   apoeres$APOE4 <- rowSums(apoeres[, c("APGEN1","APGEN2")] == 4)#   apoego2$APOE4 <- rowSums(apoego2[, c("APGEN1","APGEN2")] == 4)#   apoe <- rbind(subset(apoeres, VISCODE == 'sc', c("RID", "APOE4")), apoego2[, c("RID", "APOE4")])# #   pibpetsuvr$PIB   <- rowMeans(pibpetsuvr[, c('FRC', 'ACG', 'PRC', 'PAR')])#   ucberkeleyav45$AV45 <- rowMeans(ucberkeleyav45[, c('FRONTAL', 'CINGULATE', #                                              'TEMPORAL', 'PARIETAL')]) / ucberkeleyav45$WHOLECEREBELLUM# #   ucberkeleyfdg <- ADNIMERGE::ucberkeleyfdg#   ucberkeleyfdg$ROINAME <- as.character(ucberkeleyfdg$ROINAME)#   ucberkeleyfdg$ROILAT <- as.character(ucberkeleyfdg$ROILAT)#   ucberkeleyfdg$ROI <- paste(as.character(ucberkeleyfdg$ROILAT), as.character(ucberkeleyfdg$ROINAME), sep = ".")#   UCBPETs <- c("ORIGPROT", "RID", "VISCODE", "EXAMDATE", "ROINAME", #                "ROILAT", "MEAN", "MEDIAN", "MODE", "MIN", "MAX",#                "STDEV", "NANVOX", "TOTVOX", "ROI")#   ucberkeleyfdg1 <- stats::reshape(ucberkeleyfdg[, UCBPETs], v.names = c('MEAN', 'MEDIAN', 'MODE', 'MIN', 'MAX', 'STDEV', 'NANVOX', 'TOTVOX'),#                      timevar = 'ROI', idvar = c('RID', 'VISCODE', 'EXAMDATE'), drop = c('ROINAME', 'ROILAT'),#                      direction = "wide")# #   ucberkeleyfdg1$FDGANG  <- rowSums(ucberkeleyfdg1[,c('MEAN.Left.Angular', 'MEAN.Right.Angular')])#   ucberkeleyfdg1$FDGTEMP <- rowSums(ucberkeleyfdg1[,c('MEAN.Left.Temporal', 'MEAN.Right.Temporal')])#   ucberkeleyfdg1$FDGPC   <- ucberkeleyfdg1$MEAN.Bilateral.CingulumPost#   ucberkeleyfdg1$FDG    <- rowSums(ucberkeleyfdg1[,c('FDGANG', 'FDGPC', 'FDGTEMP')])#   fdg1 <- ucberkeleyfdg1# #   # Estevez-Gonzalez, A., Kulisevsky, J., Boltes, A., Otermin, P., & Garcia-Sanchez, C. (2003). #   # Rey verbal learning test is a useful tool for differential diagnosis in the preclinical phase#   # of Alzheimer's disease: comparison with mild cognitive impairment and normal aging. #   # International Journal of Geriatric Psychiatry. 18 (11), 1021.# #   neurobat$RAVLT.immediate <- rowSums(neurobat[, paste('AVTOT', 1:5, sep='')], na.rm=FALSE)#   neurobat$RAVLT.learning <- neurobat$AVTOT5-neurobat$AVTOT1#   neurobat$RAVLT.forgetting <- neurobat$AVTOT5-neurobat$AVDEL30MIN#   neurobat$RAVLT.perc.forgetting <- 100*neurobat$RAVLT.forgetting / neurobat$AVTOT5#   neurobat$RAVLT.perc.forgetting <- ifelse(neurobat$AVTOT5 == 0, NA, neurobat$RAVLT.perc.forgetting)#   neurobat$RAVLT <- neurobat$RAVLT.learning#  #  # E-Cog#  # Change VISSPAT5 to LANG5  Aug.15 2012#  mem <- c('MEMORY1', 'MEMORY2', 'MEMORY3', 'MEMORY4', 'MEMORY5', 'MEMORY6', 'MEMORY7', 'MEMORY8')#  lang <-  c('LANG1', 'LANG2', 'LANG3', 'LANG4', 'LANG5', 'LANG6', 'LANG7', 'LANG8', 'LANG9')#  visspat <- c('VISSPAT1', 'VISSPAT2', 'VISSPAT3', 'VISSPAT4', 'VISSPAT6', 'VISSPAT7', 'VISSPAT8')#  plan <- c('PLAN1', 'PLAN2', 'PLAN3', 'PLAN4', 'PLAN5')#  organ <- c('ORGAN1', 'ORGAN2', 'ORGAN3', 'ORGAN4', 'ORGAN5', 'ORGAN6')#  divatt <- c('DIVATT1', 'DIVATT2', 'DIVATT3', 'DIVATT4')#  #   # ecogpt   Everyday Cognition - Participant Self-Report#   ecogpt$EcogPtMem <- apply(ecogpt[, mem], 1, ecog.score)#   ecogpt$EcogPtLang <- apply(ecogpt[, lang], 1, ecog.score)#   ecogpt$EcogPtVisspat <- apply(ecogpt[, visspat], 1, ecog.score)#   ecogpt$EcogPtPlan <- apply(ecogpt[, plan], 1, ecog.score)#   ecogpt$EcogPtOrgan <- apply(ecogpt[, organ], 1, ecog.score)#   ecogpt$EcogPtDivatt <- apply(ecogpt[, divatt], 1, ecog.score)#   ecogpt$EcogPtTotal <- apply(ecogpt[, c(mem, lang, visspat, plan, organ, divatt)], 1, ecog.score)#   #   # ecogsp   Everyday Cognition - Study Partner Report#   ecogsp$EcogSPMem <- apply(ecogsp[, mem], 1, ecog.score)#   ecogsp$EcogSPLang <- apply(ecogsp[, lang], 1, ecog.score)#   ecogsp$EcogSPVisspat <- apply(ecogsp[, visspat], 1, ecog.score)#   ecogsp$EcogSPPlan <- apply(ecogsp[, plan], 1, ecog.score)#   ecogsp$EcogSPOrgan <- apply(ecogsp[, organ], 1, ecog.score)#   ecogsp$EcogSPDivatt <- apply(ecogsp[, divatt], 1, ecog.score)#   ecogsp$EcogSPTotal <- apply(ecogsp[, c(mem, lang, visspat, plan, organ, divatt)], 1, ecog.score)#  #   #simplify DXCHANGE labels #   dxchange_levs <- c('Stable: NL', 'Stable: MCI', 'Stable: Dementia', 'Conversion: NL to MCI', #     'Conversion: MCI to Dementia', 'Conversion: NL to Dementia', #     'Reversion: MCI to NL', 'Reversion: Dementia to MCI', 'Reversion: Dementia to NL')#   if(!any(dxsum$DXCHANGE %in% dxchange_levs)) stop("DXCHANGE levels have changed")#   dxsum$DX <- factor(dxsum$DXCHANGE,#     levels=dxchange_levs,#     labels=gsub("Reversion: ", "", gsub("Conversion: ", "", gsub("Stable: ", "", dxchange_levs))))#   label(dxsum$DX) <- "Dx status"# #   COLIDs <- c("COLPROT", "ORIGPROT", "RID", "VISCODE")#   KEYIDs <- c('RID', 'VISCODE')#   # RGCONDCT: Was this visit conducted? Yes#   registry <- rbind(registry[registry$COLPROT %in% c('ADNIGO', 'ADNI2') #                            & registry$VISTYPE %in% 'Standard', ], #                     registry[registry$COLPROT %in% c('ADNI1') #                            & (registry$VISCODE %in% 'sc' | registry$RGCONDCT %in% 'Yes'), ])#   #   registry <- registry[order(registry$RID, match(registry$COLPROT, c('ADNI1', 'ADNIGO', 'ADNI2'))), ]#   # remove duplicates #   registry <- removeDups.adnimerge(registry)#   #   arm$DX.bl <- arm$DX#   dd <- merge(registry[, c(COLIDs, "EXAMDATE", "RGCONDCT", "RGSTATUS")],#               subset(arm, COLPROT == ORIGPROT, select = c("RID", "DX.bl")), all.x = TRUE)# #   dd$Baselined <- ifelse(dd$RID %in% #     subset(registry, VISCODE == "bl" & (RGCONDCT == "Yes" | RGSTATUS == "Yes" | VISTYPE == "Standard"))$RID, 1, 0)#   #   dd <- dd[dd$Baselined %in% 1, ]#   dd <- merge(dd,#               subset(ptdemog, COLPROT == ORIGPROT & VISCODE == "sc", #                select = c("RID", "AGE", "PTGENDER", "PTEDUCAT", "PTETHCAT", "PTRACCAT", "PTMARRY")),#               all.x = TRUE)#   dd <- merge(dd,#               subset(roster, COLPROT == ORIGPROT, #               select = c("RID", "PTID", "SITE")),#               all.x = TRUE)#   dd <- merge(dd, apoe, by = "RID", all.x = TRUE)# #   fdg1 <- ordered(fdg1)#   pibpetsuvr <- ordered(pibpetsuvr)#   ucberkeleyav45 <- ordered(ucberkeleyav45)# #   # dd <- merge(dd, subset(fdg1, !duplicated(RID), c("RID", "FDG")), by = "RID", all.x = TRUE)#   # dd <- merge(dd, subset(pibpetsuvr, !duplicated(RID), c("RID", "PIB")), by = "RID", all.x = TRUE)#   # dd <- merge(dd, subset(ucberkeleyav45, !duplicated(RID), c("RID", "AV45")), by = "RID", all.x = TRUE)#  #   dd <- merge(dd, subset(fdg1, , c("RID", "VISCODE", "FDG")), by = c("RID", "VISCODE"), all.x = TRUE)#   dd <- merge(dd, subset(pibpetsuvr, , c("RID", "VISCODE", "PIB")), by = c("RID", "VISCODE"), all.x = TRUE)#   dd <- merge(dd, subset(ucberkeleyav45, , c("RID", "VISCODE", "AV45")), by = c("RID", "VISCODE"), all.x = TRUE)# #   process.fs <- function(ucsfvol) {#     ucsfvol$ICV <- ucsfvol$ST10CV#     ucsfvol$Hippocampus <- (ucsfvol$ST29SV + ucsfvol$ST88SV)#     ucsfvol$Entorhinal <- (ucsfvol$ST24CV + ucsfvol$ST83CV)#     ucsfvol$Fusiform <- (ucsfvol$ST26CV + ucsfvol$ST85CV)#     ucsfvol$MidTemp <- (ucsfvol$ST40CV + ucsfvol$ST99CV)#     ucsfvol$Ventricles <- (ucsfvol$ST30SV +#                            ucsfvol$ST37SV + #                            ucsfvol$ST89SV + #                            ucsfvol$ST96SV)#     ucsfvol$WholeBrain <- apply(ucsfvol[, c('ST128SV', 'ST17SV', 'ST18SV', 'ST61SV', #                                             'ST16SV', 'ST53SV', 'ST42SV', 'ST29SV', #                                             'ST12SV', 'ST11SV', 'ST65SV', 'ST76SV', #                                             'ST77SV', 'ST120SV', 'ST75SV', 'ST112SV', #                                             'ST101SV', 'ST88SV', 'ST71SV', 'ST70SV',#                                             'ST124SV', 'ST147SV', 'ST148SV', 'ST150SV', #                                             'ST151SV')], 1, sum)# #     ucsfvol$Hippocampus <- ifelse(ucsfvol$TEMPQC=="Fail", NA, ucsfvol$Hippocampus)#     ucsfvol$Entorhinal <- ifelse(ucsfvol$TEMPQC=="Fail", NA, ucsfvol$Entorhinal)#     ucsfvol$Fusiform <- ifelse(ucsfvol$TEMPQC=="Fail", NA, ucsfvol$Fusiform)#     ucsfvol$MidTemp <- ifelse(ucsfvol$TEMPQC=="Fail", NA, ucsfvol$MidTemp)#     ucsfvol$Ventricles <- ifelse(ucsfvol$TEMPQC=="Fail", NA, ucsfvol$Ventricles)#     ucsfvol$WholeBrain <- ifelse(ucsfvol$TEMPQC=="Fail", NA, ucsfvol$WholeBrain)#     ucsfvol#   }# #   MRIs <- c('Hippocampus', 'Entorhinal', 'Fusiform', 'MidTemp', 'Ventricles', 'WholeBrain', 'ICV')#   colnames(ucsffsx)[colnames(ucsffsx) %in% 'ST19SV'] <- 'ST147SV'#   colnames(ucsffsx)[colnames(ucsffsx) %in% 'ST20SV'] <- 'ST150SV'#   colnames(ucsffsx)[colnames(ucsffsx) %in% 'ST78SV'] <- 'ST148SV'#   colnames(ucsffsx)[colnames(ucsffsx) %in% 'ST79SV'] <- 'ST151SV'#   ucsfvol1 <- process.fs(ucsffsx)#   colnames(ucsffsx)[colnames(ucsffsx) %in% 'ST147SV'] <- 'ST19SV' #   colnames(ucsffsx)[colnames(ucsffsx) %in% 'ST150SV'] <- 'ST20SV'#   colnames(ucsffsx)[colnames(ucsffsx) %in% 'ST148SV'] <- 'ST78SV'#   colnames(ucsffsx)[colnames(ucsffsx) %in% 'ST151SV'] <- 'ST79SV'#   ucsfvol1 <- ucsfvol1[!apply(ucsfvol1[, MRIs], 1, function(x) all(is.na(x))), ]#   ucsfvol1 <- ucsfvol1[!ucsfvol1$VISCODE %in% 'f', ]#   ucsfvol1 <- ucsfvol1[order(ucsfvol1$RID, ucsfvol1$EXAMDATE, match(ucsfvol1$OVERALLQC, c('Pass', 'Partial'))), ]#   # Remove duplicates in ucsfvol1 with the same RID, VISCODE and OVERALLQC #   ucsfvol1 <- ucsfvol1[!duplicated(with(ucsfvol1, paste(RID, VISCODE, OVERALLQC, sep=''))), ] # #   ucsffsx51 <- subset(ucsffsx51, IMAGETYPE == "Non-Accelerated T1", )#   ucsfvol2 <- process.fs(ucsffsx51)#   # Removed MRIs all NAs in ucsfvol2 #   ucsfvol2 <- ucsfvol2[!apply(ucsfvol2[, MRIs], 1, function(x) all(is.na(x))), ]# #   reg.sc <- registry[registry$VISCODE %in% 'sc', c('RID', 'EXAMDATE')]#   ucsfvol2 <- merge(ucsfvol2, reg.sc, by='RID', suffixes=c('', '.sc'), all.x=TRUE) #   ucsfvol2 <- merge(ucsfvol2, registry[registry$COLPROT %in% c('ADNIGO', 'ADNI2'), c('RID', 'VISCODE', 'EXAMDATE')], #               by=c('RID', 'EXAMDATE'), suffixes=c('.x', ''), all.x=TRUE)#   # ucsfvol2$VISCODE <- ucsfvol2$VISCODE2#   # ucsfvol2 <- ucsfvol2[order(ucsfvol2$RID, ucsfvol2$VISCODE), ]#   ucsfvol2[ucsfvol2$VISCODE %in% 'scmri', 'VISCODE'] <- 'sc'#   ucsfvol2 <- ucsfvol2[!duplicated(paste(ucsfvol2$RID, ucsfvol2$VISCODE, sep='')), ] # #   # non-accelerated data more complete, so use that#   COLs <- c('RID', 'VISCODE', 'EXAMDATE', 'LONISID', 'LONIUID', 'IMAGEUID', MRIs)#   ucsfvol <- rbind(ucsfvol1[, COLs], ucsfvol2[, COLs])#   ucsfvol <- ucsfvol[paste(ucsfvol$RID, ucsfvol$VISCODE, sep='') %in% paste(dd$RID, dd$VISCODE, sep=''), ]# #   # Refine levels & labels#   # change dd$DX.bl to reflect baseline diagnosis instead of screening diagnosis#   dd$DX.bl <- as.character(dd$DX.bl)#   dd$DX.bl <- with(dd,#     ifelse(RID %in% subset(dxsum, VISCODE == "bl" & DXCHANGE == "Conversion: MCI to Dementia")$RID, #     "AD", DX.bl))#   dd$DX.bl <-with(dd, #     ifelse(RID %in% subset(dxsum, VISCODE == "bl" & DXCHANGE == "Reversion: MCI to NL")$RID & DX.bl != "EMCI",#     "NL", DX.bl))#   dd$DX.bl <- with(dd, #     ifelse(RID %in% subset(dxsum, VISCODE == "bl" & DXCHANGE == "Conversion: NL to MCI")$RID & DX.bl != "EMCI",#     "MCI", DX.bl))#   dd$DX.bl <- with(dd,#     ifelse(RID %in% subset(dxsum, VISCODE == "bl" & DXCHANGE == "Reversion: Dementia to MCI")$RID, #     "LMCI", DX.bl))#   #   dd$DX.bl <- factor(dd$DX.bl, levels = c('NL', 'SMC', 'EMCI', 'LMCI', 'AD'),#                   labels = c('CN', 'SMC', 'EMCI', 'LMCI', 'AD'))#   dd$SITE <- as.factor(dd$SITE)# #   dd$PTETHCAT <- factor(dd$PTETHCAT, #                         levels = c('Unknown', 'Not Hispanic or Latino', 'Hispanic or Latino'),#                         labels = c('Unknown', 'Not Hisp/Latino', 'Hisp/Latino'))#   dd$PTRACCAT <- factor(dd$PTRACCAT,#                         levels = c('American Indian or Alaskan Native', 'Asian', #                                    'Native Hawaiian or Other Pacific Islander', 'Black or African American', #                                    'White', 'More than one race', 'Unknown'),#                         labels =   c('Am Indian/Alaskan', 'Asian', #                                      'Hawaiian/Other PI', 'Black', #                                      'White', 'More than one', 'Unknown'))# #   CDRs <- 'CDRSB'; CDR.LBs <- 'CDR-SB' #   ADASs <- c('ADAS11', 'ADAS13'); ADAS.LBs <- c('ADAS 11', 'ADAS 13')#   MMSEs <- 'MMSE'; MMSE.LBs <- 'MMSE' #   NEUROBATs <- c('RAVLT', 'RAVLT.immediate'); #   NEUROBAT.LBs <- c('RAVLT (forgetting)', 'RAVLT (5 sum)')#   FAQs <- "FAQ"; FAQ.LBs <- 'FAQ'#   UCSFVOLs <- c("Ventricles", "Hippocampus", "WholeBrain", "Entorhinal", "Fusiform", "MidTemp", "ICV")#   UCSF.LBs <- c('UCSF Ventricles', 'UCSF Hippocampus', 'UCSF WholeBrain', 'UCSF Entorhinal', 'UCSF Fusiform', 'UCSF Med Temp', 'UCSF ICV')#   MOCAs <- c('MOCA'); MOCA.LBs <- c('MOCA')#   ECOGPTs <- paste('EcogPt', c('Mem', 'Lang', 'Visspat', 'Plan', 'Organ', 'Divatt', 'Total'), sep = '')#   ECOGPT.LBs <- paste('Pt ECog', c('Mem', 'Lang', 'Vis/Spat', 'Plan', 'Organ', 'Div atten', 'Total'), sep = ' - ')#   ECOGSPs <- c('EcogPtMem', 'EcogPtVisspat', 'EcogPtPlan', 'EcogPtOrgan', 'EcogPtDivatt', 'EcogPtLang', 'EcogPtTotal')#   ECOGSPs <- paste('EcogSP', c('Mem', 'Lang', 'Visspat', 'Plan', 'Organ', 'Divatt', 'Total'), sep = '')#   ECOGSP.LBs <- paste('SP ECog', c('Mem', 'Lang', 'Vis/Spat', 'Plan', 'Organ', 'Div atten', 'Total'), sep = ' - ')#  #   covariates <- c(CDRs, ADASs, MMSEs, NEUROBATs, FAQs, UCSFVOLs, MOCAs, ECOGPTs, ECOGSPs)#   vlabels <- c(CDR.LBs, ADAS.LBs, MMSE.LBs, NEUROBAT.LBs, FAQ.LBs, UCSF.LBs, MOCA.LBs, ECOGPT.LBs, ECOGSP.LBs) #    #   cdr <- cdr[!cdr$VISCODE %in% 'bl', ]#   cdr$VISCODE <- ifelse(cdr$VISCODE %in% 'sc', 'bl', cdr$VISCODE) #   mmse <- mmse[!mmse$VISCODE %in% 'bl', ]#   mmse$VISCODE <- ifelse(mmse$VISCODE %in% 'sc', 'bl', mmse$VISCODE) #   ucsfvol <- ucsfvol[!ucsfvol$VISCODE %in% 'bl', ]#   ucsfvol$VISCODE <- ifelse(ucsfvol$VISCODE %in% 'sc', 'bl', ucsfvol$VISCODE) #   #   adas <- adas[!adas$VISCODE %in% 'sc', ]#   neurobat <- neurobat[!neurobat$VISCODE %in% 'sc', ]#   faq <- faq[!faq$VISCODE %in% 'sc', ]#   ecogpt <- ecogpt[!ecogpt$VISCODE %in% 'sc', ]#   ecogsp <- ecogsp[!ecogsp$VISCODE %in% 'sc', ] # #   ldf <- list(cdr=cdr[, c(COLIDs, CDRs)],#               adas=adas[, c(COLIDs, ADASs)],#               mmse=mmse[, c(COLIDs, MMSEs)], #               neurobat=neurobat[, c(COLIDs, NEUROBATs)], #               faq=faq[, c(COLIDs, FAQs)], #               moca=moca[, c(COLIDs, MOCAs)],#               ecogpt=ecogpt[, c(COLIDs, ECOGPTs)],#               ecogsp=ecogsp[, c(COLIDs, ECOGSPs)])#               # ucsfvol=ucsfvol[, c(COLIDs, UCSFVOLs)])#   ldf <- lapply(ldf, removeDups.adnimerge)             #   ldf <- lapply(ldf, function(x) {#                          x <- x[, -grep('PROT', colnames(x))]#                          return(x) #                       })# #   mdf <- merge_recurse(ldf) #   dd <- merge(dd, mdf, by=KEYIDs, all.x=TRUE)#   dup <- is.duplicated(dd, bycols=KEYIDs)#   # make Education adjustment for MOCA; #   # Add one point for an individual who has 12 years or fewer of formal education, for a possible maximum of 30 points#   dd$MOCA <- ifelse(dd$PTEDUCAT <= 12, dd$MOCA + 1, dd$MOCA)#   dd$MOCA <- ifelse(dd$MOCA > 30, 30, dd$MOCA)#   dd <- merge(dd, ucsfvol[c('RID', 'VISCODE', UCSFVOLs)], by=c('RID', 'VISCODE'), all.x=TRUE)#   dd <- dd[!dd$VISCODE %in% c('sc', 'f', 'scmri', 'uns1'), ] #   # dd <- merge(dd, subset(dxsum, VISCODE %in% c('sc', 'bl'), c('RID', 'VISCODE', 'DX')), by=c('RID', 'VISCODE'), all.x=TRUE)#   dd <- merge(dd, subset(dxsum, , c('RID', 'VISCODE', 'DX')), by=c('RID', 'VISCODE'), all.x=TRUE)# #  label(dd$DX.bl) <- "Baseline Dx"#  label(dd$PTEDUCAT) <- "Education"#  label(dd$AGE) <- "Age"#  label(dd$PTGENDER) <- "Sex"#  label(dd$PTETHCAT) <- "Ethnicity"#  label(dd$PTRACCAT) <- "Race"#  label(dd$PTMARRY) <- "Marital"#  label(dd$APOE4) <- 'ApoE4'#  #  for(i in 1:length(covariates)) label(dd[, covariates[i]]) <- vlabels[i]#  for(i in 1:length(MRIs)) units(dd[, MRIs[i]]) <- "mm3"#  #   dd.bl <- subset(dd, COLPROT==ORIGPROT & VISCODE %in% c('bl'), c('RID', 'EXAMDATE', covariates, 'FDG', 'PIB', 'AV45')) #   dd <- merge(dd, dd.bl, by='RID', all.x=TRUE, suffixes=c('', '.bl'))#   #   dd$Years.bl <- as.numeric(dd$EXAMDATE - dd$EXAMDATE.bl)/365.25#   dd$Month.bl <- as.numeric(dd$EXAMDATE - dd$EXAMDATE.bl)/30.5#   dd$Month <- cut(dd$Month.bl, breaks=c(-1, 0, 4.5, seq(9, 597, 6)), labels=c(0, 3, seq(6, 594, 6)))#   # Months <- as.numeric(levels(dd$Month))[dd$Month]#   # dd$CompVis <- factor(dd$Month, labels= c('bl', 'm03', 'm06', paste('m', sort(unique(Months[Months > 10])), sep='')))# #   dd$M <- as.numeric(gsub("m", "", gsub("bl", 0, dd$VISCODE)))#   dd$m <- as.factor(dd$M)# #   dd[with(dd, order(RID, EXAMDATE)), !colnames(dd) %in% c('Baselined', 'm', 'RGCONDCT', 'RGSTATUS')]# }# ## <strong>End(Not run)</strong></div></pre>

Back to Top