Coder Social home page Coder Social logo

mctq's Introduction

mctq

Status at rOpenSci Software Peer Review Repo status CRAN status CRAN DOI CRAN downloads R-universe Lifecycle: maturing R-CMD-check Codecov test coverage License: MIT fair-software.eu CII Best Practices

Overview

mctq is an R package that provides a complete toolkit to process the Munich ChronoType Questionnaire (MCTQ), a quantitative and validated tool to assess chronotypes using individuals’ sleep behavior, as presented by Till Roenneberg, Anna Wirz-Justice, and Martha Merrow in 2003. Its aim is to facilitate the work of sleep and chronobiology scientists with MCTQ data and improve reproducibility in research.

mctq adheres to the tidyverse principles and integrates with the tidyverse ecosystem.

Learn more about the MCTQ questionnaire at https://www.thewep.org/documentations/mctq.

Why an R package for a questionnaire?

Although it may seem like a simple questionnaire, MCTQ requires extensive date/time manipulation, which poses challenges for many scientists. The mctq package addresses this issue by providing tools to handle the processing tasks for the three MCTQ versions (standard, micro, and shift) with few dependencies, relying mainly on the lubridate and hms packages from tidyverse.

We designed mctq with user experience in mind, creating an interface that resembles the questionnaire data as shown in MCTQ publications and providing extensive documentation about each computation proposed by the MCTQ authors. The package also includes fictional datasets for testing and learning purposes.

Prerequisites

You need some familiarity with the R programming language and the lubridate and hms packages from tidyverse to use mctq’s main functions.

If you are new to R, we recommend Hadley Wickham and Garrett Grolemund’s free online book R for Data Science and the Coursera course from Johns Hopkins University Data Science: Foundations using R (free for audit students).

Please refer to the lubridate and hms documentation to learn more about handling date/time data in R. We also recommend reading the Dates and times chapter from Wickham & Grolemund’s book R for Data Science.

Installation

You can install the released version of mctq from CRAN with:

install.packages("mctq")

And the development version from GitHub with:

# install.packages("remotes")
remotes::install_github("ropensci/mctq")

Usage

mctq uses the lubridate and hms packages, which provide special objects to handle date/time values in R. Ensure your dataset conforms to this structure before using mctq. Refer to the respective package documentation for more details.

Because of the circular nature of time, using appropriate temporal objects is crucial to avoid computation mistakes while adapting data from a base 10 to a base 12 numerical system.

For detailed usage instructions, visit our Get started guide.

Workdays and work-free days variables

After preparing your data, use the following mctq functions to process it. The function names follow the patterns used in MCTQ publications, making it easy to apply the necessary computations:

  • fd(): compute MCTQ work-free days.
  • so(): compute MCTQ local time of sleep onset.
  • gu(): compute MCTQ local time of getting out of bed.
  • sdu(): compute MCTQ sleep duration.
  • tbt(): compute MCTQ total time in bed.
  • msl(): compute MCTQ local time of mid-sleep.
  • napd(): compute MCTQ nap duration (only for MCTQ Shift).
  • sd24(): compute MCTQ 24 hours sleep duration (only for MCTQ Shift).

Example:

# Local time of preparing to sleep on workdays
sprep_w <- c(hms::parse_hm("23:45"), hms::parse_hm("02:15"))
# Sleep latency or time to fall asleep after preparing to sleep on workdays
slat_w <- c(lubridate::dminutes(30), lubridate::dminutes(90))
# Local time of sleep onset on workdays
so(sprep_w, slat_w)
#> 00:15:00
#> 03:45:00

Combining workdays and work-free days variables

For computations combining workdays and work-free days, use:

  • sd_week(): compute MCTQ average weekly sleep duration.
  • sd_overall(): compute MCTQ overall sleep duration (only for MCTQ Shift).
  • sloss_week(): compute MCTQ weekly sleep loss.
  • le_week(): compute MCTQ average weekly light exposure.
  • msf_sc(): compute MCTQ chronotype or sleep-corrected local time of mid-sleep on work-free days.
  • sjl() and sjl_rel(): compute MCTQ social jet lag.
  • sjl_sc() and sjl_sc_rel(): compute Jankowski’s MCTQ sleep-corrected social jetlag.
  • sjl_weighted(): compute MCTQ absolute social jetlag across all shifts (only for MCTQ Shift).

