This file contains hidden or 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
| functions { | |
| matrix L_cov_exp_quad_ARD(matrix x, | |
| real alpha, | |
| vector rho, | |
| real delta) { | |
| int N = rows(x); | |
| matrix[N, N] K; | |
| real sq_alpha = square(alpha); | |
| for (i in 1:(N-1)) { | |
| K[i, i] = sq_alpha + delta; |
This file contains hidden or 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
| # First load the libraries and define a function to create a | |
| library(tidyverse); library(rstan) | |
| set.seed(78) | |
| ard_Sigma <- function(features, rho, alpha) { | |
| noise <- 1e-8 | |
| features <- as.data.frame(features) | |
| P <- ncol(features) | |
| if(length(rho) != P) { |
This file contains hidden or 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
| functions { | |
| // B function | |
| vector B(vector x, vector t, int i, int j_p1); | |
| vector B(vector x, vector t, int i, int k) { | |
| vector[rows(x)] out; | |
| vector[rows(x)] a_i1j1; | |
| vector[rows(x)] a_ij1; | |
This file contains hidden or 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
| # This script checks that the b-spline function in gist https://gist.github.com/khakieconomics/2272cd7f0d61950852622198b26a2d02 | |
| # produces something approximating the function in the splines package. | |
| library(rstan) | |
| expose_stan_functions("b_spline_function.stan") | |
| probs <- runif(1000) | |
| probs <- probs[order(probs)] | |
This file contains hidden or 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
| functions { | |
| // B function | |
| vector B(vector x, vector t, int i, int j_p1); | |
| vector B(vector x, vector t, int i, int k) { | |
| vector[rows(x)] out; | |
| vector[rows(x)] a_i1j1; | |
| vector[rows(x)] a_ij1; | |
This file contains hidden or 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
| functions { | |
| vector inverse_mills(vector z) { | |
| vector[rows(z)] out; | |
| for(i in 1:rows(z)) { | |
| out[i] = exp(normal_lpdf(z[i] | 0, 1)) / (Phi(z[i])); | |
| } | |
| return(out); | |
| } | |
| } |
This file contains hidden or 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(tidyverse) | |
| # A utility function | |
| extract_pars <- function(mle_fit, pars) { | |
| unlist(lapply(pars, function(n) mle_fit$par[grepl(pattern = n, x = names(mle_fit$par))])) | |
| } | |
| # Simulate fake data ------------------------------------------------------ | |
This file contains hidden or 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(tidyverse); library(lfe) | |
| some_data <- expand.grid(time = 1:10, individual = 1:200) %>% | |
| left_join(data_frame(time = 1:10, time_effects= rnorm(10))) %>% | |
| left_join(data_frame(individual = 1:200, individual_effects= rnorm(200))) %>% | |
| mutate(treatment = sample(0:1, n(), replace = T), | |
| outcome = time_effects + individual_effects + 1 * treatment + rnorm(n())) %>% | |
| group_by(time) %>% | |
| mutate(demeaned_outcome = outcome - mean(outcome), | |
| demeaned_treatment = treatment - mean(treatment)) %>% |
This file contains hidden or 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(tidyverse); library(rstan) | |
| # Some fake data | |
| Individuals <- 1000 | |
| Sims <- 1000 | |
| Months <- 20 | |
| initial_values <- data.frame(customer_id = 1:Individuals, initial_value = rnorm(Individuals)) |
This file contains hidden or 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
| --- | |
| title: "Demo of mouse-over" | |
| output: | |
| flexdashboard::flex_dashboard: | |
| orientation: columns | |
| vertical_layout: fill | |
| --- | |
| ```{r setup, include=FALSE} | |
| library(flexdashboard) |