1
$\begingroup$

I am working on the UKBB data and trying to specify cases and controls by converting ICD9 codes to PheCodes. I have input data (icdt) where the first column (f.eid) is patient IDs and the remaining columns are ICD9 codes. I am using CreatePhewasTable function in R for the conversion. The code seems working well, But I am not getting enough 'TRUE' values for the PheCode 250.1 and 250.2, which represent PheCode for T1D and T2D. I am not sure what I am overlooking because I am getting most of the 'FALSE' values for T1D and T2D columns (250.1 and 250.2). I am sharing my R script

library(data.table)
library(dplyr)
library(PheWAS)
icdt <- fread("icd_codes.tab",header=T,sep="\t")
icdt <- as.data.frame(icdt)

for (i in 215:261) {
  icd9 <- data.frame(matrix(nrow = dim(icdt)[1], ncol = 2))
  icd9[,1] <- icdt[,1]
  colnames(icd9)[1] <- 'f.eid'
  colnames(icd9)[2] <- 'DiagnosisCodes'
  icd9[,2] <- icdt[,i]
  icd9 <- icd9[!rowSums((is.na(icd9))),]
  icd.codes <- icd9 %>% mutate(DiagnosisCodes = (paste0(substr(DiagnosisCodes,1,3),".",substr(DiagnosisCodes,4,nchar(DiagnosisCodes)))))
  icd.count <-  as.data.frame(count(icd.codes, f.eid, DiagnosisCodes))
  phenotypes <- createPhewasTable(icd.count, min.code.count = 1, add.exclusions = T, translate=T)
  phenotypes <- as.data.frame(phenotypes)
  assign(paste('Phecodes',i,sep=''),phenotypes)
  myfile <- paste0( "ALL_Phecodes", i, ".txt")
  write.table(phenotypes, file = myfile, sep = "\t", row.names = FALSE, col.names = TRUE, quote = FALSE, append = FALSE)  
}

Thanks

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.