Skip to content

Instantly share code, notes, and snippets.

View saudiwin's full-sized avatar

Robert Kubinec saudiwin

View GitHub Profile
@saudiwin
saudiwin / compare_ordbeta_glmmTMB
Created December 20, 2022 08:16
Comparison of ordbetareg and glmmTMB versions of the ordered beta regression model
# test glmmTMB's MLE implementation of the ordered beta regression model
# and compare it to the ordbetareg package, which uses
# Bayesian estimation (Stan/brms)
library(glmmTMB)
library(ordbetareg)
library(dplyr)
data("pew")
@saudiwin
saudiwin / powercalc_ord_binary.R
Created January 31, 2022 07:25
Power calculation showing why ordinal outcomes are more efficient than binary (dichotomized) outcomes
# Ordinal versus binary outcome power calculation
# Robert Kubinec
# New York University Abu Dhabi
# January 31, 2022
library(dplyr)
library(ordinal)
library(ggplot2)
@saudiwin
saudiwin / create_array.R
Created June 7, 2018 16:30
A tidy function that converts long data frames to arrays.
#' Helper function to create arrays
#'
#' Function takes a data.frame in long mode and converts it to an array. Function can also repeat a
#' single matrix to fill out an array.
#'
#' @param input_matrix Either a data.frame in long mode or a single matrix
#' @param arr_dim If \code{input_matrix} is a single matrix, \code{arr_dim} determines the length of the resulting array
#' @param row_var Unquoted variable name that identifies the data.frame column corresponding to the rows (1st dimension) of the array (must be unique)
#' @param col_var_name Unquoted variable name that identifies the data.frame column corresponding names of the columns (2nd dimension) of the array
#' @param col_var_value Unquoted variable name that identifies the data.frame column corresponding to the values that populate the cells of the array
@saudiwin
saudiwin / .gistr
Created June 7, 2018 16:30
A tidy function that converts long data frames to arrays.
gistr
@saudiwin
saudiwin / .gistr
Created June 7, 2018 16:29
A tidy function that converts long data frames to arrays.
gistr