# Predict or parametric bootstrap for a generalized mixed model

**URL:** <https://discourse.julialang.org/t/predict-or-parametric-bootstrap-for-a-generalized-mixed-model/30855>\
**Category:** Statistics\
**Tags:** question\
**Created:** [November 8, 2019, 10:40am UTC](https://discourse.julialang.org/t/predict-or-parametric-bootstrap-for-a-generalized-mixed-model/30855 "2019-11-08T10:40:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [November 8, 2019, 10:40am UTC](https://discourse.julialang.org/t/predict-or-parametric-bootstrap-for-a-generalized-mixed-model/30855/1 "2019-11-08T10:40:20Z")

</div>

I want to fit a generalized mixed model to a dataset where the dependent variable is velocity (continuous positive numbers), the random variable is the subject ID, and the predictor is distance to some point (also a continuous positive number).  
Here’s a contrived MWE:

```julia
using MixedModels, DataFrames, Distributions

n = 1000 # number of obs
x = 100rand(n) # predictor
y = 5rand(Gamma(), n) .+ rand(n).*x/100 # dependent 
data = DataFrame(x = x, y = y, id = rand(1:5, n)) # the data frame
categorical!(data, :id) # make the random variable a categorical one

m = fit(MixedModel, @formula(y ~ 1 + x + (1|id)), data, Gamma()) # fit the model

```

Apart from the `P` value, I’d also like to plot the confidence interval area around the fit, something like this (image arbitrarily stolen from [here](https://www.staringatr.com/the-grammar-of-graphics/scatter-plots/2_plottinglines/)):

 ![image](https://global.discourse-cdn.com/julialang/original/3X/2/5/250344351fbcf0496fe2e5f537a616d006ca0e02.png)

How do I get those bounds from a Generalized Mixed Model like `m`?

---

<div class="post-metadata">

**Author:** ![dave.f.kleinschmidt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dave.f.kleinschmidt/32/55_2.png) [@dave.f.kleinschmidt](https://discourse.julialang.org/u/dave.f.kleinschmidt)\
**Post date:** [November 11, 2019, 10:59pm UTC](https://discourse.julialang.org/t/predict-or-parametric-bootstrap-for-a-generalized-mixed-model/30855/2 "2019-11-11T22:59:39Z")

</div>

I think @dmbates has implemented parametric bootstrapping, at least for `LinearMixedModel` but maybe not for `GeneralizedLinearMixedModel`: [https://dmbates.github.io/MixedModels.jl/latest/bootstrap/](https://dmbates.github.io/MixedModels.jl/latest/bootstrap/)

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [November 12, 2019, 7:43am UTC](https://discourse.julialang.org/t/predict-or-parametric-bootstrap-for-a-generalized-mixed-model/30855/3 "2019-11-12T07:43:43Z")

</div>

> [@dave.f.kleinschmidt](#):
>
> implemented parametric bootstrapping, at least for `LinearMixedModel`

Yes (docs are [here](https://dmbates.github.io/MixedModels.jl/stable/bootstrap/#The-parametric-bootstrap-1)), but I want it for a Gamma link function. So my only options (after some discussion on Slack) are to just use a Gaussian link function instead (thus using a `LinearMixedModel`) and/or removing the random effect by calculating the mean within subject ID.
