Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Christopher Peters statwonk

🏠
Working from home
Block or report user

Report or block statwonk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@statwonk
statwonk / inezs_weibulls.R
Created Jun 1, 2019
;O{) # o-----\. # /.;/?}
View inezs_weibulls.R
library(tidyverse)
plot.new()
par(bg = "black")
plot(density(rweibull(1e6, 2, 0.1)), col = "pink3", lwd = 1, ylim = c(0, 20),
xlab = "", ylab = "", main = "Weibull distribution", axes = FALSE)
seq(1, 5, 0.25) %>%
map(function(x){ rweibull(1e6, x, 0.1)}) %>%
map(function(x) { density(x) %>%
lines(col = sample(colors(), 1),
lwd = sample(seq(0.1, 3, 0.1), 1),
@statwonk
statwonk / control-vs-interaction.R
Created May 17, 2019
A comparison of std.errors of the treatment effect from an additive DGP experiment where a pre-treatment variable is interacted maximally, only additive no interaction, or unadjusted for.
View control-vs-interaction.R
library(tidyverse)
library(lme4)
library(broom)
N <- 1e4
generate_data <- function() {
tibble(
intercept = 1,
pretreatment_var = case_when(rbinom(N, 1, p = 0.5) == 1 ~ 0.5, TRUE ~ -0.5),
View cdfs.R
library(tidyverse)
# Cumulative density functions
?hist
# built in datasets
str(mtcars)
head(mtcars)
@statwonk
statwonk / km-quantiles.R
Created Apr 7, 2019
A routine showing how to calculate quantiles.
View km-quantiles.R
library(survival)
library(Hmisc)
# 1. a weibull random number generator, see http://statwonk.com/weibull.html
rweibull_cens <- function(n, shape, scale) {
# will happen to see the death time first or censoring?
rweibull(n, shape = shape, scale = scale) -> a_random_death_time
rweibull(n, shape = shape, scale = scale) -> a_random_censor_time
pmin(a_random_censor_time, a_random_death_time) -> observed_time
View keybase.md

Keybase proof

I hereby claim:

  • I am statwonk on github.
  • I am statwonk (https://keybase.io/statwonk) on keybase.
  • I have a public key ASBKY0yAKx1KghVEq7DmzhrFWAIZn94O-vhQHcjU9Wwz-go

To claim this, I am signing this object:

@statwonk
statwonk / exp_relative_likelihoods.R
Created Oct 23, 2017
100 exponential random variables and their relative likelihoods
View exp_relative_likelihoods.R
suppressPackageStartupMessages({
library(dplyr)
library(ggplot2)
library(purrr)
})
exp_likelihood <- function(x, lambda) {
(lambda^length(x))*exp(-lambda*length(x)*mean(x))
}
seq_len(1e2) %>%
lapply(function(i) {
@statwonk
statwonk / library.R
Created Jul 6, 2016
R's library() function
View library.R
function (package, help, pos = 2, lib.loc = NULL, character.only = FALSE,
logical.return = FALSE, warn.conflicts = TRUE, quietly = FALSE,
verbose = getOption("verbose"))
{
testRversion <- function(pkgInfo, pkgname, pkgpath) {
if (is.null(built <- pkgInfo$Built))
stop(gettextf("package %s has not been installed properly\n",
sQuote(pkgname)), call. = FALSE, domain = NA)
R_version_built_under <- as.numeric_version(built$R)
if (R_version_built_under < "3.0.0")
View .getRequiredPackages2.R
function (pkgInfo, quietly = FALSE, lib.loc = NULL, useImports = FALSE)
{
.findVersion <- function(pkg, lib.loc = NULL) {
pfile <- system.file("Meta", "package.rds", package = pkg,
lib.loc = lib.loc)
if (nzchar(pfile))
as.numeric_version(readRDS(pfile)$DESCRIPTION["Version"])
else NULL
}
.findAllVersions <- function(pkg, lib.loc = NULL) {
View Bayesian Survival Analysis.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@statwonk
statwonk / server.R
Last active Nov 9, 2015
A DiagrammeR app
View server.R
library(shiny)
library(DiagrammeR)
library(magrittr)
shinyServer(function(input, output) {
output$diagram_plot <- renderDiagrammeR({
graph <-
create_graph() %>%
set_graph_name("Boxes and Circles") %>%
set_graph_time() %>%
You can’t perform that action at this time.