Skip to content

Instantly share code, notes, and snippets.

View lwiklendt's full-sized avatar

Lukasz Wiklendt lwiklendt

View GitHub Profile
# testing effect of correlated predictors on non-linearity when assuming a linear model
rho = 0.9
N = 20
set.seed(1)
# generate correlated x1 and x2 predictors
z = matrix(rnorm(N*2, 0, 1), 2)
L = t(chol(matrix(c(1, rho, rho, 1), 2)))
x = L %*% z
@lwiklendt
lwiklendt / pystan_vb_extract.py
Last active November 11, 2020 18:58
Extract parameter samples from PyStan's vb method, so that it resembles extract() from the sampling method
import numpy as np
from collections import OrderedDict
def pystan_vb_extract(results):
param_specs = results['sampler_param_names']
samples = results['sampler_params']
n = len(samples[0])
# first pass, calculate the shape
param_shapes = OrderedDict()