Skip to content

Instantly share code, notes, and snippets.

View bwiernik's full-sized avatar

Brenton M. Wiernik bwiernik

View GitHub Profile
@bwiernik
bwiernik / pp_check.lm.R
Last active September 4, 2020 07:43
Posterior predictive checks for lm() models
## Functions to draw samples from distributions implied by lm() models
##
## Arguments for simulate_model correspond to arguments in:
## a) stats::predict.lm();
## b) stats::simulate();
## c) nsamples is an alias for nsim;
## d) dist_type specifies the type of distribution to sample from
## 1) "ml"; from the maximum likelihood distribution;
## the distribution implied by estimated model parameters;
## (equivalent to stats::simulate());
@bwiernik
bwiernik / chicago-with-cite-group.csl
Created August 4, 2020 06:27
CSL Chicago author-date with cite-group-delimiter
<?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="display-and-sort" page-range-format="chicago">
<info>
<title>Chicago Manual of Style 17th edition (author-date)</title>
<id>http://www.zotero.org/styles/chicago-author-date</id>
<link href="http://www.zotero.org/styles/chicago-author-date" rel="self"/>
<link href="http://www.chicagomanualofstyle.org/tools_citationguide.html" rel="documentation"/>
<author>
<name>Julian Onions</name>
<email>julian.onions@gmail.com</email>
@bwiernik
bwiernik / power_tau.R
Created October 25, 2019 23:32
Power function for testing τ = 0 for random effects meta-analyses
# Based on methods described by Hedges and Pigott, https://doi.org/10.1037/1082-989X.9.4.426, p. 438
# Written 2019-10-25 by Brenton M. Wiernik
# Licensed GPL v3.0
power_curve <- function(object, tau, level = .95) {
if (! inherits(object, "rma.uni")) stop("'object' must be an object of class 'rma.uni'")
tau2 <- tau^2
obs_tau2 <- object$tau2
obs_tau <- sqrt(obs_tau2)
obs_H2 <- object$H2
>>===== MODE =====>>
bibliography
<<===== MODE =====<<
>>===== DESCRIPTION =====>>
set delimiter
<<===== DESCRIPTION =====<<
>>===== RESULT =====>>
<div class="csl-bib-body">
@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 / 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.#