Example:

# Local time of mid-sleep on workdays
msw <- c(hms::parse_hm("02:05"), hms::parse_hm("04:05"))
# Local time of mid-sleep on work-free days
msf <- c(hms::parse_hm("23:05"), hms::parse_hm("08:30"))
# Relative social jetlag
sjl_rel(msw, msf)
#> [1] "-10800s (~-3 hours)"  "15900s (~4.42 hours)"

Utilities

mctq includes utility tools to help with your MCTQ data and provides fictional datasets for the standard, micro, and shift MCTQ versions for testing and learning purposes.

All functions are documented with guidelines behind the computations. Click here to see the full list.

Citation

If you use mctq in your research, please consider citing it. We put significant effort into building and maintaining this free and open-source R package. Find the citation below.

citation("mctq")
#> To cite {mctq} in publications use:
#> 
#>   Vartanian, D. (2024). {mctq}: Munich ChronoType Questionnaire tools
#>   (Version 0.3.2.9001) [Computer software - R package]. CRAN; rOpenSci.
#>   https://doi.org/10.32614/CRAN.package.mctq
#> 
#> A BibTeX entry for LaTeX users is
#> 
#>   @Misc{,
#>     title = {{mctq}: Munich ChronoType Questionnaire tools},
#>     author = {Daniel Vartanian},
#>     year = {2024},
#>     publisher = {CRAN; rOpenSci},
#>     doi = {10.32614/CRAN.package.mctq},
#>     note = {R package version 0.3.2.9001},
#>   }

Contributing

We welcome contributions, including bug reports. Take a moment to review our Guidelines for Contributing.

Acknowledgments

The initial development of mctq was supported by a scholarship from the University of Sao Paulo (USP) (❤️).

The mctq hex logo is based on an illustration by hilda design matters Zurich for the Daylight Academy (DLA).


Become an mctq supporter!

Click here to make a donation. Please indicate the mctq package in your donation message.

mctq's People

Contributors

danielvartan avatar jonkeane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

jonkeane

mctq's Issues

Installation error with pak

Hi there,

I've tried to install the mctq package following the instructions. I get the following error message when running the suggested command pak::pkg_install("gipsousp/mctq"):

Error: callr subprocess failed: Invalid parent_resolve callback

Details here:

pak error
> pak::pkg_install("gipsousp/mctq")

`pak` will create its private package library in
`/Users/spitschan/Library/Caches/R-pkg/lib/4.0`. 
It will try to copy packages from your regular library
See `?pak_setup()` for alternatives.

Do you want to continue (Y/n)? Y

Creating private lib in `/Users/spitschan/Library/Caches/R-pkg/lib/4.0`...
Copying package `assertthat`
Copying package `base64enc`
Copying package `callr`
Copying package `cli`
Copying package `cliapp`
Copying package `crayon`
Copying package `curl`
Copying package `desc`
Copying package `filelock`
Copying package `glue`
Copying package `jsonlite`
Copying package `lpSolve`
Copying package `pkgbuild`
Copying package `pkgcache`
Copying package `prettyunits`
Copying package `processx`
Copying package `ps`
Copying package `R6`
Copying package `rematch2`
Copying package `rprojroot`
Copying package `tibble`
Copying package `fansi`
Copying package `prettycode`
Copying package `progress`
Copying package `selectr`
Copying package `withr`
Copying package `xml2`
Copying package `digest`
Copying package `rappdirs`
Copying package `rlang`
Copying package `uuid`
Copying package `ellipsis`
Copying package `lifecycle`
Copying package `magrittr`
Copying package `pillar`
Copying package `pkgconfig`
Copying package `vctrs`
Copying package `hms`
Copying package `stringr`
Copying package `utf8`
Copying package `stringi`

Created private lib in `/Users/spitschan/Library/Caches/R-pkg/lib/4.0`...
Error: callr subprocess failed: Invalid parent_resolve callback

I'm not sure if this error relates to pak or not. devtools::install_github("gipsousp/mctq") runs perfectly.

