# Reproducibility

Now that you've completed (and passed!) some Markov chain diagnostics, you're ready to finalize your `RJAGS`

simulation. To this end, reproducibility is crucial. To obtain reproducible simulation output, you must set the seed of the `RJAGS`

random number generator. This works differently than in base `R`

. Instead of using `set.seed()`

, you will specify a starting seed using `inits = list(.RNG.name = "base::Wichmann-Hill", .RNG.seed = ___)`

when you *compile* your model.

This is a part of the course

## “Bayesian Modeling with RJAGS”

### Exercise instructions

Run the provided code a few times. Notice that the

`summary()`

statistics change each time.For reproducible results, supply the random number generator

`inits`

to`jags.model()`

. Specify a starting seed of 1989.Run the new code a few times. Notice that the

`summary()`

statistics do NOT change!

### Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

```
# COMPILE the model
sleep_jags <- jags.model(textConnection(sleep_model), data = list(Y = sleep_study$diff_3))
# SIMULATE the posterior
sleep_sim <- coda.samples(model = sleep_jags, variable.names = c("m", "s"), n.iter = 10000)
# Summarize the m and s chains of sleep_sim
summary(sleep_sim)
```

This exercise is part of the course

## Bayesian Modeling with RJAGS

In this course, you'll learn how to implement more advanced Bayesian models using RJAGS.

The two-parameter Normal-Normal Bayesian model provides a simple foundation for Normal regression models. In this chapter, you will engineer the Normal-Normal and define, compile, and simulate this model using rjags. You will also explore the magic of the Markov chain mechanics behind rjags simulation.

Exercise 1: The Normal-Normal modelExercise 2: Normal-Normal priorsExercise 3: Sleep study dataExercise 4: Insights from the prior and dataExercise 5: Simulating the Normal-Normal in RJAGSExercise 6: Define, compile, & simulate the Normal-NormalExercise 7: Posterior insights on sleep deprivationExercise 8: Markov chainsExercise 9: Storing Markov chainsExercise 10: Markov chain trace plotsExercise 11: Markov chain density plotsExercise 12: Markov chain diagnostics & reproducibilityExercise 13: Multiple chainsExercise 14: Naive standard errorsExercise 15: Reproducibility### What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.