{"id":22966624,"url":"https://github.com/favstats/openmindr","last_synced_at":"2025-07-09T03:11:25.371Z","repository":{"id":108351331,"uuid":"173525178","full_name":"favstats/openmindR","owner":"favstats","description":"This is a helper package for the work at OpenMind","archived":false,"fork":false,"pushed_at":"2019-04-30T09:28:51.000Z","size":211,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-02T05:12:16.731Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/favstats.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-03T03:11:43.000Z","updated_at":"2019-05-24T18:57:47.000Z","dependencies_parsed_at":"2023-04-18T19:47:46.477Z","dependency_job_id":null,"html_url":"https://github.com/favstats/openmindR","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/favstats/openmindR","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/favstats%2FopenmindR","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/favstats%2FopenmindR/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/favstats%2FopenmindR/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/favstats%2FopenmindR/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/favstats","download_url":"https://codeload.github.com/favstats/openmindR/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/favstats%2FopenmindR/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264384389,"owners_count":23599612,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-14T20:44:52.952Z","updated_at":"2025-07-09T03:11:25.366Z","avatar_url":"https://github.com/favstats.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\ntitle: \"openmindR\"\noutput: github_document\n---\n\nInstall package like this:\n\n```{r setup, eval=FALSE}\ndevtools::install_github(\"favstats/openmindR\")\n```\n\n```{r, echo=F}\nknitr::opts_chunk$set(message = F, \n                      warning = F)\n\n```\n\n\nLoad package(s):\n\n```{r}\nlibrary(openmindR)\nlibrary(tidyverse)\n```\n\n\n\n## OpenMind Cleaning Functions\n\n```{r, echo = F}\nlibrary(DBI)\nlibrary(magrittr)\nlibrary(glue)\nlibrary(lubridate)\n\ndb_get_data \u003c- function(tbl_dat) {\n  con \u003c- dbConnect(RSQLite::SQLite(), \"../om_metrics_report/sql_data/omdata.db\")\n\n  out \u003c- con %\u003e%\n    tbl(tbl_dat) %\u003e%\n    collect()\n\n  dbDisconnect(con)\n\n  return(out)\n}\n\n\n## Matching string for all Q variables\nq_strings \u003c- paste0(\n  paste0(\"Q\", 1:18, \"P\", collapse = \"|\"), \"|\", paste0(\"Q\", 1:18, \"F\", collapse = \"|\")\n  )\n## Matching string for all (relevant) D variables\nd_strings \u003c- paste0(\"D\", 1, collapse = \"|\")\n## Matching string for all C variables\nc_strings \u003c- paste0(\"C\", 1:3, collapse = \"|\")\n\n## Matching string for all (relevant) D, Q and C variables\nvar_strings \u003c- paste0(q_strings, \"|\", d_strings, \"|\", c_strings, collapse = \"|\")\n## Matching string for all Q and C variables\nq_c_strings \u003c- paste0(q_strings, \"|\", c_strings, collapse = \"|\")\n## Matching string for ranging vars from 0 to 1 \nrange01_strings \u003c- str_c(str_c(\"Q\", 3:12, \"P\", collapse = \"|\"), \"|\",\n                         str_c(\"Q\", 3:12, \"F\", collapse = \"|\"), \n                         str_c(\"|\", c_strings, collapse = \"|\")\n)\n\n\n# Read in data\ndat.acc \u003c- db_get_data(\"dat.acc\")\ndat.par \u003c- db_get_data(\"dat.par\")\ndat.ass4 \u003c- db_get_data(\"dat.ass4\")\ndat.ass5 \u003c- db_get_data(\"dat.ass5\")\n\ndat.ass \u003c- dat.ass4 %\u003e% \n  rename_at(vars(matches(\"Followup\")), ~str_replace(., \"Followup\", \"FollowUp\")) %\u003e%\n  bind_rows(dat.ass5)\n\n\n```\n\n\n## `om_filter_data`\n\nFilter down Assessment data from AirTable by `AssessmentsDone`, `AssessmentVersion` and `AccessCodes`.\n\n```{r}\n\ndat.ass %\u003e% \n  # specify which number of assessment you want to have\n  om_filter_data(n_assessments = 1:3,\n             # assessment version?\n             version = 4,\n             # select Accesscode(s) to produce report for\n             accesscode = \"Wilkes\"\n             # \"Wilkes\" #try this out :)\n  )\n```\n\nThis dataset was filtered down to only AccessCodes that include \"Wilkes\". The `accesscode` argument is not case-sensitive and can both be used with vectors:\n\n```{r}\ndat.ass %\u003e% \n  # specify which number of assessment you want to have\n  om_filter_data(n_assessments = 1:3,\n             # assessment version?\n             version = 4,\n             # select Accesscode(s) to produce report for\n             accesscode = c(\"SuszkoWilkesUF18\", \"KarimiWilkesUF18\")\n  )\n```\n\nAnd individual strings:\n\n```{r}\ndat.ass %\u003e% \n  # specify which number of assessment you want to have\n  om_filter_data(n_assessments = 1:3,\n             # assessment version?\n             version = 4,\n             # select Accesscode(s) to produce report for\n             accesscode = c(\"suszko|karimi\")\n  )\n```\n\n\n## `om_clean_par`\n\nCleans up ParticipantProgress data and creates several measures:\n\n+ **StepTimes1 to StepTimes5:** Duration in minutes to complete a step\n\n+ **StepCorrect1 to StepCorrect5:** Percentage of correct answers for each step\n\n+ **FeedbackAnswers:** Q1 to Q5 for each individual step\n\n```{r}\ndat.par %\u003e% \n  om_clean_par()\n```\n\n## `om_construct_measures`\n\nThis is a higher-level function that uses both `polar_measures` and `calc_ih` to constuct various measures.\n\nCreates the following variables:\n\n+ **Q14:** Affective Polarization\n+ **Q15:** Ingroup\n+ **Q16:** Outgroup\n+ **Q17:** Ingroup vs. Outgroup Affective Polarization\n+ **Q18:** Intellectual Humility\n\nFunction automatically accounts for Assessment Version 4 and 5/5.1.\n\n\n```{r, eval=F}\ndat.ass %\u003e% \n  om_construct_measures()\n```\n\n\u003e Error in polar_measures(., Q1Pre, Q2Pre) : Input data is missing column `ppol_cat`. Please make sure to run om_clean_ppol before you run om_construct_measures.\n\nUh oh! That didn't work! `om_construct_measures` needs the column `ppol_cat` to run which can be created with the function `om_clean_ppol`.\n\n\n## `om_clean_ppol`\n\nCreates the following measures of Political Orientation\n\n+ **ppol_raw:** a variable that merges Assessment V4 and V5.1 spelling of Political Orientation (D4)\n+ **ppol:** a factor variable ordered from \"Very Progressive/left\" to \"Very Conservative/right\". Excludes all other categories as NA (classical liberal etc.)\n+ **ppol_num:** numeric variable ranging from 1 \"Very Progressive/left\" to 7 \"Very Conservative/right\"\n+ **ppol_cat:** a factor variable which has two categories \"Progressive\" and \"Conservative\". The rest is NA.\n\n```{r}\n\ndat.ass \u003c- dat.ass %\u003e% \n  om_clean_ppol()\n\ndat.ass\n```\n\nNow `om_construct_measures` will work!\n\n```{r}\ndat.ass %\u003e% \n  om_construct_measures()\n```\n\n## `remove_dups`\n\nThis function is really important to clean up duplicated OMIDs that occasionally occur within AirTable. \n\n```{r, message = T}\ndat.ass %\u003e% \n  remove_dups()\n```\n\n\n## OpenMind ggplot2 theme\n\nThere are three functions for the ggplot2 theme:\n\n+ `theme_om`\n+ `scale_fill_om`\n+ `scale_color_om`\n\nMake sure you have the Poppins font installed!\n\n```{r}\nwindowsFonts(`Poppins` = windowsFont(\"Poppins\"))\n\n```\n\n\n[Good tutorial on how to install custom fonts in R](https://www.andrewheiss.com/blog/2017/09/27/working-with-r-cairo-graphics-custom-fonts-and-ggplot/)\n\n**Example**\n\n```{r fig.width=8, fig.height=5, message=F, warning=F}\n## Load tidyverse\nlibrary(tidyverse)\n\ntitanic_dat \u003c- Titanic %\u003e% as_tibble()\n\ntitanic_dat %\u003e% \n  ggplot(aes(Sex, n)) +\n  geom_col(aes(fill = Class), position = position_dodge()) +\n  theme_om(legend_position = c(0.9, 0.75)) +\n  scale_fill_om(\"Class\") +\n  facet_wrap(~Survived) +\n  labs(title = \"Titanic Survival by Age and Class\") \n  \n```\n\n**Adapt `theme_om`**\n\n+ `legend_position`\n+ `axis_text_size`\n+ `axis_title_size`\n+ `legend_text_size`\n+ `title_size`\n\n```{r fig.width=8, fig.height=5, message=F}\ntitanic_dat %\u003e% \n  ggplot(aes(Class, n, fill = Class)) +\n  geom_col() +\n  theme_om(legend_position = \"bottom\",\n           axis_text_size = 10,\n           axis_title_size = 15, \n           legend_text_size = 10,\n           title_size = 20) +\n  scale_fill_om() +\n  facet_wrap(~Survived) +\n  labs(title = \"Titanic Survival by Class\") \n```\n\nOr all text sizes at once\n\n+ `overall_text_size`\n\n```{r fig.width=8, fig.height=5, message=F}\ntitanic_dat %\u003e% \n  ggplot(aes(Class, n, fill = Class)) +\n  geom_col() +\n  theme_om(legend_position = \"top\",\n           overall_text_size = 15) +\n  scale_fill_om() +\n  facet_wrap(~Survived) +\n  labs(title = \"Titanic Survival by Class\") \n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffavstats%2Fopenmindr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffavstats%2Fopenmindr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffavstats%2Fopenmindr/lists"}