Exercise

# Computing the b-value

The *b*-value is a common metric for the seismicity of a region. You can imagine you would like to calculate it often when working with earthquake data. For tasks like this that you will do often, it is best to write a function! So, write a function with signature `b_value(mags, mt, perc=[2.5, 97.5], n_reps=None)`

that returns the *b*-value and (optionally, if `n_reps`

is not `None`

) its confidence interval for a set of magnitudes, `mags`

. The completeness threshold is given by `mt`

. The `perc`

keyword argument gives the percentiles for the lower and upper bounds of the confidence interval, and `n_reps`

is the number of bootstrap replicates to use in computing the confidence interval.

Instructions

**100 XP**

- Define a function with signature
`b_value(mags, mt, perc=[2.5, 97.5], n_reps=None)`

that does the following:- Slice magnitudes out of
`mags`

at and above the completeness threshold`mt`

using Boolean indexing. Store the result in the variable`m`

. - Compute the best estimate of the
*b*-value. Remember, the best estimate for the*b*-value is*b*= (*m*-*m*)·ln(10). Store the result in the variable_{t}`b`

. - if
`n_reps`

is not None, do the following.- Draw
`n_reps`

bootstrap replicates of the mean of`m`

. Store the result in the variable`m_bs_reps`

. - Convert the bootstrap replicates of the mean of
`m`

to replicates of the*b*-value. Store the result in`b_bs_reps`

. - Compute the confidence interval from the bootstrap replicates of the
*b*-value. Store the result in`conf_int`

.

- Draw
- Return
`b`

and`conf_int`

, or just`b`

if`n_reps`

is`None`

.

- Slice magnitudes out of