-
Notifications
You must be signed in to change notification settings - Fork 2
/
jags_interactive.Rd
61 lines (50 loc) · 1.42 KB
/
jags_interactive.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data.R
\docType{data}
\name{jags_interactive}
\alias{jags_interactive}
\title{Fitted JAGS interactive linear model}
\format{
A class "rjags" object created by [R2jags::jags()]
}
\usage{
jags_interactive
}
\description{
A fitted JAGS linear model with interaction term generated with
[R2jags::jags()]. See the example code below for how it was created. Used
in examples and for testing.
}
\examples{
\donttest{
data("sim_data_interactive")
## formatting the data for jags
datjags <- as.list(sim_data_interactive)
datjags$N <- length(datjags$Y)
## creating jags model
model <- function() {
for(i in 1:N){
Y[i] ~ dnorm(mu[i], sigma) ## Bernoulli distribution of y_i
mu[i] <- b[1] +
b[2] * X1[i] +
b[3] * X2[i] +
b[4] * X1[i] * X2[i]
}
for(j in 1:4){
b[j] ~ dnorm(0, 0.001) ## Use a coefficient vector for simplicity
}
sigma ~ dexp(1)
}
params <- c("b")
inits1 <- list("b" = rep(0, 4))
inits2 <- list("b" = rep(0, 4))
inits <- list(inits1, inits2)
## fitting the model with R2jags
set.seed(123)
jags_interactive <- R2jags::jags(data = datjags, inits = inits,
parameters.to.save = params, n.chains = 2,
n.iter = 2000, n.burnin = 1000,
model.file = model)
}
}
\keyword{datasets}