# Adding new sector uncertainty given dependent parameters

**URL:** https://forum.mimiframework.org/t/adding-new-sector-uncertainty-given-dependent-parameters/228
**Category:** Uncategorized
**Created:** [December 1, 2022, 9:02pm UTC](https://forum.mimiframework.org/t/adding-new-sector-uncertainty-given-dependent-parameters/228 "2022-12-01T21:02:19Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![naomishimberg](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/naomishimberg/32/86_2.png) [@naomishimberg](https://forum.mimiframework.org/u/naomishimberg)
#### Post date: [December 1, 2022, 9:02pm UTC](https://forum.mimiframework.org/t/adding-new-sector-uncertainty-given-dependent-parameters/228/1 "2022-12-01T21:02:19Z")

</div>

I am working to add a new damage sector to MimiGIVE and account for uncertainty. I understand the steps taken in the How To Guide, but curious how to implement given more than one uncertainty parameter, and dependence between parameters.

For example, say in addition to “a”, `new_sector_damages.jl` contains some parameter “b” which is not independent from “a”. In `mcs.jl`, I see how “a” is added with some normal distribution and then connected back to new sector damages.

How would I incorporate “b” here? Would I sample from its own normal distribution using the expected value and standard error of that parameter? How do I account for parameter variance-covariance to jointly sample more than one parameter?

---

<div class="post-metadata">

### Author: ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)
#### Post date: [December 1, 2022, 9:26pm UTC](https://forum.mimiframework.org/t/adding-new-sector-uncertainty-given-dependent-parameters/228/2 "2022-12-01T21:26:01Z")

</div>

Hi @naomishimberg the Mimi documentation on Monte Carlo Simulations [here](https://www.mimiframework.org/Mimi.jl/stable/tutorials/tutorial_5/) and [here](https://www.mimiframework.org/Mimi.jl/stable/howto/howto_3/) will likely help with questions about uncertainty and MCS. I believe you can define correlations between random variables with the Latin Hypercube approach to sampling, or if you have presampled data you can consider using the `SampleStore` type to provide presampled data for the parameters.

---

<div class="post-metadata">

### Author: ![parthum](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/parthum/32/30_2.png) [@parthum](https://forum.mimiframework.org/u/parthum)
#### Post date: [December 8, 2022, 3:22pm UTC](https://forum.mimiframework.org/t/adding-new-sector-uncertainty-given-dependent-parameters/228/3 "2022-12-08T15:22:14Z")

</div>

Hi @naomishimberg. Just so I understand, are you asking about sampling `a` and `b` from a joint distribution? If so, perhaps the [template used](https://github.com/rffscghg/MimiGIVE.jl/blob/eaa9413d70dab7ad339ade0beb8ec734eb27a741/src/main_mcs.jl#L64) for the Howard and Sterner random parameters might be useful to build on? These stem from a multivariate distribution (e.g., parameters in the same regression equation).

---

<div class="post-metadata">

### Author: ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)
#### Post date: [December 9, 2022, 4:27am UTC](https://forum.mimiframework.org/t/adding-new-sector-uncertainty-given-dependent-parameters/228/4 "2022-12-09T04:27:20Z")

</div>

Ah good point @parthum I’d forgotten we had sampling for a joint distribution in the GIVE model already, that’s a good template idea.

---

<div class="post-metadata">

### Author: ![parthum](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/parthum/32/30_2.png) [@parthum](https://forum.mimiframework.org/u/parthum)
#### Post date: [December 9, 2022, 1:57pm UTC](https://forum.mimiframework.org/t/adding-new-sector-uncertainty-given-dependent-parameters/228/5 "2022-12-09T13:57:26Z")

</div>

yeah, we went back and forth about what the best method was. We were leaning towards providing presampled draws (as reference data), which might be better in the case of many parameters since your covariance matrix will get quite large. The H&S parameter set was right on the margin of this tradeoff, and since it was already coded we just stuck with it. Researcher preference I think at that point!

---

<div class="post-metadata">

### Author: ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)
#### Post date: [December 9, 2022, 8:20pm UTC](https://forum.mimiframework.org/t/adding-new-sector-uncertainty-given-dependent-parameters/228/6 "2022-12-09T20:20:09Z")

</div>

It would probably be a good addition to Mimi to have a way to have the MCS functionality draw these on each trial, building it into the more typical `@defsim` structure that we generally use for other IAMs, instead of having to create a `SampleStore`, I can open an Issue to do that but probably won’t have time to do it on your timeline @naomishimberg so the approach there might be wisest.

For background @naomishimberg if you take a look at other models we often just use the `@defsim` macro which abstracts away some of these details, but for `MimiGIVE` the combination of multivariate distributions, resampled data, and other nuances meant we wrote a more verbose construction of the Monte Carlo object.

---

<div class="post-metadata">

### Author: ![naomishimberg](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/naomishimberg/32/86_2.png) [@naomishimberg](https://forum.mimiframework.org/u/naomishimberg)
#### Post date: [December 9, 2022, 8:40pm UTC](https://forum.mimiframework.org/t/adding-new-sector-uncertainty-given-dependent-parameters/228/7 "2022-12-09T20:40:11Z")

</div>

> [@lrennels](#):
>
> k at other models we often just use the `@defsim` macro which abstracts away some of these details, but for `MimiGIVE` the combination of multivariate distributions, resampled data, and other nuances meant we

Thank you for your responses! This all makes sense to me. Could you point me to some guidance on how to create presampled draws for the `SampleStore`? I’ve read the Monte Carlo + SA page on Mimi.jl but it doesn’t go into specifics. I’m only working with 3 parameters in one function and 4 parameters in another, so the covariance matrix is not too large.

---

<div class="post-metadata">

### Author: ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)
#### Post date: [December 12, 2022, 6:36am UTC](https://forum.mimiframework.org/t/adding-new-sector-uncertainty-given-dependent-parameters/228/8 "2022-12-12T06:36:44Z")

</div>

`Mimi.SampleStore` is a type defined in `Mimi` that extends the `Distributions` package type `PseudoDistribution` as shown [here](https://github.com/mimiframework/Mimi.jl/blob/a0e5f0516878c8927233ed05229ae68e6adde12e/src/mcs/mcs_types.jl#L48). The extension involves defining the type, and a few methods including `rand`, `quantile, `length`, and a few others.

It is defined such that when `rand` is called on the `SampleStore` type the function returns the next value in the provided vector of values.

So if you create a SampleStore

```auto
d = SampleStore([1,2,3,4,5])

```

and then call `rand` you get

```auto
rand(d)
1
rand(d)
2
rand(d) 
3

```

etcetera. You can therefore use the `SampleStore` type to define a Distribution that is assigned to a random variable, just like you would with any other Distribution (`Normal`, etc.). This is useful for presampled draws, or in the case we point out above draws that are sampled in a function when creating the Monte Carlo Simulation object.

The `main_mcs.jl` file in MimiGIVE uses these quite a bit, I’m not sure which other models take advantage of them yet although I’m sure a few do.
