samesies

Compare Similarity of Texts, Factors, or Numbers

https://github.com/dylanpieper/samesies

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.3%) to scientific vocabulary
Last synced: 11 months ago · JSON representation

Repository

Compare Similarity of Texts, Factors, or Numbers

Basic Info
Statistics
  • Stars: 7
  • Watchers: 2
  • Forks: 0
  • Open Issues: 0
  • Releases: 1
Created over 1 year ago · Last pushed 12 months ago
Metadata Files
Readme Changelog License

README.md

samesies

CRAN status R-CMD-check

Compare lists of texts, factors, or numerical values to measure their similarity. Use cases include comparing responses from multiple raters, evaluating model outputs, and assessing data consistency.

Installation

From CRAN:

``` r

install.packages("pak")

pak::pak("samesies") ```

Development version:

r pak::pak("dylanpieper/samesies")

Basic Usage

samesies provides three main functions for measuring similarity:

same_text()

Compare similarity between multiple lists of character strings:

``` r library(samesies)

r1 <- list("R is a statistical computing software", "R enables grammar of graphics using ggplot2", "R supports advanced statistical models") r2 <- list("R is a full-stack programming language", "R enables advanced data visualizations", "R supports machine learning algorithms")

tex <- same_text(r1, r2)

> ✔ Computed osa scores for "r1_r2" [mean: 0.43]

> ✔ Computed lv scores for "r1_r2" [mean: 0.43]

> ✔ Computed dl scores for "r1_r2" [mean: 0.43]

> ✔ Computed hamming scores for "r1_r2" [mean: 0.123]

> ✔ Computed lcs scores for "r1_r2" [mean: 0.061]

> ✔ Computed qgram scores for "r1_r2" [mean: 0.682]

> ✔ Computed cosine scores for "r1_r2" [mean: 0.771]

> ✔ Computed jaccard scores for "r1_r2" [mean: 0.735]

> ✔ Computed jw scores for "r1_r2" [mean: 0.818]

> ✔ Computed soundex scores for "r1_r2" [mean: 0.667]

```

Methods available via stringdist (e.g., method = "osa"):

  • Edit Distance Methods
    • osa, lv, dl
  • Token-Based Similarity
    • hamming, lcs, qgram, cosine, jaccard
  • Phonetic Methods
    • jw, soundex

same_factor()

Compare similarity between multiple lists of categorical data:

``` r f1 <- list("R", "R", "Python") f2 <- list("R", "Python", "R")

fct <- same_factor(f1, f2)

> ℹ Skipping 'order' method as factor levels are not ordered

> ✔ Computed exact scores for "f1_f2" [mean: 0.333]

```

Compare similarity based on ordered factors:

``` r of1 <- list("High School", "Bachelor's", "Master's", "PhD") of2 <- list("Bachelor's", "High School", "PhD", "Master's")

educomparison <- samefactor(of1, of2, levels = c("High School", "Bachelor's", "Master's", "PhD"))

fctordered <- averagesimilarity(edu_comparison)

> ✔ Computed exact scores for "of1_of2" [mean: 0]

> ✔ Computed order scores for "of1_of2" [mean: 0.667]

```

Methods available (e.g., method = "exact"):

  • exact: Exact matching
  • order: Distances across ordered factor levels

same_number()

Compare similarity between multiple lists of numeric values:

``` r n1 <- list(1, 2, 3) n2 <- list(1, 2.1, 3.2)

num <- same_number(n1, n2)

> ✔ Computed exact scores for "n1_n2" [mean: 0.333]

> ✔ Computed raw scores for "n1_n2" [mean: 0.1]

> ✔ Computed exp scores for "n1_n2" [mean: 0.908]

> ✔ Computed percent scores for "n1_n2" [mean: 0.963]

> ✔ Computed normalized scores for "n1_n2" [mean: 0.955]

> ✔ Computed fuzzy scores for "n1_n2" [mean: 0.977]

```

Methods available (e.g., method = "exact"):

  • exact: Exact matching
  • raw: Absolute difference
  • exp: Exponential decay on the absolute difference
  • pct_diff: Percentage difference
  • normalized: Normalized difference
  • fuzzy: Intelligent threshold-based matching that adapts to data scale:
    • Uses two tolerance thresholds: absolute (calculated) and relative (default 2%)
    • Calculation of the absolute threshold averages data variability (10% of standard deviation), magnitude (0.5% of mean absolute values), and range (1% of value range)
    • Effective threshold is the larger of these two values
    • Perfect matches (score = 1.0) when difference ≤ effective threshold
    • Scores decrease smoothly as differences exceed the threshold

