I hereby claim:
- I am khakieconomics on github.
- I am javage (https://keybase.io/javage) on keybase.
- I have a public key ASCOfa5tiUHOtFlCuiaEWO_BO1GQwq0-7ugZRerDYO_p7go
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
| # A simple script to grab github commits for a list of users and plot | |
| # Group average commits per day for two groups | |
| # To use this script, you'll need to set up a yaml file with credentials | |
| # for github, and set up a google sheet with columns `Github handle` and | |
| #`Attended` (with values "Yes" or "No") | |
| # Author: Jim Savage, Schmidt Futures | |
| # Load libraries | |
| library(tidyverse); library(httr); library(yaml);library(jsonlite); |
| data { | |
| int N; | |
| int N_neg; | |
| int N_pos; | |
| int P; | |
| matrix[N, P] X; | |
| matrix[N, 3] Y_raw; // first column is 0s and 1s | |
| int pos_neg[N_neg]; | |
| int pos_pos[N_pos]; | |
| } |
| data { | |
| int N; // number of individuals | |
| int T; // number of time periods | |
| matrix[N, T] Y; // outcome matrix; missing entries set to -9.0 | |
| int K; // rank of matrix | |
| } | |
| parameters { | |
| matrix[N, K] M; // individual loadings | |
| matrix[T, K] U; // time factors | |
| real<lower = 0> sigma; // error scale |
| functions { | |
| matrix make_pairwise_logit_mat(vector theta) { | |
| matrix[rows(theta), rows(theta)] out; | |
| for(r in 1:rows(out)) { | |
| for(c in 1:r) { | |
| if(r==c) { | |
| out[r, c] = 0; | |
| } else { | |
| out[r, c] = exp(theta[c])/(exp(theta[c]) + exp(theta[r])); |
| data { | |
| int N; // number of observations | |
| int T; // number of time periods | |
| int I; // number of groups | |
| int P; // number of controls | |
| int<lower = 1, upper = T> time[N]; // time index | |
| int<lower = 1, upper = I> group[N]; // group index | |
| vector[N] Y; | |
| matrix[N, P] X; // you should include group/time means in X | |
| } |
| --- | |
| title: "Demo of mouse-over" | |
| output: | |
| flexdashboard::flex_dashboard: | |
| orientation: columns | |
| vertical_layout: fill | |
| --- | |
| ```{r setup, include=FALSE} | |
| library(flexdashboard) |
| 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)) |
| 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)) %>% |
| 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 ------------------------------------------------------ | |