Package 'harmonydata'

Title: R Library for 'Harmony'
Description: 'Harmony' is a tool using AI which allows you to compare items from questionnaires and identify similar content. You can try 'Harmony' at <https://harmonydata.ac.uk/app/> and you can read our blog at <https://harmonydata.ac.uk/blog/> or at <https://fastdatascience.com/how-does-harmony-work/>. Documentation at <https://harmonydata.ac.uk/harmony-r-released/>.
Authors: Omar Hassoun [aut, cre], Thomas Wood [ctb], Alex, Nikic [ctb], Ulster University [cph]
Maintainer: Omar Hassoun <[email protected]>
License: MIT + file LICENSE
Version: 0.2.1
Built: 2025-03-09 10:56:09 UTC
Source: https://github.com/cran/harmonydata

Help Index


Create instrument from list

Description

This function creates an instrument from a list of questions.

Usage

create_instrument_from_list(
  question_texts,
  question_numbers = NULL,
  instrument_name = "My instrument"
)

Arguments

question_texts

A character vector of question texts.

question_numbers

A character vector of question numbers. If not provided, the question number will be the index of the question text.

instrument_name

A character string of the instrument name.

Author(s)

Alex Nikic

Examples

instrument = create_instrument_from_list(
  list("How old are you?",
    "What is your gender?",
    "What is your name?")
)

Generate Crosswalk Table Function

Description

Generate a crosswalk table for a list of instruments, given the similarity matrix that came out of the match function. A crosswalk is a list of pairs of variables from different studies that can be harmonised.

Usage

generate_crosswalk_table(
  instruments,
  similarity,
  threshold,
  is_allow_within_instrument_matches = FALSE,
  is_enforce_one_to_one = FALSE
)

Arguments

instruments

The original list of instruments, each containing a question. The sum of the number of questions in all instruments is the total number of questions which should equal both the width and height of the similarity matrix.

similarity

The cosine similarity matrix from Harmony

threshold

The minimum threshold that we consider a match. This is applied to the absolute match value. So if a question pair has similarity 0.2 and threshold = 0.5, then that question pair will be excluded. Leave as None if you don't want to apply any thresholding.

is_allow_within_instrument_matches

Defaults to False. If this is set to True, we include crosswalk items that originate from the same instrument, which would otherwise be excluded by default.

is_enforce_one_to_one

Defaults to False. If this is set to True, we force all variables in the crosswalk table to be matched with exactly one other variable.

Value

A crosswalk table as a DataFrame.

Author(s)

Alex Nikic

Examples

instrument_A = create_instrument_from_list(list(
  "How old are you?",
  "What is your gender?"
))

instrument_B = create_instrument_from_list(list(
  "Do you smoke?"
))

instruments = list(instrument_A, instrument_B)

match_response = match_instruments(instruments)
instrument_list = match_response$instruments
similarity_matrix = match_response$matches

crosswalk_table.df = generate_crosswalk_table(
  instrument_list, similarity_matrix, threshold = 0.7,
  is_allow_within_instrument_matches = FALSE, is_enforce_one_to_one = TRUE
)

Retrieve Example Instruments from 'Harmony Data API'

Description

This function retrieves example instruments from the 'Harmony Data API' using an HTTP POST request.

Usage

get_example_instruments()

Value

A list representing example instruments retrieved from the 'Harmony Data API'.

Author(s)

Ulster University [cph]

Examples

# Load required libraries (httr) and call the function
require(httr)
instruments <- get_example_instruments()

# Print the retrieved JSON content
print(instruments)

Load Instruments from File

Description

This function loads instruments from a file specified by the path parameter and sends the file content to an API for further processing. It also accepts a URL leading to a file.

Usage

load_instruments_from_file(path)

Arguments

path

The path to the file to load instruments from.

Value

A list of instruments returned from the API.

Author(s)

Ulster University [cph]

Examples

# Load instruments from a PDF file
pdf_file <- "https://www.apa.org/depression-guideline/patient-health-questionnaire.pdf"
response <- load_instruments_from_file(pdf_file)

Match Instruments Function

Description

This function takes a list of instruments, converts it to a format acceptable by the database, and matches the instruments using the 'Harmony Data API'. It returns the matched instruments.

Usage

match_instruments(instruments, is_negate = TRUE)

Arguments

instruments

A list of instruments to be matched.

is_negate

A boolean value to toggle question negation. Default is TRUE.

Value

A list of matched instruments returned from the 'Harmony Data API'.

Author(s)

Ulster University [cph]

Examples

instrument_A <- create_instrument_from_list(list(
  "How old are you?",
  "What is your gender?"
))

instrument_B <- create_instrument_from_list(list(
  "Do you smoke?"
))

instruments <- list(instrument_A, instrument_B)

matched_instruments <- match_instruments(instruments)