knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) options(rmarkdown.html_vignette.check_title = FALSE) frag_path <- here::here("man", "fragments", "gds") paths <- list.files(frag_path, "Rmd", full.names = TRUE) names(paths) <- gsub("\\.Rmd", "", basename(paths)) paths <- as.list(paths)
library(questionnaires) gds_values(yes = 1, no = 0) gds_values(yes = "yes", no = "no") gds_values(yes = "ja", no = "nei")
gds
functionslibrary(dplyr) library(tidyr) # randomly create some data as example gds_data <- expand_grid(ID = 1:5, key = "gds", question = sprintf("%02d", 1:30)) gds_data <- gds_data %>% mutate(value = sample(c(0,1), nrow(gds_data), replace = TRUE)) %>% unite(key, c(key, question)) %>% spread(key, value) gds_data
The function to calculate the total GDS score is gds_compute_sum
, and requires a data frame, a tidy-selector that selects all the GDS columns and a tidy-selector indicating which columns should be reversed.
If you have NOAS-like data, then the defaults should work, and as such you need not specify this.
gds_data %>% gds_compute_sum()
To add a column with total GDS to a data set, place the argument inside a mutate
, here a column named gds_total
will appear as the right-most column.
gds_data %>% mutate( gds_total = gds_compute_sum(gds_data) )
Most often, people will report not only the actual score, but also the accompanying depression classification based on that score.
This can be derived by using the gds_factorise
function.
gds_data %>% gds_compute_sum() %>% gds_factorise()
and this can also be added directly to the data through a `mutate``
gds_data %>% mutate( gds_total = gds_compute_sum(gds_data), gds_cat = gds_factorise(gds_total) )
Lastly, since it is most common to want both the score and the factor added directly do data, a convenience function exists to assist in that.
gds_data %>% gds_compute()
alternatively, you can also keep_all = FALSE
in that function, to only retain the two computed columns, while maintaining the remaining data structure.
gds_data %>% gds_compute(keep_all = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.