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(KFAS) | |
library(rstan) | |
data(GlobalTemp) | |
model_dlm1a <- stan_model("../stan/dlm1a.stan") | |
y <- as.matrix(GlobalTemp) | |
data <- | |
within(list(), | |
{ |
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(readr); library(dplyr); library(lubridate) | |
dat_2 <- read_csv("Datathon WC Data Games 11-20.csv") | |
glimpse(dat_2) | |
dat_3 <- read_csv("Datathon WC Data Games 21-30.csv") | |
as_datetime <- function(x){ |
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
# Some fake data | |
library(dplyr); library(rstan) | |
# Write out the data generation with known parameters | |
# Set the number of individuals | |
n_ind <- 50 |
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
# Generate fake data | |
dgp <- "data { | |
int<lower=1> N; | |
real x[N]; | |
real rho; | |
real sigma; | |
} | |
transformed data { | |
vector[N] mu; |
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(MASS); library(rstan) | |
# Sample size | |
N <- 5000 | |
# Generate two uncorrelated covariates (means 1 and 5, both with standard deviations of 1) | |
X <- mvrnorm(N, c(1, 5), matrix(c(1, 0, 0, 1), 2, 2)) | |
plot(X) | |
# Loadings matrix | |
Gamma <- matrix(c(0.5, 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
# In this demonstration, I estimate a discrete-time NGARCH model. | |
# I first simulate the model with known parameters, then try to | |
# recover the parameters from simulated data. Then I apply the | |
# model to weekly returns for Google. | |
# The model seems to be able to recover most of the parameters | |
# fairly well, with inference for alpha, beta fairly week. gamma | |
# does not seem to be well identified. | |
# jim savage, james@lendable.io |
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(tidyr); library(ggplot2) | |
library(rvest); library(dplyr); library(ggthemes) | |
session <- html_session("http://visadoor.com/") | |
form <- html_form(session)[[1]] | |
# Add job titles to the character list below | |
jobs <- c("data scientist", "economist", "actuary", "consultant", "management consultant", "statistician") | |
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 the Stan library and set it up to use all cores | |
library(rstan) | |
options(mc.cores = parallel::detectCores()) | |
# Create some data | |
softmax <- function(x) exp(x)/sum(exp(x)) | |
N <- 50 | |
P <- 5 | |
theta <- rnorm(P) |
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 { | |
int N; // number of observations | |
matrix[N, 6] Y; // a matrix of observations for each measure. I've encoded missing values as -9 | |
vector[6] inits; // a vector of centers for the initial values of the data | |
} | |
parameters { | |
// the state | |
matrix[N, 6] X; | |
// cholesky factor of the correlation matrix of the innovations to the state | |
cholesky_factor_corr[6] L_omega; |
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(dplyr) | |
aa <- data_frame(a = rnorm(30, 2, .1), b = rnorm(30, .5, .05), sigma = rnorm(30, 1, .1)) | |
g <- ggplot(data.frame(x = c(-1, 5.5)), aes(x)) | |
for(i in 1:nrow(aa)) { | |
g <- g + | |
stat_function(fun = dnorm, args = list(mean = c(aa$a[i] + aa$b[i]), sd = aa$sigma[i]), alpha = 0.3) | |
} | |
g + |
OlderNewer