Here is my session summary:

Session info
> devtools::session_info() 
─ Session info ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 4.0.3 (2020-10-10)
 os       macOS Catalina 10.15.7      
 system   x86_64, darwin17.0          
 ui       RStudio                     
 language (EN)                        
 collate  en_GB.UTF-8                 
 ctype    en_GB.UTF-8                 
 tz       Europe/Zurich               
 date     2021-07-19Packages ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 ! package     * version date       lib source        
   cachem        1.0.4   2021-02-13 [1] CRAN (R 4.0.2)
   callr         3.7.0   2021-04-20 [1] CRAN (R 4.0.2)
 V cli           2.5.0   2021-07-17 [1] CRAN (R 4.0.2)
   crayon        1.4.1   2021-02-08 [1] CRAN (R 4.0.2)
   curl          4.3.1   2021-04-30 [1] CRAN (R 4.0.2)
   desc          1.3.0   2021-03-05 [1] CRAN (R 4.0.2)
   devtools      2.4.1   2021-05-05 [1] CRAN (R 4.0.3)
   digest        0.6.27  2020-10-24 [1] CRAN (R 4.0.2)
   ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.0.2)
   evaluate      0.14    2019-05-28 [1] CRAN (R 4.0.0)
   fastmap       1.1.0   2021-01-25 [1] CRAN (R 4.0.2)
   filelock      1.0.2   2018-10-05 [1] CRAN (R 4.0.2)
   forcats       0.5.1   2021-01-27 [1] CRAN (R 4.0.2)
   fs            1.5.0   2020-07-31 [1] CRAN (R 4.0.2)
   glue          1.4.2   2020-08-27 [1] CRAN (R 4.0.2)
   htmltools     0.5.1.1 2021-01-22 [1] CRAN (R 4.0.2)
   knitr         1.33    2021-04-24 [1] CRAN (R 4.0.2)
   lifecycle     1.0.0   2021-02-15 [1] CRAN (R 4.0.2)
   magrittr      2.0.1   2020-11-17 [1] CRAN (R 4.0.2)
   memoise       2.0.0   2021-01-26 [1] CRAN (R 4.0.2)
   pak           0.1.2.1 2020-11-19 [1] CRAN (R 4.0.2)
   pkgbuild      1.2.0   2020-12-15 [1] CRAN (R 4.0.3)
   pkgload       1.2.1   2021-04-06 [1] CRAN (R 4.0.2)
   prettyunits   1.1.1   2020-01-24 [1] CRAN (R 4.0.0)
   processx      3.5.2   2021-04-30 [1] CRAN (R 4.0.2)
   ps            1.6.0   2021-02-28 [1] CRAN (R 4.0.2)
   purrr         0.3.4   2020-04-17 [1] CRAN (R 4.0.0)
   R6            2.5.0   2020-10-28 [1] CRAN (R 4.0.2)
   remotes       2.3.0   2021-04-01 [1] CRAN (R 4.0.2)
   rlang         0.4.11  2021-04-30 [1] CRAN (R 4.0.2)
   rmarkdown     2.8     2021-05-07 [1] CRAN (R 4.0.3)
   rprojroot     2.0.2   2020-11-15 [1] CRAN (R 4.0.2)
   rstudioapi    0.13    2020-11-12 [1] CRAN (R 4.0.2)
   sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.0.0)
   testthat      3.0.2   2021-02-14 [1] CRAN (R 4.0.2)
   usethis       2.0.1   2021-02-10 [1] CRAN (R 4.0.2)
   withr         2.4.2   2021-04-18 [1] CRAN (R 4.0.2)
   xfun          0.23    2021-05-15 [1] CRAN (R 4.0.2)
   yaml          2.2.1   2020-02-01 [1] CRAN (R 4.0.0)

