From eed21293c2499f93f2cf525dcce4ac0f01bfc164 Mon Sep 17 00:00:00 2001 From: AlexNikic Date: Fri, 2 Jan 2026 12:24:41 +0000 Subject: [PATCH 1/4] response options reformatted to data frame --- R/match_instruments.R | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/R/match_instruments.R b/R/match_instruments.R index 676b32f..032980e 100644 --- a/R/match_instruments.R +++ b/R/match_instruments.R @@ -154,7 +154,7 @@ match_instruments <- function(instruments, conten$clusters[[i]]$cluster_id <- conten$clusters[[i]]$cluster_id + 1 } - # here we will convert the match_matrix to a data frame to avoid users boilerplating this code + # here we will convert the questions matrix to a data frame to avoid users boilerplating this code df <- data.frame(conten$matches[[1]]) for (x in seq_along(conten$matches)) { df[x, ] <- conten$matches[[x]] @@ -163,5 +163,14 @@ match_instruments <- function(instruments, rownames(df) <- lapply(conten$questions, function(x) paste(x$question_no, x$question_text, sep = " ")) conten$matches <- df + # here we will also convert the response options similarity matrix to a data frame + df_response_options <- data.frame(conten$response_options_similarity[[1]]) + for (x in seq_along(conten$response_options_similarity)) { + df_response_options[x, ] <- conten$response_options_similarity[[x]] + } + colnames(df_response_options) <- lapply(conten$questions, function(x) paste(x$question_no, x$question_text, sep = " "))[seq_len(ncol(df_response_options))] # we add the [seq_len()] to account for the case when there are empty response options + rownames(df_response_options) <- lapply(conten$questions, function(x) paste(x$question_no, x$question_text, sep = " "))[seq_len(nrow(df_response_options))] + conten$response_options_similarity <- df_response_options + return(conten) } From 331fd82e870c86c812c6283ba07932045e8ed8a8 Mon Sep 17 00:00:00 2001 From: AlexNikic Date: Fri, 2 Jan 2026 12:29:21 +0000 Subject: [PATCH 2/4] updated notebook ro reflect changes --- harmony_r_example.Rmd | 12 +++++-- harmony_r_example.html | 73 ++++++++++++++++++++++-------------------- 2 files changed, 47 insertions(+), 38 deletions(-) diff --git a/harmony_r_example.Rmd b/harmony_r_example.Rmd index 0a2d299..671e1c9 100644 --- a/harmony_r_example.Rmd +++ b/harmony_r_example.Rmd @@ -105,13 +105,19 @@ heatmap(as.matrix(match$matches), margins = c(10, 10)) ``` - -The first three entries in the similarity matrix for the response options are: +We can view the first few rows of the similarity matrix for the response options. ```{r} -match$response_options_similarity[[1]][c(1, 2, 3)] +head(match$response_options_similarity) ``` +We can also plot a heat map of the response options similarity matrix. + +```{r} +heatmap(as.matrix(match$response_options_similarity), + Rowv = NA, Colv = NA, main = "Response Options Similarity Matrix", + margins = c(10, 10)) +``` ## Generate a Crosswalk table diff --git a/harmony_r_example.html b/harmony_r_example.html index c43ec72..e0946a2 100644 --- a/harmony_r_example.html +++ b/harmony_r_example.html @@ -1800,17 +1800,20 @@

Harmony walkthrough - R library

Rowv = NA, Colv = NA, main = "Questions Similarity Matrix", margins = c(10, 10))

-

The first three entries in the similarity matrix for the response -options are:

-
match$response_options_similarity[[1]][c(1, 2, 3)]
-
## [[1]]
-## [1] 1
-## 
-## [[2]]
-## [1] 1
-## 
-## [[3]]
-## [1] 1
+

We can view the first few rows of the similarity matrix for the +response options.

+
head(match$response_options_similarity)
+
+ +
+

We can also plot a heat map of the response options similarity +matrix.

