Skip to content

Instantly share code, notes, and snippets.

View ericpgreen's full-sized avatar

Eric Green ericpgreen

View GitHub Profile
@ericpgreen
ericpgreen / steppedwedgeR.R
Last active December 20, 2015 23:29
power calculator for stepped wedge designs
# Calculation of power for stepped wedge design
# Adapted from an excel-based calculator from Jim Hughes, jphughes@u.washington.edu
# see http://faculty.washington.edu/peterg/Vaccine2006/articles/HusseyHughes.2007.pdf
# http://faculty.washington.edu/jphughes/Power%20for%20stepped%20wedge.xls
# http://faculty.washington.edu/jphughes/Power%20for%20stepped%20wedge%20(mean).xls
# Adapted by Eric Green, eric.green@duke.edu, @ericpgreen
# (1) enter or (2) import design matrix ===========================================================
# skip option 1 if using option 2, and vice versa
# power.p is the final object of interest for proportions
@ericpgreen
ericpgreen / rnw article template
Last active December 22, 2015 16:29
template for writing an article in RStudio that combines text + R code and compiles into .tex and .pdf via LaTeX
%-------------------------------------------------------------------------------
% Title
% Code written by AUTHOR, email
% Date
% Other notes
%-------------------------------------------------------------------------------
\documentclass[authoryear,11pt]{elsarticle} % requires elsarticle package
\usepackage[T1]{fontenc}
@ericpgreen
ericpgreen / .R file template
Created September 10, 2013 00:19
.R file template
#------------------------------------------------------------------------------
# Title
# Code written by AUTHOR, email
# Date
# Other notes
#------------------------------------------------------------------------------
# setup
#------------------------------------------------------------------------------
# load libraries
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
*.aux
*.glo
@ericpgreen
ericpgreen / bootSem2.R
Last active December 25, 2015 05:39
modification to bootSem for R sem package to prevent crashing on Mac
# bootstrapped standard errors and confidence intervals for sem
# original sem code from sem:::bootSem.sem
# original post: http://r.789695.n4.nabble.com/Bootstrap-bootSem-causes-R-to-crash-tp4661900p4677999.html
# commented out lines referencing tcltk
bootSem2 <- function (model, R = 100, Cov = cov, data = model$data, max.failures = 10,
...)
{
@ericpgreen
ericpgreen / simord.R
Last active December 26, 2015 04:09
code for simulating a multivariate ordinal dataset using the MultiOrd package and resulting dataset
# info
#-------------------------------------------------------------------------------------
# simulation of a multivariate ordinal dataset using the MultiOrd package
# running this .R gist will *only* read in the final data, not run the simulation
# scroll down to see original code to simulate
# sim code modified by package creator to override simBinCorr function
# simulated data
#-------------------------------------------------------------------------------------
<!DOCTYPE html>
<html>
<head>
<title>Test Google Forms</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
</head>
<body>
<div>
<div>
miList <- list(structure(list(v1 = c(2, 3, 0, 0, 0, 2, 1, 0, 3, 3, 1, 3,
3, 0, 1, 3, 3, 2, 0, 1, 3, 0, 0, 0, 2, 0, 3, 3, 0, 0, 2, 0, 1,
2, 3, 3, 0, 3, 3, 2, 3, 3, 0, 0, 0, 0, 1, 1, 0, 3, 0, 3, 3, 3,
0, 3, 3, 2, 3, 2, 3, 3, 0, 2, 0, 3, 0, 2, 0, 0, 3, 2, 3, 0, 2,
3, 0, 3, 2, 0, 0, 2, 0, 1, 2, 2, 3, 0, 0, 0, 0, 0, 0, 3, 0, 0,
0, 3, 0, 2, 0, 0, 1, 3, 0, 0, 2, 1, 3, 0, 0, 3, 2, 0, 3, 3, 1,
3, 3, 2, 0, 3, 2, 2, 3, 0, 3, 2, 3, 0, 0, 2, 0, 0, 2, 0, 0, 0,
2, 0, 2, 0, 1, 0, 2, 0, 2, 1, 2, 3, 0, 0, 3, 2, 0, 2, 3, 2, 0,
3, 0, 2, 3, 0, 0, 0, 0, 2, 2, 3, 3, 2, 3, 2, 0, 0, 3, 3, 3, 0,
0, 3, 1, 0, 0, 0, 3, 3, 0, 1, 3, 3, 3, 1, 0, 1, 0, 0, 3, 3, 0
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# export from R to Excel with conditional highlighting
# see http://stackoverflow.com/questions/21618556/export-data-frames-to-excel-via-xlsx-with-conditional-formatting
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# get some data from the psych package
library(psych)
dat <- bfi
# load xlsx
library(xlsx)
# :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# dhis api access
# :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# https://www.dhis2.org/doc/snapshot/en/developer/html/apas07.html
# https://github.com/jason-p-pickering/datim-validation
# http://www.r-fiddle.org/#/fiddle?id=wHglXleC&version=1
# :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# setup =======================================================================
require(RCurl)