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 |
This function creates an instrument from a list of questions.
create_instrument_from_list( question_texts, question_numbers = NULL, instrument_name = "My instrument" )
create_instrument_from_list( question_texts, question_numbers = NULL, instrument_name = "My instrument" )
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. |
Alex Nikic
instrument = create_instrument_from_list( list("How old are you?", "What is your gender?", "What is your name?") )
instrument = create_instrument_from_list( list("How old are you?", "What is your gender?", "What is your name?") )
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.
generate_crosswalk_table( instruments, similarity, threshold, is_allow_within_instrument_matches = FALSE, is_enforce_one_to_one = FALSE )
generate_crosswalk_table( instruments, similarity, threshold, is_allow_within_instrument_matches = FALSE, is_enforce_one_to_one = FALSE )
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. |
A crosswalk table as a DataFrame.
Alex Nikic
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 )
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 )
This function retrieves example instruments from the 'Harmony Data API' using an HTTP POST request.
get_example_instruments()
get_example_instruments()
A list representing example instruments retrieved from the 'Harmony Data API'.
Ulster University [cph]
# Load required libraries (httr) and call the function require(httr) instruments <- get_example_instruments() # Print the retrieved JSON content print(instruments)
# Load required libraries (httr) and call the function require(httr) instruments <- get_example_instruments() # Print the retrieved JSON content print(instruments)
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.
load_instruments_from_file(path)
load_instruments_from_file(path)
path |
The path to the file to load instruments from. |
A list of instruments returned from the API.
Ulster University [cph]
# 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)
# 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)
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.
match_instruments(instruments, is_negate = TRUE)
match_instruments(instruments, is_negate = TRUE)
instruments |
A list of instruments to be matched. |
is_negate |
A boolean value to toggle question negation. Default is TRUE. |
A list of matched instruments returned from the 'Harmony Data API'.
Ulster University [cph]
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)
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)