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(data.table) | |
library(purrr) | |
set.seed(12345) | |
x <- rnorm(100) | |
x[sample(1:100, size = 50)] = NA | |
df <- data.table(matrix(x, nrow=10)) | |
df[, columnA:=rep(letters[1:5], 2)] | |
df[, list(n_missings=map_dbl(.SD, ~(mean(is.na(.x))<0.33))%>%sum), by='columnA'] |
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
''' | |
define and run a latent variable model | |
''' | |
import numpyro | |
from jax import numpy as np, random | |
from jax.scipy.special import logsumexp | |
from numpyro import distributions as dist | |
from numpyro.distributions import constraints | |
from numpyro.handlers import mask, substitute, trace, seed |
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
#' Latent confounder model | |
# dag: | |
#' W1 <- U -> W2 | |
#' tx -> y | |
#' U -> y | |
#' U -> tx | |
library(lavaan) |
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
''' | |
define and run a latent variable model, everything gaussian, with posterior predictive on newdata | |
for a description of the model see twitter thread: https://twitter.com/WvanAmsterdam/status/1251214875394740226?s=20 | |
DAG: | |
W1 <- U -> W2 # latent confounder with 2 proxies | |
U -> tx | |
U -> y | |
tx -> 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
# Ordinal regression with ImproperUniform | |
from jax import numpy as np, random | |
import numpyro | |
from numpyro import sample | |
from numpyro.distributions import constraints, Normal, ImproperUniform, Categorical, OrderedLogistic | |
from numpyro.infer.mcmc import NUTS, MCMC | |
import pandas as pd | |
num_chains = 4 |