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   1260         109        4    1144         175       10935   332
##   quality   370          84        9     226          58        2652   282
##   urgent    809         162       26    1847         252        5539   615
##   warning   250          22        0     224          40        1308   110
##          
##           palpitations shortness_of_breath
##   normal           465                 920
##   quality          379                 338
##   urgent          1767                1541
##   warning          134                 188
### 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$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): 377     
##  Mean of positive(s): 0.4297    
##  Variance of positive(s): 0.2457
##  ===== Negative(s) =====        
##  Number of negative(s): 31510   
##  Mean of negative(s): 0.3677    
##  Variance of negative(s): 0.2325
##  ===== AUC =====                
##  Area under curve: 0.531        
##                                 
##  =========================      
##     FPR    TPR
##  0.0000 0.0000
##  0.3677 0.4297
##  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): 39      
##  Mean of positive(s): 0.6667    
##  Variance of positive(s): 0.2281
##  ===== Negative(s) =====        
##  Number of negative(s): 31848   
##  Mean of negative(s): 0.3681    
##  Variance of negative(s): 0.2326
##  ===== AUC =====                
##  Area under curve: 0.6493       
##                                 
##  =========================      
##     FPR    TPR
##  0.0000 0.0000
##  0.3681 0.6667
##  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): 3441    
##  Mean of positive(s): 0.5368    
##  Variance of positive(s): 0.2487
##  ===== Negative(s) =====        
##  Number of negative(s): 28446   
##  Mean of negative(s): 0.3481    
##  Variance of negative(s): 0.2269
##  ===== AUC =====                
##  Area under curve: 0.5943       
##                                 
##  =========================      
##     FPR    TPR
##  0.0000 0.0000
##  0.3481 0.5368
##  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): 525     
##  Mean of positive(s): 0.48      
##  Variance of positive(s): 0.2501
##  ===== Negative(s) =====        
##  Number of negative(s): 31362   
##  Mean of negative(s): 0.3666    
##  Variance of negative(s): 0.2322
##  ===== AUC =====                
##  Area under curve: 0.5567       
##                                 
##  =========================      
##     FPR  TPR
##  0.0000 0.00
##  0.3666 0.48
##  1.0000 1.00
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): 20434   
##  Mean of positive(s): 0.2711    
##  Variance of positive(s): 0.1976
##  ===== Negative(s) =====        
##  Number of negative(s): 11453   
##  Mean of negative(s): 0.5422    
##  Variance of negative(s): 0.2482
##  ===== AUC =====                
##  Area under curve: 0.3644       
##                                 
##  =========================      
##     FPR    TPR
##  0.0000 0.0000
##  0.5422 0.2711
##  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): 1339    
##  Mean of positive(s): 0.4593    
##  Variance of positive(s): 0.2485
##  ===== Negative(s) =====        
##  Number of negative(s): 30548   
##  Mean of negative(s): 0.3645    
##  Variance of negative(s): 0.2316
##  ===== AUC =====                
##  Area under curve: 0.5474       
##                                 
##  =========================      
##     FPR    TPR
##  0.0000 0.0000
##  0.3645 0.4593
##  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): 2987    
##  Mean of positive(s): 0.5159    
##  Variance of positive(s): 0.2498
##  ===== Negative(s) =====        
##  Number of negative(s): 28900   
##  Mean of negative(s): 0.3532    
##  Variance of negative(s): 0.2285
##  ===== AUC =====                
##  Area under curve: 0.5813       
##                                 
##  =========================      
##     FPR    TPR
##  0.0000 0.0000
##  0.3532 0.5159
##  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): 2745    
##  Mean of positive(s): 0.6437    
##  Variance of positive(s): 0.2294
##  ===== Negative(s) =====        
##  Number of negative(s): 29142   
##  Mean of negative(s): 0.3425    
##  Variance of negative(s): 0.2252
##  ===== AUC =====                
##  Area under curve: 0.6506       
##                                 
##  =========================      
##     FPR    TPR
##  0.0000 0.0000
##  0.3425 0.6437
##  1.0000 1.0000
plot(ROCit_obj_palpitations)