calculate_slr: Calculate a Score-Based Likelihood Ratio

View source: R/slrs.R

calculate_slrR Documentation

Calculate a Score-Based Likelihood Ratio

Description

[Superseded] calculate_slr has been superseded in favor of compare_documents() which offers more functionality.

Usage

calculate_slr(
  sample1_path,
  sample2_path,
  rforest = NULL,
  reference_scores = NULL,
  project_dir = NULL
)

Arguments

sample1_path

A file path to a handwriting sample saved in PNG file format.

sample2_path

A file path to a second handwriting sample saved in PNG file format.

rforest

Optional. A random forest trained with ranger. If no random forest is specified, random_forest will be used.

reference_scores

Optional. A dataframe of reference similarity scores. If reference scores is not specified, ref_scores will be used.

project_dir

A path to a directory where helper files will be saved. If no project directory is specified, the helper files will be saved to tempdir() and deleted before the function terminates.

Details

Compares two handwriting samples scanned and saved a PNG images with the following steps:

  1. processDocument splits the writing in both samples into component shapes, or graphs.

  2. get_clusters_batch groups the graphs into clusters of similar shapes.

  3. get_cluster_fill_counts counts the number of graphs assigned to each cluster.

  4. get_cluster_fill_rates calculates the proportion of graphs assigned to each cluster. The cluster fill rates serve as a writer profile.

  5. A similarity score is calculated between the cluster fill rates of the two documents using a random forest trained with ranger.

  6. The similarity score is compared to reference distributions of same writer and different writer similarity scores. The result is a score-based likelihood ratio that conveys the strength of the evidence in favor of same writer or different writer. For more details, see Madeline Johnson and Danica Ommen (2021) doi:10.1002/sam.11566.

Value

A dataframe

Examples


# Compare two samples from the same writer
s1 <- system.file(file.path("extdata", "docs", "w0005_s01_pLND_r03.png"),
  package = "handwriterRF"
)
s2 <- system.file(file.path("extdata", "docs", "w0005_s02_pWOZ_r02.png"),
  package = "handwriterRF"
)
calculate_slr(s1, s2)

# Compare samples from two writers
s1 <- system.file(file.path("extdata", "docs", "w0005_s02_pWOZ_r02.png"),
  package = "handwriterRF"
)
s2 <- system.file(file.path("extdata", "docs", "w0238_s01_pWOZ_r02.png"),
  package = "handwriterRF"
)
calculate_slr(s1, s2)



handwriterRF documentation built on April 4, 2025, 5:38 a.m.