Skip to content

Instantly share code, notes, and snippets.

View bwiernik's full-sized avatar

Brenton M. Wiernik bwiernik

View GitHub Profile
@bwiernik
bwiernik / zotbear.js
Last active January 19, 2022 15:01 — forked from zuphilip/zotbear.js
/*
How does this work?
0) make a backup copy
1) create a collection of all entries you want to batch edit
(maybe use a smart search or drag and drop, delete individual items)
2) check that you have exactly the items you want to change in your collection
3) choose one example here and adapt it to your needs
4) run the code
5) save the log if needed
*/
@bwiernik
bwiernik / empirical_es_benchmarks.json
Created April 30, 2020 23:50
Empirical effect size benchmarks
[
{"id":"BoscoCorrelationaleffectsize2015","abstract":"Effect size information is essential for the scientific enterprise and plays an increasingly central role in the scientific process. We extracted 147,328 correlations and developed a hierarchical taxonomy of variables reported in Journal of Applied Psychology and Personnel Psychology from 1980 to 2010 to produce empirical effect size benchmarks at the omnibus level, for 20 common research domains, and for an even finer grained level of generality. Results indicate that the usual interpretation and classification of effect sizes as small, medium, and large bear almost no resemblance to findings in the field, because distributions of effect sizes exhibit tertile partitions at values approximately one-half to one-third those intuited by Cohen (1988). Our results offer information that can be used for research planning and design purposes, such as producing better informed non-nil hypotheses and estimating statistical power and planning sample size accordin
@bwiernik
bwiernik / s3_tutorial.R
Created March 8, 2021 22:09
S3 dispatch examples for R packages
library(psychmeta)
ma_obj <- ma_r(rxyi = rxyi, n = n, rxx = rxxi, ryy = ryyi,
construct_x = x_name, construct_y = y_name, sample_id = sample_id,
moderators = moderator, data = data_r_meas_multi)
summary(ma_obj)
class(ma_obj)
inherits(ma_obj, "ma_psychmeta")
inherits(ma_obj, "ma_table")
@bwiernik
bwiernik / ape-numeric.csl
Created October 5, 2017 10:29
Numeric APA CSL style
<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" demote-non-dropping-particle="never">
<info>
<title>American Psychological Association 6th edition (numeric)</title>
<title-short>APA (numeric)</title-short>
<id>http://www.zotero.org/styles/apa-numeric</id>
<link href="http://www.zotero.org/styles/apa-numeric" rel="self"/>
<link href="http://owl.english.purdue.edu/owl/resource/560/01/" rel="documentation"/>
<author>
<name>Simon Kornblith</name>
@bwiernik
bwiernik / sim.rma.uni.R
Created February 16, 2021 14:14
Posterior (predictive) simulation for metafor rma models
# Copyright (2021) Brenton M. Wiernik
# Licensed under GPL-3.0
#
sim.rma.uni <- function(object, n.sims = object$k, sim.type = c("coef", "sample"), newdata = NULL, control = NULL, ...) {
sim.type <- match.arg(sim.type)
if (!inherits(object, "rma.uni"))
stop(mstyle$stop("Argument 'object' must be an object of class \"rma.uni\"."))
if (inherits(object, "robust.rma"))
stop(mstyle$stop("Method not available for objects of class \"robust.rma\"."))
if (inherits(object, "rma.ls"))
@bwiernik
bwiernik / compute_smd.R
Created December 6, 2020 13:42
R functions to compute adjusted SMD (Cohen's d) from a regression or ANCOVA model
.cmicalc <- function (df) {
cmi <- ifelse(df <= 1, NA,
exp(lgamma(df/2) - log(sqrt(df/2)) - lgamma((df - 1)/2))
)
return(cmi)
}
smd_stats <-
function(diff = NULL,
se_diff = NULL,
@bwiernik
bwiernik / apa_references.yaml
Created November 18, 2020 18:23
APA Manual references
---
references:
- id: 1917a
archive: 'Manuscripts and Archives, Yale University Library'
archive_location: 'Robert Mearns Yerkes Papers (Box 137, Folder 2292)'
archive-place: 'New Haven, CT'
issued:
- year: 1917
- year: 1954
circa: true
@bwiernik
bwiernik / refernces.yaml
Created November 18, 2020 18:16
Example CSL YAML
---
references:
- id: BalsamAffirmativecognitivebehavior2019
accessed:
- year: 2019
month: 10
day: 17
author:
- family: Balsam
given: Kimberly F.
@bwiernik
bwiernik / complete_list.R
Last active November 7, 2020 15:27
R function to complete lists and make missing elements explicitly NA
complete_list <- function(.list, .names) {
if (missing(.names)) return(.list)
.list[.names[! (.names %in% names(.list)) ]] <- NA
return(.list)
}
a <- list(b = 1, c = 2)
a <- complete_list(a, c("a", "b", "c"))
dplyr::coalesce(a$a, a$b, a$c, 0)
@bwiernik
bwiernik / change_plot.R
Created October 30, 2020 20:12
ggplot example individual + group change plot
library(tidyverse)
ind_data <- psych::bfi %>%
na.omit() %>%
filter(education %in% c(2, 4, 5)) %>%
select(A1:A5, education) %>%
group_by(education) %>%
slice(sample(1:n(), 40)) %>%
ungroup() %>%
rowid_to_column(".id") %>%