+
heatmap(as.matrix(match$response_options_similarity),
+        Rowv = NA, Colv = NA, main = "Response Options Similarity Matrix",
+        margins = c(10, 10))
+

Generate a Crosswalk table

We can generate a crosswalk table to match questions with a cosine @@ -1911,45 +1914,45 @@

Cluster the questions

print(paste(" ", match$questions[[id]]$question_text)) } } -
## [1] "Cluster 4: I was bothered by things that usually don’t bother me."
-## [1] "Keywords: unfriendly, dificuldade"
+
## [1] "Cluster 2: I was bothered by things that usually don’t bother me."
+## [1] "Keywords: ficar, could"
 ## [1] "     I was bothered by things that usually don’t bother me."
-## [1] "     I did not feel like eating; my appetite was poor."
 ## [1] "     I felt that I could not shake off the blues even with help from my family or friends."
 ## [1] "     I had trouble keeping my mind on what I was doing."
-## [1] "     I talked less than usual."
-## [1] "     People were unfriendly."
+## [1] "     I could not get “going.”"
+## [1] "     Sentir-se nervoso/a, ansioso/a ou muito tenso/a"
 ## [1] "     Não ser capaz de impedir ou de controlar as preocupações"
+## [1] "     Preocupar-se muito com diversas coisas"
 ## [1] "     Dificuldade para relaxar"
+## [1] "     Ficar tão agitado/a que se torna difícil permanecer sentado/a"
 ## [1] "     Ficar facilmente aborrecido/a ou irritado/a"
+## [1] "     Følt deg nervøs, engstelig eller veldig stresset"
 ## [1] "     Ikke klart å slutte å bekymre deg eller kontrolleren bekymringene dine"
-## [1] "Cluster 1: I felt I was just as good as other people."
-## [1] "Keywords: happy, enjoyed, future, hopeful"
+## [1] "Cluster 1: I did not feel like eating; my appetite was poor."
+## [1] "Keywords: unfriendly, talked, less"
+## [1] "     I did not feel like eating; my appetite was poor."
+## [1] "     I talked less than usual."
+## [1] "     People were unfriendly."
+## [1] "Cluster 5: I felt I was just as good as other people."
+## [1] "Keywords: effort, everything, good"
 ## [1] "     I felt I was just as good as other people."
-## [1] "     I felt hopeful about the future."
-## [1] "     I was happy."
-## [1] "     I enjoyed life."
-## [1] "Cluster 2: I felt depressed."
-## [1] "Keywords: depressed, lonely, sad, crying, spells"
+## [1] "     I felt that everything I did was an effort."
+## [1] "Cluster 3: I felt depressed."
+## [1] "Keywords: sad, depressed, lonely, fearful, felt"
 ## [1] "     I felt depressed."
 ## [1] "     I thought my life had been a failure."
+## [1] "     I felt fearful."
+## [1] "     My sleep was restless."
 ## [1] "     I felt lonely."
 ## [1] "     I had crying spells."
 ## [1] "     I felt sad."
 ## [1] "     I felt that people dislike me."
-## [1] "Cluster 3: I felt that everything I did was an effort."
-## [1] "Keywords: effort, everything"
-## [1] "     I felt that everything I did was an effort."
-## [1] "Cluster 5: I felt fearful."
-## [1] "Keywords: fearful, sentir, sleep"
-## [1] "     I felt fearful."
-## [1] "     My sleep was restless."
-## [1] "     I could not get “going.”"
-## [1] "     Sentir-se nervoso/a, ansioso/a ou muito tenso/a"
-## [1] "     Preocupar-se muito com diversas coisas"
-## [1] "     Ficar tão agitado/a que se torna difícil permanecer sentado/a"
 ## [1] "     Sentir medo como se algo horrível fosse acontecer"
