Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion R/match_instruments.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand All @@ -163,5 +163,16 @@ 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
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
}

return(conten)
}
14 changes: 10 additions & 4 deletions harmony_r_example.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,27 @@ 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),
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:
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

Expand Down
70 changes: 38 additions & 32 deletions harmony_r_example.html

Large diffs are not rendered by default.