Created
April 25, 2017 16:29
-
-
Save sachsmc/240367f4b946b2163e422b448e115d4d to your computer and use it in GitHub Desktop.
trial level sampling
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
X <- rnorm(n, 1) | |
Y <- -.5 + 1.5 * X + rnorm(n, sd = .5) | |
enns <- sample(ceiling(runif(n, 200, 2000))) | |
samp.indi.data <- function(i) { | |
Z <- rbinom(enns[i], 1, .5) | |
mu.S <- 2.5 + X[i] * Z | |
lambda.T <- -1 + Y[i] * Z | |
S <- rnorm(enns[i], mean = mu.S) | |
T <- rpois(enns[i], exp(lambda.T)) | |
data.frame(Z, S, T) | |
} | |
library(arm) | |
s1 <- bayesglm(S ~ Z, data = test) | |
zpost <- sim(s1, n.sims = 1000)@coef[, 2] | |
indi.datasets <- lapply(1:n, samp.indi.data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment