Skip to content

Instantly share code, notes, and snippets.

View phewson's full-sized avatar

Paul Hewson phewson

View GitHub Profile
@phewson
phewson / server.R
Created November 28, 2014 15:12
Parrondo's Paradox
shinyServer(function(input, output) {
gameA <- function(p){
WinLose <- sample(c(1,-1), size = 1, prob=c(p,(1-p)))
}
gameB <- function(CurrentCapital, p1, p2){
WinLose <- 0
if ((CurrentCapital %% 3) == 0){
@phewson
phewson / server.R
Created November 27, 2014 11:16
OneSample
library(shiny)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
Data <- reactive({
# output$contents <- renderTable({
# input$file1 will be NULL initially. After the user selects
# and uploads a file, it will be a data frame with 'name',
@phewson
phewson / server.R
Last active September 9, 2015 20:15
Distribution Plotter
library(arm)
options(warn=-1)
shinyServer(function(input, output){
Data <- reactive({
#N <- as.numeric(input$ns)
#prob <- input$prob
lambda <- 0
@phewson
phewson / server.R
Created November 11, 2014 08:37
Illustration of Randomisation Tests
library(shiny)
# Define server logic required to generate and plot a random distribution
shinyServer(function(input, output) {
x1 <- c(3.36, 3.24, 5.16, 6.09, 3.08, 6.97, 4.85, 5.42, 5.15, 3.61, 4.95, 2.22)
x2 <- c(2.72, 3.09, 1.49, 1.98, 0.85, 2.56, 2.14, 1.80, 0.57, 3.16, 0.90, 0.15)
x <- c(x1, x2)
mycol = c(rep("red", 12), rep("blue", 12))
ind <- c(rep(1,12), rep(2,12))
X <- matrix("numeric", 24, 1001)
@phewson
phewson / server.R
Last active August 29, 2015 14:08
Version 0.1 Run a two sample t-test from Shiny
library(shiny)
shinyServer(function(input, output) {
Data <- reactive({
# output$contents <- renderTable({
# input$file1 will be NULL initially. After the user selects
@phewson
phewson / LOO.R
Created October 8, 2013 19:12
This is an animation using the manipulate package in R-studio. It uses the Anscombe data - you get to choose which pair. Then you slide through the datasets and the line is computed omitting that data point, and the leave one out residual is illustrated. I would like to tidy up a few details on this, but it works as a first step.
require(MASS)
require(manipulate)
data(anscombe)
plotit <- function(whichpair, i){
eval(parse(text = paste("sortit <- order(anscombe$x", whichpair, ")", sep = "")))
eval(parse(text = paste("data.df <- data.frame(x=anscombe$x", whichpair, "[sortit], y=anscombe$y", whichpair, "[sortit])", sep = "")))
ylims <- c(min(data.df$y)*0.8, max(data.df$y)*1.2)
xlims <- c(min(data.df$x)*0.8, max(data.df$x)*1.2)
@phewson
phewson / Hamiltonian
Last active December 19, 2015 04:49
Early explorations in Hamiltonian MC (based on Radford Neal's chapter in the MCMC handbook)
This file has been truncated, but you can view the full file.
{
"metadata": {
"name": "Hamiltonian"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@phewson
phewson / gist:5821745
Created June 20, 2013 10:32
This is a simple illustration of a rejection sampler. At the moment we just get Beta random variables, which is a little unfortunate as we are using two uniform distributions in the simulations which I think confuses a few people.
{
"metadata": {
"name": "Rejection Sampler Illustrated"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@phewson
phewson / GibbsChangepoint.ipynb
Last active December 18, 2015 14:29
This is a draft of the Coalmine disasters Poisson changepoint problem, with a Bayesian model estimated by a simple Gibbs sampler written in Python.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.