[1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library

 V ── Loaded and on-disk version mismatch.

Try to integrate `checkmate` with `cli`

Comments in English, Spanish, or Portuguese are welcome.
Comentarios en inglés, español o portugués son bienvenidos.
Comentários em inglês, espanhol ou português são bem-vindos.

  • Due date: TBD.

Instructions

  • mctq now uses the cli package for the command line interface. But checkmate is still widely used for standard checks. Maybe there's a way to integrate the two.

Add a validation function for MCTQ data

Comments in English, Spanish, or Portuguese are welcome.
Comentarios en inglés, español o portugués son bienvenidos.
Comentários em inglês, espanhol ou português são bem-vindos.

  • Due date: TBD.

Instructions

  • Add a validation function called validate_mctq().
  • Use the validate package.
  • Create and export the set of rules.

Write a vignette explaining the utility functions

Comments in English, Spanish, or Portuguese are welcome.
Comentarios en inglés, español o portugués son bienvenidos.
Comentários em inglês, espanhol ou português são bem-vindos.

  • Due date: TBD.

Review CONTRIBUTING.md and add road map

Comments in English, Spanish, or Portuguese are welcome.
Comentarios en inglés, español o portugués son bienvenidos.
Comentários em inglês, espanhol ou português são bem-vindos.

  • Due date: TBD.

issue with installing mctq via pak (resolved)

Hi Daniel,
Just saw your poster and tried to install mctq. When doing so with the normal version of pak it failed. However if i installed the devel version it works! Thought it might be useful to post this here in case someone came across the same problem.

so instead of:
install.packages("pak")

I did:

install.packages("pak", repos = "https://r-lib.github.io/p/pak/dev/")
pak::pkg_install("gipso/mctq")
> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252    LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] mctq_0.0.0.9001

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7       magrittr_2.0.1   hms_1.1.1        tidyselect_1.1.1 R6_2.5.0         rlang_0.4.11     fansi_0.5.0      dplyr_1.0.7      tools_4.1.0      pak_0.1.2.9001  
[11] utf8_1.2.2       cli_2.5.0        DBI_1.1.1        ellipsis_0.3.2   assertthat_0.2.1 tibble_3.1.5     lifecycle_1.0.1  crayon_1.4.1     processx_3.5.2   purrr_0.3.4     
[21] callr_3.7.0      vctrs_0.3.8      ps_1.6.0         glue_1.4.2       compiler_4.1.0   pillar_1.6.3     generics_0.1.0   lubridate_1.7.10 pkgconfig_2.0.3 

All the best with the project!

Redesign `mctq` Hex logo

Comments in English, Spanish, or Portuguese are welcome.
Comentarios en inglés, español o portugués son bienvenidos.
Comentários em inglês, espanhol ou português são bem-vindos.

  • Due date: TBD.

Submit `mctq` to rOpenSci

Comments in English, Spanish, or Portuguese are welcome.
Comentarios en inglés, español o portugués son bienvenidos.
Comentários em inglês, espanhol ou português são bem-vindos.

  • Due date: TBD.

Submit `mctq` to CRAN

Comments in English, Spanish, or Portuguese are welcome.
Comentarios en inglés, español o portugués son bienvenidos.
Comentários em inglês, espanhol ou português são bem-vindos.

  • Due date: TBD.

Add `lintr` to Github Actions

Comments in English, Spanish, or Portuguese are welcome.
Comentarios en inglés, español o portugués son bienvenidos.
Comentários em inglês, espanhol ou português são bem-vindos.

  • Due date: TBD.