-## [1] "     Følt deg nervøs, engstelig eller veldig stresset"
+## [1] "Cluster 4: I felt hopeful about the future." +## [1] "Keywords: happy, enjoyed, future, hopeful" +## [1] " I felt hopeful about the future." +## [1] " I was happy." +## [1] " I enjoyed life."

Display the similarities between instruments

From 71738c3503bc19e1ca682102117689d443bebcde Mon Sep 17 00:00:00 2001 From: AlexNikic Date: Fri, 2 Jan 2026 12:39:15 +0000 Subject: [PATCH 3/4] included warning for image compression for heatmap --- harmony_r_example.Rmd | 2 +- harmony_r_example.html | 51 ++++++++++++++++++++++-------------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/harmony_r_example.Rmd b/harmony_r_example.Rmd index 671e1c9..c347737 100644 --- a/harmony_r_example.Rmd +++ b/harmony_r_example.Rmd @@ -97,7 +97,7 @@ We can view the first few rows of the similarity matrix for the questions. head(match$matches) ``` -We can also plot a heat map of the questions similarity matrix. +We can also plot a heat map of the questions similarity matrix. Please bare in mind however that R will compress the matrix to fit the size of the plotting area, which may reduce the visible resolution for large matrices. ```{r} heatmap(as.matrix(match$matches), diff --git a/harmony_r_example.html b/harmony_r_example.html index e0946a2..08fdcb6 100644 --- a/harmony_r_example.html +++ b/harmony_r_example.html @@ -1795,7 +1795,10 @@

Harmony walkthrough - R library

{"columns":[{"label":[""],"name":["_rn_"],"type":[""],"align":["left"]},{"label":["1 I was bothered by things that usually don’t bother me."],"name":[1],"type":["dbl"],"align":["right"]},{"label":["2 I did not feel like eating; my appetite was poor."],"name":[2],"type":["dbl"],"align":["right"]},{"label":["3 I felt that I could not shake off the blues even with help from my family or friends."],"name":[3],"type":["dbl"],"align":["right"]},{"label":["4 I felt I was just as good as other people."],"name":[4],"type":["dbl"],"align":["right"]},{"label":["5 I had trouble keeping my mind on what I was doing."],"name":[5],"type":["dbl"],"align":["right"]},{"label":["6 I felt depressed."],"name":[6],"type":["dbl"],"align":["right"]},{"label":["7 I felt that everything I did was an effort."],"name":[7],"type":["dbl"],"align":["right"]},{"label":["8 I felt hopeful about the future."],"name":[8],"type":["dbl"],"align":["right"]},{"label":["9 I thought my life had been a failure."],"name":[9],"type":["dbl"],"align":["right"]},{"label":["10 I felt fearful."],"name":[10],"type":["dbl"],"align":["right"]},{"label":["11 My sleep was restless."],"name":[11],"type":["dbl"],"align":["right"]},{"label":["12 I was happy."],"name":[12],"type":["dbl"],"align":["right"]},{"label":["13 I talked less than usual."],"name":[13],"type":["dbl"],"align":["right"]},{"label":["14 I felt lonely."],"name":[14],"type":["dbl"],"align":["right"]},{"label":["15 People were unfriendly."],"name":[15],"type":["dbl"],"align":["right"]},{"label":["16 I enjoyed life."],"name":[16],"type":["dbl"],"align":["right"]},{"label":["17 I had crying spells."],"name":[17],"type":["dbl"],"align":["right"]},{"label":["18 I felt sad."],"name":[18],"type":["dbl"],"align":["right"]},{"label":["19 I felt that people dislike me."],"name":[19],"type":["dbl"],"align":["right"]},{"label":["20 I could not get “going.”"],"name":[20],"type":["dbl"],"align":["right"]},{"label":["1 Sentir-se nervoso/a, ansioso/a ou muito tenso/a"],"name":[21],"type":["dbl"],"align":["right"]},{"label":["2 Não ser capaz de impedir ou de controlar as preocupações"],"name":[22],"type":["dbl"],"align":["right"]},{"label":["3 Preocupar-se muito com diversas coisas"],"name":[23],"type":["dbl"],"align":["right"]},{"label":["4 Dificuldade para relaxar"],"name":[24],"type":["dbl"],"align":["right"]},{"label":["5 Ficar tão agitado/a que se torna difícil permanecer sentado/a"],"name":[25],"type":["dbl"],"align":["right"]},{"label":["6 Ficar facilmente aborrecido/a ou irritado/a"],"name":[26],"type":["dbl"],"align":["right"]},{"label":["7 Sentir medo como se algo horrível fosse acontecer"],"name":[27],"type":["dbl"],"align":["right"]},{"label":["1 Følt deg nervøs, engstelig eller veldig stresset"],"name":[28],"type":["dbl"],"align":["right"]},{"label":["2 Ikke klart å slutte å bekymre deg eller kontrolleren bekymringene dine"],"name":[29],"type":["dbl"],"align":["right"]}],"data":[{"1":"1.0000000","2":"0.3136500","3":"0.3432307","4":"-0.2608283","5":"0.4278881","6":"0.3405483","7":"-0.3074892","8":"-0.1844938","9":"-0.2591457","10":"0.3123279","11":"0.2805717","12":"-0.2810103","13":"0.4857708","14":"0.2721404","15":"-0.2800038","16":"-0.1989061","17":"0.2869449","18":"0.3109423","19":"0.3754597","20":"0.2882913","21":"0.3378802","22":"0.4429031","23":"0.4387079","24":"-0.26580209","25":"0.3878320","26":"0.5300115","27":"0.2584586","28":"0.3483438","29":"0.4759780","_rn_":"1 I was bothered by things that usually don’t bother me."},{"1":"0.3136500","2":"1.0000000","3":"0.3253127","4":"-0.3844967","5":"-0.3938281","6":"-0.4360754","7":"-0.4443424","8":"-0.2370180","9":"-0.4699656","10":"-0.3660821","11":"-0.3449357","12":"-0.2956176","13":"0.3629988","14":"0.3855065","15":"-0.2076230","16":"-0.3017449","17":"-0.4111851","18":"-0.4271794","19":"-0.3394136","20":"0.3795191","21":"-0.3170622","22":"0.1143586","23":"-0.1107869","24":"-0.19496467","25":"-0.2502767","26":"-0.1438234","27":"-0.2480338","28":"-0.2999410","29":"-0.1247651","_rn_":"2 I did not feel like eating; my appetite was poor."},{"1":"0.3432307","2":"0.3253127","3":"1.0000000","4":"-0.4572784","5":"0.3600379","6":"0.4461865","7":"-0.4240063","8":"-0.3070913","9":"-0.4090989","10":"0.3407558","11":"-0.2236730","12":"-0.3927100","13":"-0.2237019","14":"0.3298419","15":"-0.2240179","16":"-0.2790295","17":"-0.4055312","18":"0.3980323","19":"0.3333253","20":"0.5022725","21":"-0.2473898","22":"0.3689574","23":"-0.2246580","24":"-0.30274118","25":"0.2995582","26":"-0.2420086","27":"-0.3136669","28":"-0.2620691","29":"0.3011257","_rn_":"3 I felt that I could not shake off the blues even with help from my family or friends."},{"1":"-0.2608283","2":"-0.3844967","3":"-0.4572784","4":"1.0000000","5":"-0.4569577","6":"-0.4227796","7":"0.3870321","8":"0.3036616","9":"-0.5226836","10":"-0.3991098","11":"-0.2377619","12":"0.5163324","13":"-0.3410804","14":"-0.3767204","15":"-0.3634026","16":"0.4320105","17":"-0.3503849","18":"-0.4186762","19":"-0.4891295","20":"-0.3347450","21":"-0.2370714","22":"-0.1197432","23":"-0.1870206","24":"-0.08848838","25":"-0.2003901","26":"-0.1840171","27":"-0.2976140","28":"-0.2145504","29":"-0.1502534","_rn_":"4 I felt I was just as good as other people."},{"1":"0.4278881","2":"-0.3938281","3":"0.3600379","4":"-0.4569577","5":"1.0000000","6":"0.4661298","7":"0.4215717","8":"-0.3835386","9":"0.4345674","10":"0.4801742","11":"0.4149681","12":"-0.4282185","13":"0.3995716","14":"0.3118243","15":"0.1871167","16":"-0.3302681","17":"0.3876780","18":"0.4053666","19":"0.3504265","20":"0.5536180","21":"0.3233571","22":"0.3584794","23":"0.3913057","24":"-0.28819365","25":"0.3857854","26":"0.2309111","27":"0.3112746","28":"0.3266130","29":"0.4051712","_rn_":"5 I had trouble keeping my mind on what I was doing."},{"1":"0.3405483","2":"-0.4360754","3":"0.4461865","4":"-0.4227796","5":"0.4661298","6":"1.0000000","7":"0.3766690","8":"0.3778587","9":"0.6105928","10":"0.6234880","11":"0.3890580","12":"-0.5056132","13":"0.3023000","14":"0.6345771","15":"0.1413898","16":"-0.3053482","17":"0.7211359","18":"0.8496906","19":"0.4866536","20":"0.4031319","21":"0.5902460","22":"0.1959993","23":"0.3799167","24":"0.34379200","25":"0.5652907","26":"0.3365583","27":"0.5824768","28":"0.5735959","29":"0.3399480","_rn_":"6 I felt depressed."}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
-

We can also plot a heat map of the questions similarity matrix.

+

We can also plot a heat map of the questions similarity matrix. +Please bare in mind however that R will compress the matrix to fit the +size of the plotting area, which may reduce the visible resolution for +large matrices.

heatmap(as.matrix(match$matches), 
         Rowv = NA, Colv = NA, main = "Questions Similarity Matrix",
         margins = c(10, 10))
@@ -1914,45 +1917,45 @@

Cluster the questions

print(paste(" ", match$questions[[id]]$question_text)) } } -
## [1] "Cluster 2: I was bothered by things that usually don’t bother me."
-## [1] "Keywords: ficar, could"
+
## [1] "Cluster 3: I was bothered by things that usually don’t bother me."
+## [1] "Keywords: unfriendly, talked"
 ## [1] "     I was bothered by things that usually don’t bother me."
-## [1] "     I felt that I could not shake off the blues even with help from my family or friends."
 ## [1] "     I had trouble keeping my mind on what I was doing."
-## [1] "     I could not get “going.”"
-## [1] "     Sentir-se nervoso/a, ansioso/a ou muito tenso/a"
+## [1] "     I talked less than usual."
+## [1] "     People were unfriendly."
 ## [1] "     Não ser capaz de impedir ou de controlar as preocupações"
 ## [1] "     Preocupar-se muito com diversas coisas"
+## [1] "     Ikke klart å slutte å bekymre deg eller kontrolleren bekymringene dine"
+## [1] "Cluster 2: I did not feel like eating; my appetite was poor."
+## [1] "Keywords: ficar, dificuldade, relaxar, facilmente"
+## [1] "     I did not feel like eating; my appetite was poor."
+## [1] "     Sentir-se nervoso/a, ansioso/a ou muito tenso/a"
 ## [1] "     Dificuldade para relaxar"
 ## [1] "     Ficar tão agitado/a que se torna difícil permanecer sentado/a"
 ## [1] "     Ficar facilmente aborrecido/a ou irritado/a"
 ## [1] "     Følt deg nervøs, engstelig eller veldig stresset"
-## [1] "     Ikke klart å slutte å bekymre deg eller kontrolleren bekymringene dine"
-## [1] "Cluster 1: I did not feel like eating; my appetite was poor."
-## [1] "Keywords: unfriendly, talked, less"
-## [1] "     I did not feel like eating; my appetite was poor."
-## [1] "     I talked less than usual."
-## [1] "     People were unfriendly."
-## [1] "Cluster 5: I felt I was just as good as other people."
-## [1] "Keywords: effort, everything, good"
+## [1] "Cluster 1: I felt that I could not shake off the blues even with help from my family or friends."
+## [1] "Keywords: happy, enjoyed, life, future"
+## [1] "     I felt that I could not shake off the blues even with help from my family or friends."
 ## [1] "     I felt I was just as good as other people."
 ## [1] "     I felt that everything I did was an effort."
-## [1] "Cluster 3: I felt depressed."
-## [1] "Keywords: sad, depressed, lonely, fearful, felt"
+## [1] "     I felt hopeful about the future."
+## [1] "     I was happy."
+## [1] "     I enjoyed life."
+## [1] "Cluster 4: I felt depressed."
+## [1] "Keywords: sad, depressed, crying, spells"
 ## [1] "     I felt depressed."
 ## [1] "     I thought my life had been a failure."
+## [1] "     I had crying spells."
+## [1] "     I felt sad."
+## [1] "Cluster 5: I felt fearful."
+## [1] "Keywords: fearful, lonely, sleep, restless, dislike"
 ## [1] "     I felt fearful."
 ## [1] "     My sleep was restless."
 ## [1] "     I felt lonely."
-## [1] "     I had crying spells."
-## [1] "     I felt sad."
 ## [1] "     I felt that people dislike me."
-## [1] "     Sentir medo como se algo horrível fosse acontecer"
-## [1] "Cluster 4: I felt hopeful about the future."
-## [1] "Keywords: happy, enjoyed, future, hopeful"
-## [1] "     I felt hopeful about the future."
-## [1] "     I was happy."
-## [1] "     I enjoyed life."
+## [1] " I could not get “going.”" +## [1] " Sentir medo como se algo horrível fosse acontecer"

Display the similarities between instruments

From 808052bd6d5aecce2e929512c157302f294e72cb Mon Sep 17 00:00:00 2001 From: AlexNikic Date: Fri, 2 Jan 2026 12:47:08 +0000 Subject: [PATCH 4/4] added check for empty response options matrix to ensure tests pass --- R/match_instruments.R | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/R/match_instruments.R b/R/match_instruments.R index 032980e..5006dd5 100644 --- a/R/match_instruments.R +++ b/R/match_instruments.R @@ -164,13 +164,15 @@ match_instruments <- function(instruments, conten$matches <- df # here we will also convert the response options similarity matrix to a data frame - df_response_options <- data.frame(conten$response_options_similarity[[1]]) - for (x in seq_along(conten$response_options_similarity)) { - df_response_options[x, ] <- conten$response_options_similarity[[x]] + if (length(conten$response_options_similarity) > 0) { + df_response_options <- data.frame(conten$response_options_similarity[[1]]) + for (x in seq_along(conten$response_options_similarity)) { + df_response_options[x, ] <- conten$response_options_similarity[[x]] + } + colnames(df_response_options) <- lapply(conten$questions, function(x) paste(x$question_no, x$question_text, sep = " "))[seq_len(ncol(df_response_options))] # we add the [seq_len()] to account for the case when there are empty response options + rownames(df_response_options) <- lapply(conten$questions, function(x) paste(x$question_no, x$question_text, sep = " "))[seq_len(nrow(df_response_options))] + conten$response_options_similarity <- df_response_options } - colnames(df_response_options) <- lapply(conten$questions, function(x) paste(x$question_no, x$question_text, sep = " "))[seq_len(ncol(df_response_options))] # we add the [seq_len()] to account for the case when there are empty response options - rownames(df_response_options) <- lapply(conten$questions, function(x) paste(x$question_no, x$question_text, sep = " "))[seq_len(nrow(df_response_options))] - conten$response_options_similarity <- df_response_options return(conten) }