This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(reshape2) | |
library(ggplot2) | |
#' Create a heatmap in ggplot2 | |
#' | |
#' @param data Data set | |
#' @param print.cors Default TRUE. Should the correlations be printed in each block of the heatmap? | |
#' @param reoder Default TRUE. Should the entries be re-ordered via clustering, similar to `heatmap`? | |
#' @param colors Default c("red", "white", "blue"). Vector of length three defining colors for correaltions (1, 0, -1). | |
#' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This gist has been superceded by the howManyImputations package (https://cran.r-project.org/web/packages/howManyImputations/index.html and https://errickson.net/howManyImputations/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SEP="," | |
HEADER=true | |
STDERR=false | |
while [ "$#" -gt 0 ]; do | |
case "$1" in | |
-s) SEP="$2"; shift 2;; | |
-c) COL="$2"; shift 2;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "i <- rownames(installed.packages())" > __tmp__.R | |
grep -oh --include=\*.{Rmd,R} -r * -e "\(library\|require\)([A-Za-z0-9.]\+)" | \ | |
sed 's_library(_"_' | \ | |
sed 's_require(_"_' | \ | |
sed 's_)_",_' | sort | uniq | \ | |
perl -p -e 's/\n/ /' | \ | |
sed 's_^_new <- c(_' | \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
webuse mheart1s20, clear | |
* Run the input model, producing the results as well as returning the AIC/BIC | |
capture program drop modelPlusIC | |
program modelPlusIC, eclass properties(mi) | |
args model | |
quiet `model' | |
quiet estat ic | |
matrix S = r(S) | |
* Append the new AIC/BIC to IC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
suppressMessages(require(devtools)) | |
yesno <- function(...) { | |
cat(paste0(..., collapse = "")) | |
# For whatever reason, devtools:::yesno returns `TRUE` if you select a No | |
# option, and `FALSE` if you select a Yes option | |
utils::menu(c("Yes", "No")) != 1 | |
} | |
utils::assignInNamespace("yesno", yesno, "devtools") | |
# remove stand-alone `yesno` | |
rm(yesno) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(forestplot) | |
data(mtcars) | |
mtcars$disp <- mtcars$disp/100 | |
coefs <- summary(mod <- lm(mpg ~ disp + cyl + qsec + wt, data = mtcars))$coeff | |
cis <- confint(mod) | |
dat <- data.frame(cbind(coefs[, c(1, 4)], cis)) | |
names(dat) <- c("mean", "pv", "lower", "upper") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
summary.lm <- function(object, correlation = FALSE, symbolic.cor = FALSE, ..., vcov. = NULL) { | |
ss <- stats::summary.lm(object, correlation, symbolic.cor, ...) | |
if (!is.null(vcov.)) { | |
if (is.function(vcov.)) { | |
vcov. <- vcov.(object, ...) | |
} | |
ss$cov.unscaled <- vcov./ss$sigma^2 | |
ss$coefficients[,2] <- sqrt(diag(vcov.)) |