Instructions

  • "lintr is an R package offering static code analysis for R. It checks adherence to a given style, syntax errors and possible semantic issues". Add it to mctq workflows`.
  • Follow this guideline to implement this feature.

Write an article about `mctq`

Comments in English, Spanish, or Portuguese are welcome.
Comentarios en inglés, español o portugués son bienvenidos.
Comentários em inglês, espanhol ou português são bem-vindos.

  • Due date: TBD.

Instructions

  • Explore and choose a journal for publishing (e.g., Journal of Sleep Research, Chronobiology International)
  • Draft a mctq article using the journal guidelines.
  • Contact the main MCTQ authors (e.g., Roenneberg , Merrow, Juda, Gotbi) and invite them to author the article and the package.
  • Don't forget to change the CITATION file after the article is published.

Move MCTQ cases from `std_mctq`, `micro_mctq`, and `shift_mctq` to a Google Sheets

Comments in English, Spanish, or Portuguese are welcome.
Comentarios en inglés, español o portugués son bienvenidos.
Comentários em inglês, espanhol ou português são bem-vindos.

  • Due date: TBD.

Instructions

  • The common MCTQ cases used in std_mctq, micro_mctq, and shift_mctq are build in the data-raw code. Move them to a public Google Sheets.
  • Use the googlesheets4 package to retrieve the cases.

Add msf_sc_plot()

Comments in English, Spanish, or Portuguese are welcome.
Comentarios en inglés, español o portugués son bienvenidos.
Comentários em inglês, espanhol ou português são bem-vindos.

  • Due date: TBD.

Instructions

  • Add a msf_sc_plot() function that plots the distribution of chronotypes using different methods to categorize them.

Release mctq 0.2.0

Prepare for release:

  • Check current CRAN check results
  • Polish NEWS
  • devtools::build_readme()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • revdepcheck::revdep_check(num_workers = 4)
  • Check Github Actions
  • Update cran-comments.md
  • Review pkgdown reference index for, e.g., missing topics

Submit to CRAN:

  • usethis::use_version('minor')
  • devtools::release()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • Tweet

Add analytical functions

Comments in English, Spanish, or Portuguese are welcome.
Comentarios en inglés, español o portugués son bienvenidos.
Comentários em inglês, espanhol ou português são bem-vindos.

  • Due date: TBD.

Instructions

  • Add functions that automate common analysis of MCTQ data.
  • Use the analysis showed in the MCTQ articles for reference.

Change the test suite to `testthat` 3rd ed.

Comments in English, Spanish, or Portuguese are welcome.
Comentarios en inglés, español o portugués son bienvenidos.
Comentários em inglês, espanhol ou português são bem-vindos.

  • Due date: TBD.

Instructions

  • Adapt the test suit to testthat 3rd edition.
  • At the moment the mctq package uses the 2nd edition of the testthat package.

Move utility functions to a new package called `lubritime`

Comments in English, Spanish, or Portuguese are welcome.
Comentarios en inglés, español o portugués son bienvenidos.
Comentários em inglês, espanhol ou português são bem-vindos.

  • Due date: TBD.

Instructions

  • mctq utility functions may be the subject of a new package called lubritime. Create this new package and start adding those features.
  • Don't forget to adapt the old convert() to this package.

Add links to class constructors in the documentation

Comments in English, Spanish, or Portuguese are welcome.
Comentarios en inglés, español o portugués son bienvenidos.
Comentários em inglês, espanhol ou português são bem-vindos.

  • Due date: TBD.

Instructions

  • Add links to class constructors while referring to object classes in the documentation.

Example

#' @param so A [`hms`][hms::hms()] object corresponding to the __local time of sleep onset__
#'   from a standard, micro, or shift version of the MCTQ questionnaire. You can
#'   use [mctq::so()] to compute it for the standard or shift version.
#' @param se A [`hms`][[hms::hms()]] object corresponding to the __local time of sleep end__
#'   from a standard, micro, or shift version of the MCTQ questionnaire.
#'
#' @return A [`Duration`][lubridate::duration()] object corresponding to the vectorized difference
#'   between `se` and `so` in a circular time frame of 24 hours.

Add Jankowski's approach to compute the social jet lag

Comments in English, Spanish, or Portuguese are welcome.
Comentarios en inglés, español o portugués son bienvenidos.
Comentários em inglês, espanhol ou português são bem-vindos.

  • Due date: TBD.

Instructions

  • Add a function called slj_sc with the Jankowski's proposal for computing the social jetlag (SJLsc = |sleep onset on free days - sleep onset on workdays|).
  • mctq package currently doesn't provide a function for the Jankowski's (2017) proposal since his alternative is still disputed (see Roenneberg, Pilz, Zerbini, & Winnebeck, 2019.).

Materials

  • Jankowski, K. S. (2017). Social jet lag: Sleep-corrected formula. Chronobiology international, 34(4), 531-535. doi: 10.1080/07420528.2017.1299162.
  • Roenneberg, T., Pilz, L. K., Zerbini, G., & Winnebeck, E. C. (2019). Chronotype and social jetlag: a (self-) critical review. Biology, 8(3). doi: 10.3390/biology8030054.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.