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
#load packages | |
library("curl") | |
library("ggplot2") | |
library("rstan") | |
#retrieve the data | |
tmpf = tempfile() | |
curl_download("http://www.metoffice.gov.uk/hadobs/hadcrut4/data/current/time_series/HadCRUT.4.5.0.0.annual_ns_avg.txt", tmpf) | |
gtemp = read.table(tmpf, colClasses = rep("numeric", 12))[, 1:2] # only want some of the variables | |
names(gtemp) = c("Year", "Temperature") |
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
data { | |
#N: number of cases | |
int N ; | |
#: K: number of outcome variables | |
int K ; | |
#X: matrix of outcomes for each case & variable | |
matrix[N,K] X ; | |
#Y: outcomes | |
vector[N] Y; | |
} |
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(rstan) | |
library(MASS) | |
# Generate some fake data ------------------------------------------------- | |
set.seed(1) | |
N = 100 #number of subjects | |
K = 10 #number of observations per subject per condition | |
#population parameters |
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
data { | |
// N: num unique x values | |
int<lower=1> N ; | |
// x: x values | |
real x[N] ; | |
// y: data | |
vector[N] y ; | |
} | |
transformed data{ | |
vector[N] zeros ; |
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(rstan) | |
#set random seed for reproducibility | |
set.seed(1) | |
#generate fake data | |
#variables setting data size | |
N = 30 #number of x-axis grid points | |
M = 2 #number of noisy replicates per grid point |
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(ggplot2) | |
library(rstan) | |
N = 100 #number of x-axis grid points | |
M = 10 #number of noisy replicates per grid point | |
noise = 1 #amount of noise added to each replicate | |
#define the x-axis grid | |
x = seq(-10,10,length.out=N) |
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
# Example model from a typical Psychology experiment where mutiple | |
# human subjects each contribute multiple observations ("trials") | |
# in each of two conditions. We model the subject population as | |
# having a mean intercept and mean difference-between-conditions, | |
# and subjects as having potentially-correlated deviations from | |
# these means. For a given subject in a given condition, trial-by- | |
# trial observations are sampled with normal error, with a common | |
# error magnitude used across all subjects/conditions. | |
#clear workspace to ensure a fresh start |
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
Last login: Tue Jun 28 15:06:37 on ttys003 | |
Mikes-MacBook-Air:~ mike$ R | |
R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree" | |
Copyright (C) 2015 The R Foundation for Statistical Computing | |
Platform: x86_64-apple-darwin13.4.0 (64-bit) | |
R is free software and comes with ABSOLUTELY NO WARRANTY. | |
You are welcome to redistribute it under certain conditions. | |
Type 'license()' or 'licence()' for distribution details. |
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(ggplot2) | |
library(rstan) | |
#set random seed for reproducibility | |
set.seed(1) | |
NX = 100 #number of x-axis grid points | |
NZ = 10 #number of noisy replicates per condition | |
#define the x-axis grid |
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
#load packages | |
library("curl") | |
library("ggplot2") | |
library("rstan") | |
#retrieve the data | |
tmpf <- tempfile() | |
curl_download("http://www.metoffice.gov.uk/hadobs/hadcrut4/data/current/time_series/HadCRUT.4.5.0.0.annual_ns_avg.txt", tmpf) | |
gtemp <- read.table(tmpf, colClasses = rep("numeric", 12))[, 1:2] # only want some of the variables | |
names(gtemp) <- c("Year", "Temperature") |