List Support

Named Lists

For more control over results, you can use named lists to specify custom labels for comparisons:

``` r resultnumber <- samenumber("baseline" = n1, "treatment" = n2, method = "fuzzy")

> ✔ Computed fuzzy scores for "baseline_treatment" [mean: 0.978]

```

More Lists

When you input more than two lists, samesies computes pairwise comparisons across all lists:

``` r r1 <- list("Statistical computing", "Data visualization", "Machine learning") r2 <- list("Statistical software", "Data plotting", "ML algorithms") r3 <- list("Statistical analysis", "Data graphics", "AI models")

multitext <- sametext(r1, r2, r3, method = "cosine")

> ✔ Computed cosine scores for "r1_r2" [mean: 0.717]

> ✔ Computed cosine scores for "r1_r3" [mean: 0.607]

> ✔ Computed cosine scores for "r2_r3" [mean: 0.68]

```

Nested Lists

Compare nested lists with identical structure and names:

``` r nest1 <- list( groupa = list("Good", "Very Good", "Fair"), groupb = list("Excellent", "Good", "Poor") )

nest2 <- list( groupa = list("Very Good", "Good", "Fair"), groupb = list("Good", "Excellent", "Fair")
)

nestedresult <- sametext(nest1, nest2, method = "jw")

> ✔ Computed jw scores for "nest1_nest2" [mean: 0.25]

```

Methods

All three functions return similar objects that support the following methods:

``` r result <- same_text(r1, r2, method = "cosine")

Print detailed results

print(result)

Summarize results

summary(result)

> method pair avg_score

> cosine r1_r2 0.771

Get average similarity scores

average_similarity(result)

> cosine

> 0.771

Get pair-wise averages

pair_averages(result)

> method pair avg_score

> 1 cosine r1_r2 0.771

```

Accessing Object Data

The package uses S3 objects, allowing access to the underlying data using $:

``` r result <- same_text(r1, r2, method = "cosine")

Access similarity scores

result$scores

> $cosine

> $cosine$r1_r2

> R is a statistical computing software

> 0.7917448

> R enables grammar of graphics using ggplot2

> 0.7027498

> R supports advanced statistical models

> 0.8197365

Access methods used

result$methods

> [1] "cosine"

Access list names

result$list_names

> [1] "r1" "r2"

```

Available components:

  • scores: A list of similarity scores for each method and comparison pair
  • summary: A list of statistical summaries for each method and comparison pair
  • methods: The similarity methods used in the analysis
  • list_names: Names of the input lists
  • raw_values: The original input values
  • digits: Number of decimal places for rounding results in output

Credits

The Spiderman image in the hex logo is fan art created by the Reddit user WistlerR15.

Owner

  • Login: dylanpieper
  • Kind: user

GitHub Events

Total
  • Create event: 2
  • Release event: 1
  • Issues event: 2
  • Watch event: 6
  • Delete event: 1
  • Issue comment event: 1
  • Push event: 69
  • Pull request event: 2
Last Year
  • Create event: 2
  • Release event: 1
  • Issues event: 2
  • Watch event: 6
  • Delete event: 1
  • Issue comment event: 1
  • Push event: 69
  • Pull request event: 2

Committers

Last synced: about 1 year ago

All Time
  • Total Commits: 53
  • Total Committers: 1
  • Avg Commits per committer: 53.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 53
  • Committers: 1
  • Avg Commits per committer: 53.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Dylan Pieper d****r@g****m 53

Issues and Pull Requests

Last synced: 12 months ago

All Time
  • Total issues: 1
  • Total pull requests: 1
  • Average time to close issues: about 5 hours
  • Average time to close pull requests: less than a minute
  • Total issue authors: 1
  • Total pull request authors: 1
  • Average comments per issue: 1.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 1
  • Average time to close issues: about 5 hours
  • Average time to close pull requests: less than a minute
  • Issue authors: 1
  • Pull request authors: 1
  • Average comments per issue: 1.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • dylanpieper (1)
Pull Request Authors
  • dylanpieper (2)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cran 157 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 1
  • Total maintainers: 1
cran.r-project.org: samesies

Compare Similarity Across Text, Factors, or Numbers

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 157 Last month
Rankings
Dependent packages count: 27.0%
Dependent repos count: 33.3%
Average: 49.1%
Downloads: 87.0%
Maintainers (1)
Last synced: 12 months ago

Dependencies

DESCRIPTION cran
  • testthat >= 3.0.0 suggests