Exercises

  1. Using PyMC3, change the parameters of the prior beta distribution in our_first_model to match those of the previous chapter. Compare the results to the previous chapter. Replace the beta distribution with a uniform one in the interval [0,1]. Are the results equivalent to the ? Is the sampling slower, faster, or the same? What about using a larger interval such as [-1, 2]? Does the model run? What errors do you get?
  2. Read about the coal mining disaster model that is part of the PyMC3 documentation: http://pymc-devs.github.io/pymc3/notebooks/getting_started.html#Case-study-2:-Coal-mining-disasters. Try to implement and run this model by yourself.
  1. Modify model_g, change the prior for the mean to a Gaussian distribution centered at the empirical mean, and play with a couple of reasonable values for the standard deviation of this prior. How robust/sensitive are the inferences to these changes? What do you think of using a Gaussian, which is an unbounded distribution (goes from -∞ to ∞), to model bounded data such as this? Remember that we said it is not possible to get values below 0 or above 100.
  2. Using the data in the chemical_shifts.csv file, compute the empirical mean and the standard deviation with and without outliers. Compare those results to the Bayesian estimation using the Gaussian and Student's t-distribution. Repeat the exercise by adding more outliers.
  3. Modify the tips example to make it robust to outliers. Try with one shared for all groups and also with one  per group. Run posterior predictive checks to assess these three models.
  4. Compute the probability of superiority directly from the posterior (without computing Cohen's d first). You can use the pm.sample_posterior_predictive() function to take a sample from each group. Is it really different from the calculation assuming normality? Can you explain the result?
  5. Repeat the exercise we did with model_h. This time, without hierarchical structure, use a flat prior such as . Compare the results of both models.
  6. Create a hierarchical version of the tips example by partially pooling across the days of the week. Compare the results to those obtained without the hierarchical structure.
  7. PyMC3 can create directed acyclic graphs (DAGs) from models that are very similar to Kruschke's diagrams. You can obtain them using the pm.model_to_graphviz() function. Generate a DAG for each model in this chapter.

Besides the exercises you will find at the end of each chapter, you can always try to (and probably should) think of problems you are interested in and how to apply what you have learned to that problem. Maybe you will need to define your problem in a different way, or maybe you will need to expand or modify the models you have learned. If you think this task is beyond your actual skills, note down the problem and come back to it after reading another chapter in this book. Eventually, if the book does not answer your questions, check the PyMC3 examples (http://pymc-devs.github.io/pymc3/examples.html) or ask a question at https://discourse.pymc.io/.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.89.30