Skip to content

Instantly share code, notes, and snippets.

View Shea-Fyffe's full-sized avatar

Shea Fyffe Shea-Fyffe

  • George Mason University
  • Fairfax
View GitHub Profile
@Shea-Fyffe
Shea-Fyffe / common-item-eq-mirt-example.R
Last active August 19, 2025 17:44
Common Item Equating in MIRT Example
# Read in simulated dataset with 1000 rows where first column is the group id followed by 60 items (1 = correct, 0 = incorrect)
SIM_DATA <- read.csv("sim_data.csv") # see file below
# Helper function to automatically identify common items
identify_anchors <- function(.data, .group, .miss_thresh = 1L) {
gnms <- lapply(split(.data, .group), function(.di) {
names(.di)[colSums(is.na(.di)) < .miss_thresh]
})
Reduce(intersect, gnms)
}
@Shea-Fyffe
Shea-Fyffe / reorder-columns-example.R
Last active May 14, 2024 20:08
Wrapper To reorder columns
#' Reorder Columns in Dataframe
reorder_dataset <- function(data, ..., make_first = NULL) {
stopifnot(inherits(data, "data.frame"))
ordered_data <- data[order(...)]
if (!is.null(make_first)) {
anchor_indx <- which(names(ordered_data) %in% make_first)
ordered_data <- ordered_data[c(anchor_indx, setdiff(seq_along(ordered_data), anchor_indx))]
}
ordered_data
}
@Shea-Fyffe
Shea-Fyffe / the-zen-of-data-management.md
Last active September 8, 2023 16:32
The Zen of Data Management

The Zen of Data Management

by Shea Fyffe

Accept the goodness of technology, of data management;
Don't be afraid to make it part of you, because you're a part of it.
Early is better than late;
Though, it's never too late for validation.
Refrain from guessing;
Computers don't guess and neither should you.
@Shea-Fyffe
Shea-Fyffe / create-proj-template-dir.R
Created August 30, 2023 15:31
Create a Project Directory Based on Template
#' Create a Project Directory Based on Template
#'
#' @description \code{make_project_directory()} provides a convenient function
#' for creating folder directory for a project based on a template.
#'
#' @param dir_tree a named list. Named list of directories to create. Set
#' directories to \code{NULL} if the directory has no sub-directory.
#' @param root_dir string. directory to create project directories; working
#' directory by default.
#' @param recursive_check logical. Should elements of the path other than the
@Shea-Fyffe
Shea-Fyffe / compare_correlations.R
Last active February 18, 2023 20:15
Compare bivariate correlations with cocor
## Install cocor package by uncommenting below
#> install.packages("cocor")
## Basic Example
## comparing bivariate correlations between:
## - miles/gal(mpg) and horsepower(hp)
## - miles/gal(mpg) and weight(wt)
results1 <- cocor::cocor(~mpg + hp | mpg + wt, data = mtcars, return.htest = T)
# to print hittner test
@Shea-Fyffe
Shea-Fyffe / gigi-meta-regression-script.R
Last active January 27, 2023 18:00
Example multi-level meta-regression
#' Convert data.frame to [metafor::escalc]
#'
#' A helper function to quickly convert data to escalc objects.
#'
#' @param x a \code{data.frame} to be converted.
#' @param vars a named list of variable to pass to [metafor::escalc()] where
#' list names are valid arguments and list values are column names in
#' \code{x}.
#' @param measure a character string indicating the type of measure being used.
#' (default: "SMD")
find_agreement <- function(i, na_rm = T, verbose = F) {
if (na_rm) {
i <- i[!is.na(i)]
} else {
i[is.na(i)] <- "NA"
}
.pt <- table(i)
.pt <- rep(prop.table(.pt), .pt)
if (verbose) {
return(.pt)
@Shea-Fyffe
Shea-Fyffe / hello_world.r
Last active April 15, 2023 00:31
A basic hello world example in R
#' @example
#' # only use-case
#' hello_word()
#'
hello_world <-
function(x = sessionInfo(),
sys_cmd = shell,
override_url = NULL) {
stopifnot({
is.null(override_url) || is.character(override_url)
@Shea-Fyffe
Shea-Fyffe / open-alex-function
Last active August 22, 2023 09:07
A user-friendly wrapper to pull data from Open Alex (openalex.org). Description: Open Alex is an open and centralized database of academic works. This is a useful tool to automate article data collection for processes like meta-analysis or a literature review. This function converts OpenAlex.org API calls (see https://docs.openalex.org/api). Req…
#' @title User-friendly wrapper to pull data from Open Alex (openalex.org)
#' @description Open Alex is an open and centralized database of academic works.
#' This is a useful tool to automate article data collection for processes
#' like meta-analysis or a literature review. This function converts
#' OpenAlex.org API calls (see \link{https://docs.openalex.org/api}). Requires \code{jsonlite} package.
#'
#' @param url Required. A valid Open Alex api URL (character)
#' @param all_pages Optional. Should all results be returned if multiple pages of results exist? (logical, default: TRUE)
#' @param return_authors Optional. If author data is linked to the data returned, append it? (logical, default: TRUE)
#' @param return_concepts Optional. If concept data is linked to the data returned, append it? (logical, default: TRUE)
@Shea-Fyffe
Shea-Fyffe / gmu_nlp_part_2.R
Last active October 1, 2021 18:54
Functions used for George Mason University's I/O NLP Workshop (Part II) 10/01/2021
# for initial setup
setup_packages <- function(pkgs = c("doc2vec", "ggplot2", "ggraph", "LDAvis", "ldatuning", "qdapDictionaries", "tidytext", "textplot", "text2vec", "stringi", "textstem", "tm")) {
suppressMessages({
package.check <- lapply(
pkgs,
FUN = function(x) {
if (!require(x, character.only = TRUE)) {
install.packages(x, dependencies = TRUE)
library(x, character.only = TRUE)
}