To compare the differences in bone mineral content between BIA and DXA measurements we can link the two data points using unique identifiers like the participants unique ID and scan dates. By using multiple factors we can ensure that each participant is matched to the correct measurement set.
As a proof of concept we’ve utilized the current Men Moving Forward data set which includes up to four measures per participant at various time points, months apart from one another.
Pull all the various data sets together after exporting from DXA computer and BIA SD cards.
#Load libraries
library(dplyr)
library(plyr)
library(readr)
library(ggplot2)
library(ggsci)
library(ggpmisc)
library(CGPfunctions)
library(purrr)
#Import whole body DXA data & patient keys
MMF_DXA_Export_Wbody <- read.csv("/Volumes/Z_Kindl USB/MMF DXA:BIA Exports/MMF_DXA_Export_1_10_23/MMF_DXA_Export_1_10_23_Wbody.csv")
MMF_DXA_Patient_Keys <- read.csv("/Volumes/Z_Kindl USB/MMF DXA:BIA Exports/MMF_DXA_Export_1_10_23/MMF_DXA_Export_1_10_23_PATIENT.csv")
MMF_Scan_Analysis <- read.csv("/Volumes/Z_Kindl USB/MMF DXA:BIA Exports/MMF_DXA_Export_1_10_23/MMF_DXA_Export_1_10_23_ScanAnalysis.csv")
MMF_DXA_Export_Wbody <- select(MMF_DXA_Export_Wbody,PATIENT_KEY,SCANID,WBTOT_BMC)
MMF_DXA_Patient_Keys <- select(MMF_DXA_Patient_Keys,PATIENT_KEY,IDENTIFIER1)
MMF_Scan_Analysis <- select(MMF_Scan_Analysis,PATIENT_KEY,SCANID,SCAN_DATE,WEIGHT,SCAN_TYPE)
data_frames <- list(MMF_DXA_Export_Wbody,MMF_DXA_Patient_Keys,MMF_Scan_Analysis)
merged <- distinct(merge(MMF_DXA_Patient_Keys,MMF_DXA_Export_Wbody,by="PATIENT_KEY"))
MMF_Scan_Analysis<-MMF_Scan_Analysis%>%filter(SCAN_TYPE=="39")
DXA <- distinct(merge(merged,MMF_Scan_Analysis,by=c("PATIENT_KEY","SCANID")))
tanitalist <- list.files(pattern = ".CSV",full.names = TRUE)
data_list <- lapply(tanitalist,read_csv,show_col_types=FALSE)
We will eliminate variables not of interest at the moment to simplify the dataset. Additionally we have to filter by scan type, and use the DXA unique scan identifiers to link to participant MMF ID’s so we are able to link them to each BIA scan which only contain MMF identifiers
DXA2<-select(DXA,IDENTIFIER1,WBTOT_BMC,WEIGHT,SCAN_DATE)
BIA2<-select(BIA,ID,BONE,MDATE,'WEIGHT kg',AGE,GENDER)
#Format unique identifiers to match & filter by gender, age,
#DXA2<-DXA2%>%
# filter((ADJUSTED_AGE.x)>10)%>%
# filter((SEX)!="F")
#eliminate any NA values in bone reading & format unique ID
BIA2 <- BIA2%>%
filter(!is.na(BONE))%>%
filter((GENDER)!="2")%>%
filter(ID!= "0000000000000001")
#Drop extra zeros at start of ID
BIA2$ID<-substring(BIA2$ID,13)
#Rename some columns for easy matching
colnames(DXA2)[colnames(DXA2)=="IDENTIFIER1"]<-"ID"
colnames(DXA2)[colnames(DXA2)=="SCAN_DATE"]<-"DATE"
colnames(DXA2)[colnames(DXA2)=="WBTOT_BMC"]<-"BONE_DXA"
#colnames(DXA2)[colnames(DXA2)=="ADJUSTED_AGE.x"]<-"AGE_DXA"
#colnames(DXA2)[colnames(DXA2)=="WEIGHT.y"]<-"WEIGHT"
colnames(BIA2)[colnames(BIA2)=="MDATE"]<-"DATE"
colnames(BIA2)[colnames(BIA2)=="BONE"]<-"BONE_BIA"
colnames(BIA2)[colnames(BIA2)=="WEIGHT kg"]<-"WEIGHT"
colnames(BIA2)[colnames(BIA2)=="AGE"]<-"AGE_BIA"
#Convert DXA bone measure units from grams to kgs
DXA2$BONE_DXA<-round(DXA2$BONE_DXA/1000,1)
#Format dates for both
DXA2$DATE <- as.Date(DXA2$DATE, "%m/%d/%Y")
BIA2$DATE <- as.Date(BIA2$DATE, "%m/%d/%Y")
Utilizing the MMF ID and Date we merge the two data sets so the scans line up with one another. Once data sets are matched we can substract and calculate a percent difference between the measurements.
#Merge the two data sets by ID and DATE
COMB <- merge(DXA2,BIA2,by=c("ID","DATE","WEIGHT"))
#Drop no longer needed variables
COMB <- select(COMB,ID,DATE,BONE_DXA,BONE_BIA,WEIGHT)
#Convert both BONE measures to numeric then calculate difference between two measures
COMB$BONE_DXA<-as.numeric(COMB$BONE_DXA)
COMB$BONE_BIA <- as.numeric(COMB$BONE_BIA)
#COMB$WEIGHT_BIA <- as.numeric(COMB$WEIGHT_BIA)
#COMB$AGE_BIA <- as.numeric(COMB$AGE_BIA)
COMB$DIFF_BONE<- (COMB$BONE_DXA)-(COMB$BONE_BIA)
COMB$DIFF_BONE <- (COMB$DIFF_BONE/COMB$BONE_DXA)*100
COMB$DIFF_BONE <- as.numeric(abs(round(COMB$DIFF_BONE)))
COMB <- unique(COMB)
We can then plot the respective BMC of each measure technique to
determine the correlation between the two