--- title: "Geriatric Depression Scale" subtitle: "Original version: Yesavage J A, 1983 - Norwegian version: Knut Engedal" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{gds} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} 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) ``` ## Background ```{r child=paths$background, eval = TRUE} ``` ## Scoring ```{r child=paths$scoring, eval = TRUE} ``` ## Data requirements ```{r child=paths$datareq, eval = TRUE} ``` ```{r} library(questionnaires) gds_values(yes = 1, no = 0) gds_values(yes = "yes", no = "no") gds_values(yes = "ja", no = "nei") ``` ## Using the `gds` functions ```{r} library(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 ``` ### Calculating the GDS sum 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. ```{r} 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. ```{r} gds_data %>% mutate( gds_total = gds_compute_sum(gds_data) ) ``` ### Turning the sum into a factor 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. ```{r} gds_data %>% gds_compute_sum() %>% gds_factorise() ``` and this can also be added directly to the data through a `mutate`` ```{r} gds_data %>% mutate( gds_total = gds_compute_sum(gds_data), gds_cat = gds_factorise(gds_total) ) ``` ### Computing score and factor in one function 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. ```{r} 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. ```{r} gds_data %>% gds_compute(keep_all = FALSE) ``` ## References ```{r child=paths$references, eval = TRUE} ```