summary_data <- select(measurements, id, userIds.0, data.indicator, data.context.symptoms.0)
summary_data_clean = na.omit(summary_data)
#Remove NA's
summary_data_clean <- summary_data[-which(summary_data$data.context.symptoms.0 == ""), ]
Removed_data = nrow(summary_data)-nrow(summary_data_clean)
#create a summary table
tabl <- table(summary_data$data.indicator, summary_data$data.context.symptoms.0)
tabl
##
## chest_pains confused fatigue lightheaded no_symptoms other
## normal 1017 60 3 950 131 9403 200
## quality 320 59 6 178 49 2409 256
## urgent 802 140 25 1831 249 5398 579
## warning 161 5 0 129 36 716 18
##
## palpitations shortness_of_breath
## normal 372 484
## quality 307 305
## urgent 1712 1481
## warning 76 63
### create AF column
for(i in 1:nrow(summary_data_clean))
{
if(summary_data_clean$data.indicator[i] == "urgent")
{
summary_data_clean$data.indicator.af[i]= "1"
}
else
{
summary_data_clean$data.indicator.af[i]= "0"
}
}
### create Chestpains column
for(i in 1:nrow(summary_data_clean))
{
if(summary_data_clean$data.context.symptoms.0[i] == "chest_pains")
{
summary_data_clean$chestpains[i]= "1"
}
else
{
summary_data_clean$chestpains[i]= "0"
}
}
### create confused column
for(i in 1:nrow(summary_data_clean))
{
if(summary_data_clean$data.context.symptoms.0[i] == "confused")
{
summary_data_clean$confused[i]= "1"
}
else
{
summary_data_clean$confused[i]= "0"
}
}
### create fatigue column
for(i in 1:nrow(summary_data_clean))
{
if(summary_data_clean$data.context.symptoms.0[i] == "fatigue")
{
summary_data_clean$fatigue[i]= "1"
}
else
{
summary_data_clean$fatigue[i]= "0"
}
}
### create lightheaded column
for(i in 1:nrow(summary_data_clean))
{
if(summary_data_clean$data.context.symptoms.0[i] == "lightheaded")
{
summary_data_clean$lightheaded[i]= "1"
}
else
{
summary_data_clean$lightheaded[i]= "0"
}
}
### create no_symptoms column
for(i in 1:nrow(summary_data_clean))
{
if(summary_data_clean$data.context.symptoms.0[i] == "no_symptoms")
{
summary_data_clean$no_symptoms[i]= "1"
}
else
{
summary_data_clean$no_symptoms[i]= "0"
}
}
### create other column
for(i in 1:nrow(summary_data_clean))
{
if(summary_data_clean$data.context.symptoms.0[i] == "other")
{
summary_data_clean$other[i]= "1"
}
else
{
summary_data_clean$other[i]= "0"
}
}
### palpitations
for(i in 1:nrow(summary_data_clean))
{
if(summary_data_clean$data.context.symptoms.0[i] == "palpitations")
{
summary_data_clean$palpitations[i]= "1"
}
else
{
summary_data_clean$palpitations[i]= "0"
}
}
### shortness of breath
for(i in 1:nrow(summary_data_clean))
{
if(summary_data_clean$data.context.symptoms.0[i] == "shortness_of_breath")
{
summary_data_clean$shortness_of_breath[i]= "1"
}
else
{
summary_data_clean$shortness_of_breath[i]= "0"
}
}
summary_data_clean = subset(summary_data_clean,data.indicator != "quality")
summary_data_clean$data.indicator.af <- as.numeric(summary_data_clean$data.indicator.af)
summary_data_clean$chestpains <- as.numeric(summary_data_clean$chestpains)
summary_data_clean$palpitations <- as.numeric(summary_data_clean$palpitations)
summary_data_clean$shortness_of_breath <- as.numeric(summary_data_clean$shortness_of_breath)
summary_data_clean$other <- as.numeric(summary_data_clean$other)
summary_data_clean$lightheaded <- as.numeric(summary_data_clean$lightheaded)
summary_data_clean$confused <- as.numeric(summary_data_clean$confused)
summary_data_clean$no_symptoms <- as.numeric(summary_data_clean$no_symptoms)
summary_data_clean$lightheaded <- as.numeric(summary_data_clean$lightheaded)
summary_data_clean$fatigue <- as.numeric(summary_data_clean$fatigue)
##### chestpains
ROCit_obj_chestpain <- rocit(score=summary_data_clean$data.indicator.af,class=summary_data_clean$chestpains)
ROCit_obj_chestpain
##
## Method used: empirical
## ===== Positive(s) =====
## Number of positive(s): 205
## Mean of positive(s): 0.6829
## Variance of positive(s): 0.2176
## ===== Negative(s) =====
## Number of negative(s): 23856
## Mean of negative(s): 0.4726
## Variance of negative(s): 0.2493
## ===== AUC =====
## Area under curve: 0.6051
##
## =========================
## FPR TPR
## 0.0000 0.0000
## 0.4726 0.6829
## 1.0000 1.0000
plot(ROCit_obj_chestpain)

