Skip to content

Instantly share code, notes, and snippets.

Richard Morey richarddmorey

Block or report user

Report or block richarddmorey

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
@richarddmorey
richarddmorey / missings_jags.R
Created Dec 23, 2016
Using JAGS to sample missing values in both DVs and IVs in Bayesian regression
View missings_jags.R
set.seed(123) # make reproducible
M = 10000 # Number of posterior samples
N = 20
# sample the IV
x = rnorm(N, 10, 5)
# regression model for DVs
y = 100 + 3*x + rnorm(N,0,10)
## Delete missing data (3 in each)
View t1err-sim.R
### Utility functions
# Do a single t test simulation
# report the p value
ttest.sim = function(n, func, true.mean = 0, alpha = 0.05){
x = func(n) - true.mean
t.test(x)$p.value
}
# Do a sequence of M t tests, report significance
@richarddmorey
richarddmorey / getSpookyNums.R
Last active Oct 28, 2016
Spooky random numbers
View getSpookyNums.R
getSpookyNums = function(M){
s = tempfile() # to ensure no caching
my.url = paste0("http://richarddmorey.org/spooky.php?n=",M,"&",s)
as.numeric(readLines(my.url))
}
x = getSpookyNums(10)
@richarddmorey
richarddmorey / normal.xml
Created Oct 28, 2016
example XML for distribution
View normal.xml
<?xml version="1.0" encoding="utf-8"?>
<distribution>
<names>
<shortname>Normal</shortname>
<longname>Normal</longname>
<alternate>Gaussian</alternate>
<id>normal</id>
</names>
<type>continuous</type>
<support>
@richarddmorey
richarddmorey / solve.Rmd_
Last active Nov 17, 2016
Troubleshooting flexdashboard scrollbars
View solve.Rmd_
---
title: "Generated data demo"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: scroll
runtime: shiny
---
```{r setup, include=FALSE}
@richarddmorey
richarddmorey / runAll.R
Last active Aug 11, 2016
Run the Essex Data Analysis Summer School JAGS demo in R
View runAll.R
devtools::source_gist("2bd1b7a409fad3d71fc2d60884c85e50", filename = "runJAGSDemo.R")
@richarddmorey
richarddmorey / beta.binomial.R
Created Aug 10, 2016
example, Essex, beta/binomial
View beta.binomial.R
y = 13
N = 35
a = 1
b = 1
theta = seq(0, 1, len = 100)
likelihood = theta ^ y * (1-theta)^(N-y) #dbinom(y, N, theta)
prior = theta ^ (a-1) * (1-theta)^(b-1) #dbeta(theta, a, b)
posterior1 = prior * likelihood
@richarddmorey
richarddmorey / do_plots.R
Last active Aug 8, 2016
Comparison between normal and logistic priors for proportion Bayes factors
View do_plots.R
devtools::source_gist("e49c345fcd6cfe8f32535eda4bd8c29b", filename='utility_functions.R')
# Prior Setup
p0 = .5
rscale = .5
interval = c(.5,1)
# Do not change shift unless you want different prior shift
# will cause deviation from BayesFactor package
# (not that there's anything wrong with that, but changes demo)
shift = qlogis(p0)
@richarddmorey
richarddmorey / binomial-beta.Rnw
Created Jun 4, 2016
A demonstration of Bayes' theorem as "selecting subsets" using R markdown and interactive 3D plots
View binomial-beta.Rnw
---
title: "Joint and conditional, binomial/beta example"
author: "Richard D. Morey"
date: "4 June 2016"
output: html_document
---
```{r,echo=FALSE,warning=FALSE}
library(rgl)
library(knitr)
@richarddmorey
richarddmorey / test_gist.Rnw
Created May 26, 2016
A test of importing gists inside a latex (really, Sweave) document compiled with knitr in Rstudio.
View test_gist.Rnw
\documentclass{article}
\usepackage{fancyvrb, listings, xcolor}
\usepackage{hyperref}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{mauve}{rgb}{0.88, 0.69, 1.0}
\lstset{ %
language=R, % the language of the code
basicstyle=\footnotesize, % the size of the fonts that are used for the code
You can’t perform that action at this time.