The ChildRecordsR package is an R package dedicated to the analysis of annotations of daylong recordings in ChildRecordsData format. The objective of our package is to provide data aggregation functions and to analyze the reliability of annotations and annotators.

Install the Vandam data

Vandam daylong recording is a public data set, a childrecordsData format and install procedure is available at (https://github.com/LAAC-LSCP/vandam-daylong-demo)

Create a ChildRecordings class

Here you will create a class by specifying the root folder of your corpus, which needs to be formatted using ChildRecordingData specifications. By using a class, we standardize all the references to the information in your corpus. Additionally, we provide basic checks such as missing files or unreferenced files in the meta data. Try to add, misplace or erase some files to see how these checks work.

library(ChildRecordsR)
ChildRecordingsPath = "/mnt/94707AA4707A8CAC/CNRS/corpus/vandam-daylong-demo" # Use your  own path to Vandam data 
CR = ChildRecordings(ChildRecordingsPath)
#> ###############################################
#> Hello Wellcome to the ChildRecordings R Project 
#> 
#> Your ChildRecording project path contained : 
#>  9  annotations files 
#>  1  are referenced in the metadata 
#>  2  coders were found :  its vtc 
#> 
#> 5  file(s) seem(s) to be unreferenced in the metadata 
#>   more infos in  ChildRecordings$integrity_test$files.unreferenced

All functions are based on the class (i.e., CR in our example above) to avoid problems of reference, since the class is always set up in the same way.

For the purpose of the tutorial we will need more annotation than provided initially. The next function will help us to add some dummy annotations with distortion in the rating. The first dummy annotation will have slightly modified and will be very close to the original; the second and third on will have important modifiable and could be considered as a bad annotator.

New.annotations(row.meta = CR$all.meta[2,], time.sd = 10, change.cat.prob = 0.001, new.name = "vtc_mod", CR)
New.annotations(row.meta = CR$all.meta[2,], time.sd = 1500, change.cat.prob = 0.10, new.name = "vtc_BAD", CR)
New.annotations(row.meta = CR$all.meta[2,], time.sd = 1800, change.cat.prob = 0.15, new.name = "vtc_VeryBAD", CR)

Finding annotations: Search function

Before it can provide any statistical reliability, the current package will need to find annotation segments that have been annotated by at least two annotators. The annotators could be humans or algorithms – the package does not know the difference, so you need to think about implications. This search is performed by the find.rating.segment function, which returns a data frame with the wav filenames, the annotators’ codenames, the annotation filenames and the onset and offset of the annotated segment(s) with respect to the wav.

At a minimum, you need to provide to the search function the class (i.e., CR in our example above) and the relative path to one or several wav files. The function will then find every segment annotated by any annotators in the wav files. In the following example, we provide the path to a single wav file (to speed things up, see section Analyze a corpus in the ChildRecordsR vignette for an example with multiple files):

record.file <- CR$all.meta$recording_filename[1]

find.rating.segment(CR,record.file)
#>   recording_filename         set annotation_filename true_onset true_offset
#> 1    BN32_010007.mp3         its BN32_010007_0_0.csv          0    50464000
#> 2    BN32_010007.mp3         vtc BN32_010007_0_0.csv          0    50464000
#> 3    BN32_010007.mp3     vtc_mod BN32_010007_0_0.csv          0    50464000
#> 4    BN32_010007.mp3     vtc_BAD BN32_010007_0_0.csv          0    50464000
#> 5    BN32_010007.mp3 vtc_VeryBAD BN32_010007_0_0.csv          0    50464000

Alternatively, if a specific time window is provided, the search function will find all the annotations that overlap with the time window provided.

find.rating.segment(CR,record.file,range_from = 27180000, range_to = 27240000)
#>   recording_filename         set annotation_filename true_onset true_offset
#> 1    BN32_010007.mp3         its BN32_010007_0_0.csv   27180000    27240000
#> 2    BN32_010007.mp3         vtc BN32_010007_0_0.csv   27180000    27240000
#> 3    BN32_010007.mp3     vtc_mod BN32_010007_0_0.csv   27180000    27240000
#> 4    BN32_010007.mp3     vtc_BAD BN32_010007_0_0.csv   27180000    27240000
#> 5    BN32_010007.mp3 vtc_VeryBAD BN32_010007_0_0.csv   27180000    27240000
find.rating.segment(CR,record.file,range_from = 27000000, range_to = 50464000)
#>   recording_filename         set annotation_filename true_onset true_offset
#> 1    BN32_010007.mp3         its BN32_010007_0_0.csv    2.7e+07    50464000
#> 2    BN32_010007.mp3         vtc BN32_010007_0_0.csv    2.7e+07    50464000
#> 3    BN32_010007.mp3     vtc_mod BN32_010007_0_0.csv    2.7e+07    50464000
#> 4    BN32_010007.mp3     vtc_BAD BN32_010007_0_0.csv    2.7e+07    50464000
#> 5    BN32_010007.mp3 vtc_VeryBAD BN32_010007_0_0.csv    2.7e+07    50464000
find.rating.segment(CR,record.file,range_from = 0, range_to = 27260000)
#>   recording_filename         set annotation_filename true_onset true_offset
#> 1    BN32_010007.mp3         its BN32_010007_0_0.csv          0    27260000
#> 2    BN32_010007.mp3         vtc BN32_010007_0_0.csv          0    27260000
#> 3    BN32_010007.mp3     vtc_mod BN32_010007_0_0.csv          0    27260000
#> 4    BN32_010007.mp3     vtc_BAD BN32_010007_0_0.csv          0    27260000
#> 5    BN32_010007.mp3 vtc_VeryBAD BN32_010007_0_0.csv          0    27260000

It is also possible to find annotations for a specific set of annotators, by providing the list of their codenames:

raters <- c("its","vtc","vtc_mod","vtc_BAD")
find.rating.segment(CR,record.file,raters)
#>   recording_filename     set annotation_filename true_onset true_offset
#> 1    BN32_010007.mp3     its BN32_010007_0_0.csv          0    50464000
#> 2    BN32_010007.mp3     vtc BN32_010007_0_0.csv          0    50464000
#> 3    BN32_010007.mp3 vtc_mod BN32_010007_0_0.csv          0    50464000
#> 4    BN32_010007.mp3 vtc_BAD BN32_010007_0_0.csv          0    50464000

Time window and limited annotator can also be specified jointly:

search1 <- find.rating.segment(CR,record.file, raters, range_from = 12616000, range_to = 12616000*3)
search1
#>   recording_filename     set annotation_filename true_onset true_offset
#> 1    BN32_010007.mp3     its BN32_010007_0_0.csv   12616000    37848000
#> 2    BN32_010007.mp3     vtc BN32_010007_0_0.csv   12616000    37848000
#> 3    BN32_010007.mp3 vtc_mod BN32_010007_0_0.csv   12616000    37848000
#> 4    BN32_010007.mp3 vtc_BAD BN32_010007_0_0.csv   12616000    37848000

Measuring reliability and classification agreement

Once you have obtained information on a set of annotations with the search function and stored it in an object (search1 above), you can use the aggregate function. This function will create a table with the annotation information, and additionally convert your data into a long format, where annotations are split up into temporal bins. For instance, imagine that an annotator said FEM spoke between .5s and 1s of the wav file. This would be one row in the table format. To convert this to long format, a bin size (in milliseconds) can be provided using the cut argument. For instance, if you specify cut = 10, then that 500 millisecond vocalization by FEM becomes 50 rows, each representing 10 milliseconds of speech. By default cut is set to 100 milliseconds. The function will return a raterData class with the original format and a long format for every annotator.

rating1  = aggregate.rating(search1, CR, cut = 100)
#> number of annotators 4 
#> length of recording annotation for each annotator  25232000 ms or  7.008889 hours

Next, an analysis function can be called. We provide several. They all assume you have at least two annotators. It could be two automated algorithms, two humans, or one automated and one human – this package does not treat these cases differently, so you should interpret results carefully.

The reliability or get.reliability function provides alpha, kappa and AC1 for the whole pool of annotators in your search (so this works even if you have 10 annotators). Reliability will be computed for every speaker category and a composite of all of them.

rez1 = get.reliability(rating1)
#> Reliability indicator by type 
#> 
#> # CHI 
#> 
#>             coeff.name        pa         pe coeff.val coeff.se      conf.int
#> 1 Krippendorff's Alpha 0.9109977 0.82048050   0.50422  0.00175 (0.501,0.508)
#> 2        Fleiss' Kappa 0.9109976 0.82048050   0.50422  0.00175 (0.501,0.508)
#> 3                  AC1 0.9109976 0.04487987   0.90682  0.00044 (0.906,0.908)
#>   p.value     w.name
#> 1       0 unweighted
#> 2       0 unweighted
#> 3       0 unweighted
#> 
#> 
#> # OCH 
#> 
#>             coeff.name        pa         pe coeff.val coeff.se      conf.int
#> 1 Krippendorff's Alpha 0.9752307 0.96401446   0.31169  0.00423  (0.303,0.32)
#> 2        Fleiss' Kappa 0.9752306 0.96401446   0.31169  0.00423  (0.303,0.32)
#> 3                  AC1 0.9752306 0.01199518   0.97493  0.00023 (0.974,0.975)
#>   p.value     w.name
#> 1       0 unweighted
#> 2       0 unweighted
#> 3       0 unweighted
#> 
#> 
#> # FEM 
#> 
#>             coeff.name        pa         pe coeff.val coeff.se      conf.int
#> 1 Krippendorff's Alpha 0.9221872 0.86290818   0.43240  0.00204 (0.428,0.436)
#> 2        Fleiss' Kappa 0.9221871 0.86290818   0.43240  0.00204 (0.428,0.436)
#> 3                  AC1 0.9221871 0.03427296   0.91943  0.00041  (0.919,0.92)
#>   p.value     w.name
#> 1       0 unweighted
#> 2       0 unweighted
#> 3       0 unweighted
#> 
#> 
#> # MAL 
#> 
#>             coeff.name        pa         pe coeff.val coeff.se      conf.int
#> 1 Krippendorff's Alpha 0.9494745 0.88925900   0.54375  0.00235 (0.539,0.548)
#> 2        Fleiss' Kappa 0.9494744 0.88925900   0.54375  0.00235 (0.539,0.548)
#> 3                  AC1 0.9494744 0.03691367   0.94754  0.00034 (0.947,0.948)
#>   p.value     w.name
#> 1       0 unweighted
#> 2       0 unweighted
#> 3       0 unweighted
#> 
#> 
#> # composit 
#> 
#>             coeff.name        pa         pe coeff.val coeff.se      conf.int
#> 1 Krippendorff's Alpha 0.8073858 0.61897208   0.49449  0.00106 (0.492,0.497)
#> 2        Fleiss' Kappa 0.8073856 0.61897208   0.49449  0.00106 (0.492,0.497)
#> 3                  AC1 0.8073856 0.07620558   0.79150  0.00064  (0.79,0.793)
#>   p.value     w.name
#> 1       0 unweighted
#> 2       0 unweighted
#> 3       0 unweighted

Another possible way to investigate annotators is through classification indicators, such as precision, recall, and F-score. These can only be calculated for cases with exactly two annotators. The first annotator will be assumed as the “gold” annotator, so if you have a human and an automated annotator, or someone with more versus less experience, make sure you order them so that the more reliable annotator (more likely to be “gold”) is provided first.

ratercomp <- c("vtc","its")
get.classification(rating1,ratercomp)
#> Confusion matrix : 
#> 
#>          its
#> vtc          CHI    FEM    MAL    OCH overlap silence
#>   CHI      10860   1050    159   2316      29    8067
#>   FEM        377   5192    778    386      10    7095
#>   MAL         66    528   6103     43       5    5546
#>   OCH         41     48     18    526       1     701
#>   overlap   1188   1343   1219    758      12    1772
#>   silence   2051   1764   1082   1070       9  190108
#> 
#> 
#> STD by class : 
#> 
#>                      Class: CHI Class: FEM Class: MAL  Class: OCH
#> Sensitivity          0.74470274 0.52312343 0.65209958 0.103157482
#> Specificity          0.95111846 0.96433109 0.97453100 0.996727638
#> Pos Pred Value       0.48307460 0.37519873 0.49654219 0.394007491
#> Neg Pred Value       0.98380178 0.98015372 0.98643503 0.981779860
#> Precision            0.48307460 0.37519873 0.49654219 0.394007491
#> Recall               0.74470274 0.52312343 0.65209958 0.103157482
#> F1                   0.58601338 0.43698186 0.56378753 0.163506372
#> Prevalence           0.05779543 0.03933482 0.03709164 0.020208385
#> Detection Rate       0.04304041 0.02057696 0.02418744 0.002084646
#> Detection Prevalence 0.08909683 0.05484284 0.04871176 0.005290879
#> Balanced Accuracy    0.84791060 0.74372726 0.81331529 0.549942560
#>                      Class: overlap Class: silence
#> Sensitivity            1.818182e-01      0.8913165
#> Specificity            9.751046e-01      0.8468949
#> Pos Pred Value         1.907184e-03      0.9695233
#> Neg Pred Value         9.997805e-01      0.5877981
#> Precision              1.907184e-03      0.9695233
#> Recall                 1.818182e-01      0.8913165
#> F1                     3.774772e-03      0.9287764
#> Prevalence             2.615716e-04      0.8453082
#> Detection Rate         4.755847e-05      0.7534371
#> Detection Prevalence   2.493649e-02      0.7771212
#> Balanced Accuracy      5.784614e-01      0.8691057
#> 
#> 
#> STD macro indicators : 
#> 
#>        type  unweight    weight
#> 1    Recall 0.5160363 0.8433741
#> 2 Precision 0.4533756 0.8886041
#> 3        F1 0.4471401 0.8603768

Compare annotators

Finally, the raterComparaison function allows you to compare the impact of annotators on reliability indicators. This is useful if you have multiple human annotators and you want to check whether one of them is doing something different, or if you want to check whether your automated annotator stands out in your pool of annotators. You can only use this function when you have more than 2 annotators. The impact of a given annotator is calculated by removing that annotator from the pool of annotators, and observing the increase or decrease in the overall reliability. If the reliability indicators increase after the deletion of a specific annotator, then that annotator should be considered as having a negative impact on the annotations. In our next example, vtc_BAD has a negative impact on reliability.

comparaison = compare.rating(rating1)
#> number of annotators 4 
#> length of reccording annotation 100928000 seconds or  28035.56 hours
#> Record span  25232000 seconds or  7008.889 hours
#> 
#> ### Annotator its ###
#> 
#>                      coeff.val before conf.int before coeff.val after
#> Krippendorff's Alpha            0.494   (0.492,0.497)           0.551
#> Fleiss' Kappa                   0.494   (0.492,0.497)           0.551
#> AC1                             0.792    (0.79,0.793)           0.798
#>                      conf.int after coeff.difference
#> Krippendorff's Alpha  (0.549,0.553)           -0.057
#> Fleiss' Kappa         (0.549,0.553)           -0.057
#> AC1                     (0.797,0.8)           -0.007
#> 
#>           unweight weight
#> Recall       0.398  0.800
#> Precision    0.471  0.772
#> F1           0.394  0.772
#> 
#> ### Annotator vtc ###
#> 
#>                      coeff.val before conf.int before coeff.val after
#> Krippendorff's Alpha            0.494   (0.492,0.497)            0.37
#> Fleiss' Kappa                   0.494   (0.492,0.497)            0.37
#> AC1                             0.792    (0.79,0.793)            0.74
#>                      conf.int after coeff.difference
#> Krippendorff's Alpha  (0.368,0.373)            0.124
#> Fleiss' Kappa         (0.368,0.373)            0.124
#> AC1                   (0.739,0.742)            0.051
#> 
#>           unweight weight
#> Recall       0.622  0.855
#> Precision    0.622  0.861
#> F1           0.604  0.853
#> 
#> ### Annotator vtc_BAD ###
#> 
#>                      coeff.val before conf.int before coeff.val after
#> Krippendorff's Alpha            0.494   (0.492,0.497)           0.696
#> Fleiss' Kappa                   0.494   (0.492,0.497)           0.696
#> AC1                             0.792    (0.79,0.793)           0.886
#>                      conf.int after coeff.difference
#> Krippendorff's Alpha  (0.694,0.699)           -0.202
#> Fleiss' Kappa         (0.694,0.699)           -0.202
#> AC1                   (0.885,0.887)           -0.095
#> 
#>           unweight weight
#> Recall       0.411  0.721
#> Precision    0.339  0.789
#> F1           0.348  0.751
#> 
#> ### Annotator vtc_mod ###
#> 
#>                      coeff.val before conf.int before coeff.val after
#> Krippendorff's Alpha            0.494   (0.492,0.497)           0.370
#> Fleiss' Kappa                   0.494   (0.492,0.497)           0.370
#> AC1                             0.792    (0.79,0.793)           0.741
#>                      conf.int after coeff.difference
#> Krippendorff's Alpha  (0.368,0.373)            0.124
#> Fleiss' Kappa         (0.368,0.373)            0.124
#> AC1                   (0.739,0.742)            0.051
#> 
#>           unweight weight
#> Recall       0.622  0.854
#> Precision    0.622  0.861
#> F1           0.603  0.853
plot(comparaison)