##### confused
ROCit_obj_confused <- rocit(score=summary_data_clean$data.indicator.af,class=summary_data_clean$confused)
ROCit_obj_confused
##
## Method used: empirical
## ===== Positive(s) =====
## Number of positive(s): 28
## Mean of positive(s): 0.8929
## Variance of positive(s): 0.09921
## ===== Negative(s) =====
## Number of negative(s): 24033
## Mean of negative(s): 0.4739
## Variance of negative(s): 0.2493
## ===== AUC =====
## Area under curve: 0.7095
##
## =========================
## FPR TPR
## 0.0000 0.0000
## 0.4739 0.8929
## 1.0000 1.0000
plot(ROCit_obj_confused)

##### fatigue
ROCit_obj_fatigue <- rocit(score=summary_data_clean$data.indicator.af,class=summary_data_clean$fatigue)
ROCit_obj_fatigue
##
## Method used: empirical
## ===== Positive(s) =====
## Number of positive(s): 2910
## Mean of positive(s): 0.6292
## Variance of positive(s): 0.2334
## ===== Negative(s) =====
## Number of negative(s): 21151
## Mean of negative(s): 0.4531
## Variance of negative(s): 0.2478
## ===== AUC =====
## Area under curve: 0.588
##
## =========================
## FPR TPR
## 0.0000 0.0000
## 0.4531 0.6292
## 1.0000 1.0000
plot(ROCit_obj_fatigue)

##### lightheaded
ROCit_obj_lightheaded <- rocit(score=summary_data_clean$data.indicator.af,class=summary_data_clean$lightheaded)
ROCit_obj_lightheaded
##
## Method used: empirical
## ===== Positive(s) =====
## Number of positive(s): 416
## Mean of positive(s): 0.5986
## Variance of positive(s): 0.2409
## ===== Negative(s) =====
## Number of negative(s): 23645
## Mean of negative(s): 0.4722
## Variance of negative(s): 0.2492
## ===== AUC =====
## Area under curve: 0.5632
##
## =========================
## FPR TPR
## 0.0000 0.0000
## 0.4722 0.5986
## 1.0000 1.0000
plot(ROCit_obj_lightheaded)

##### no_symptoms
ROCit_obj_no_symptoms <- rocit(score=summary_data_clean$data.indicator.af,class=summary_data_clean$no_symptoms)
ROCit_obj_no_symptoms
##
## Method used: empirical
## ===== Positive(s) =====
## Number of positive(s): 15517
## Mean of positive(s): 0.3479
## Variance of positive(s): 0.2269
## ===== Negative(s) =====
## Number of negative(s): 8544
## Mean of negative(s): 0.7042
## Variance of negative(s): 0.2083
## ===== AUC =====
## Area under curve: 0.3218
##
## =========================
## FPR TPR
## 0.0000 0.0000
## 0.7042 0.3479
## 1.0000 1.0000
plot(ROCit_obj_no_symptoms)

##### other
ROCit_obj_other <- rocit(score=summary_data_clean$data.indicator.af,class=summary_data_clean$other)
ROCit_obj_other
##
## Method used: empirical
## ===== Positive(s) =====
## Number of positive(s): 797
## Mean of positive(s): 0.7265
## Variance of positive(s): 0.199
## ===== Negative(s) =====
## Number of negative(s): 23264
## Mean of negative(s): 0.4658
## Variance of negative(s): 0.2488
## ===== AUC =====
## Area under curve: 0.6303
##
## =========================
## FPR TPR
## 0.0000 0.0000
## 0.4658 0.7265
## 1.0000 1.0000
plot(ROCit_obj_other)

##### shortness_of_breath
ROCit_obj_shortness_of_breath <- rocit(score=summary_data_clean$data.indicator.af,class=summary_data_clean$shortness_of_breath)
ROCit_obj_shortness_of_breath
##
## Method used: empirical
## ===== Positive(s) =====
## Number of positive(s): 2028
## Mean of positive(s): 0.7303
## Variance of positive(s): 0.1971
## ===== Negative(s) =====
## Number of negative(s): 22033
## Mean of negative(s): 0.4509
## Variance of negative(s): 0.2476
## ===== AUC =====
## Area under curve: 0.6397
##
## =========================
## FPR TPR
## 0.0000 0.0000
## 0.4509 0.7303
## 1.0000 1.0000
plot(ROCit_obj_shortness_of_breath)

##### palpitations
ROCit_obj_palpitations <- rocit(score=summary_data_clean$data.indicator.af,class=summary_data_clean$palpitations)
ROCit_obj_palpitations
##
## Method used: empirical
## ===== Positive(s) =====
## Number of positive(s): 2160
## Mean of positive(s): 0.7926
## Variance of positive(s): 0.1645
## ===== Negative(s) =====
## Number of negative(s): 21901
## Mean of negative(s): 0.443
## Variance of negative(s): 0.2468
## ===== AUC =====
## Area under curve: 0.6748
##
## =========================
## FPR TPR
## 0.000 0.0000
## 0.443 0.7926
## 1.000 1.0000
plot(ROCit_obj_palpitations)

write_xlsx(summary_data_clean, "/Volumes/GoogleDrive/Shared drives/9. Clinical/9.6 Data reporting/AZM/PRE-ECV /ggplt/allmeas.xlsx")