Skip to content

Instantly share code, notes, and snippets.

View bwiernik's full-sized avatar

Brenton M. Wiernik bwiernik

View GitHub Profile
@bwiernik
bwiernik / bugreport_limit-day-ordinals-to-day-1.txt
Created June 27, 2020 19:32
citeproc-js_bug_limit-day-ordinals-to-day-1
>>===== MODE =====>>
bibliography
<<===== MODE =====<<
>>===== DESCRIPTION =====>>
limit-day-ordinals-to-day-1 with date ranges
<<===== DESCRIPTION =====<<
>>===== RESULT =====>>
<div class="csl-bib-body">
@bwiernik
bwiernik / alpha_stratified.R
Created June 16, 2020 21:19
stratified alpha R function
alpha_stratified <- function(x, a, na.rm = TRUE) {
v <- diag(var(x, na.rm = na.rm))
vt <- sum(var(x, na.rm = na.rm))
ev <- sum((1 - a) * v)
return(list(strat.alpha = c(1 - ev/vt), scores = rowMeans(x, na.rm = TRUE)))
}
@bwiernik
bwiernik / alpha_stratified.R
Created June 16, 2020 21:19
stratified alpha R function
alpha_stratified <- function(x, a, na.rm = TRUE) {
v <- diag(var(x, na.rm = na.rm))
vt <- sum(var(x, na.rm = na.rm))
ev <- sum((1 - a) * v)
return(list(strat.alpha = c(1 - ev/vt), scores = rowMeans(x, na.rm = TRUE)))
}
@bwiernik
bwiernik / apa-fullnote-annotations.csl
Created May 30, 2020 13:39
APA CSL style, with citations formatted as full notes and standalone annotations entered in the `annote` field of patent items.
<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" class="note" version="1.0" demote-non-dropping-particle="never" page-range-format="expanded">
<info>
<title>American Psychological Association 7th edition (full note, annotations)</title>
<title-short>APA (full note, annote)</title-short>
<summary>APA style, with citations formatted as full notes and standalone annotations entered in the `annote` field of patent items.</summary>
<id>http://www.zotero.org/styles/apa-fullnote-annotations</id>
<link href="https://raw.githubusercontent.com/bwiernik/zotero-tools/master/apa-fullnote-annotations.csl" rel="self"/>
<link href="http://www.zotero.org/styles/apa" rel="template"/>
<link href="https://apastyle.apa.org/style-grammar-guidelines/references/examples" rel="documentation"/>
@bwiernik
bwiernik / apanum.vb
Created May 12, 2020 14:13
Excel Functions for APA number and estimate/CI formatting
' Functions to format numbers and estimates with confidence intervals in an APA-like format
'
' Author: Brenton M. Wiernik
' Date: 2020-05-12
'
' License: CC0
'
' Usage examples:
' Single number:
' =apanum(value, lead_zero, pos_sign, neg_sign, big_sep)
@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 / ma_sem_model.R
Created April 24, 2020 15:53
Script to meta-analyze results of lavaan sem models
# Script to meta-analyze results of lavaan sem models
#
# Author: Brenton M. Wiernik
# Date: 2020-04-24
# License: CC-BY 4.0 (https://creativecommons.org/licenses/by/4.0/)
#
# This script will meta-analyze the results of lavaan sem models. It assumes
# that the exact same lavaan model is specified for each sample and is
# not robust to differences in model specfications.#
@bwiernik
bwiernik / ridge_plot_example.R
Last active March 4, 2020 05:17
Ridge plot for plotting logistic regression data
library(dplyr)
library(ggplot2)
library(ggridges)
dat <- select(psych::bfi, age, education, gender) %>%
mutate(education = as.factor(education),
gender = as.factor(gender),
gender_edu = paste(education, gender)) %>%
na.omit()
ggplot(dat, aes(x = age,
@bwiernik
bwiernik / correlation_matrix_format.R
Created March 1, 2020 19:49
R functions to format correlation matrices into upper, lower, or upperLower format for printing
#' Format the lower triangle of a matrix for printing
#'
#' @param x A matrix (e.g., a correlation matrix).
#' @param diag Either a logical value indicating whether to print the diagonal of the matrix (`TRUE`) or not (`FALSE`) or a vector of values to place on the diagonal (e.g., variable reliabilities).
#' @param format_num Logical. Should the `format_num()` function from the `psychmeta` package be used to format numbers?
#' @param ... Arguments passed to `psychmeta::format_num()`.
#'
#' @return
#' @export
#'
@bwiernik
bwiernik / coef_cov.R
Last active January 27, 2020 22:02
Function to compute simple linear regression coefficients and their covariances
#####
# Function: coef_cov
# Author: Brenton M. Wiernik
# Date: 2020-01-27
# Version: 1.0
#
# Computes univariate linear regresssion models,
# predicting each response variable [`.y`] with each
# predictor variable [`.x`]. Returns the coefficients
# and their variance-covariance matrix.