Skip to content

Commit

Permalink
dwelltime: make standard errors private
Browse files Browse the repository at this point in the history
  • Loading branch information
JoepVanlier committed Dec 3, 2024
1 parent 3c5f15b commit f04e1fe
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 35 deletions.
1 change: 0 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* Added parameter `titles` to customize title of each subplot in [`Kymo.plot_with_channels()`](https://lumicks-pylake.readthedocs.io/en/latest/_api/lumicks.pylake.kymo.Kymo.html#lumicks.pylake.kymo.Kymo.plot_with_channels).
* Added [`KymoTrack.sample_from_channel()`](https://lumicks-pylake.readthedocs.io/en/latest/_api/lumicks.pylake.kymotracker.kymotrack.KymoTrack.html#lumicks.pylake.kymotracker.kymotrack.KymoTrack.sample_from_channel) to downsample channel data to the time points of a kymotrack.
* Added support for file names with spaces in [`lk.download_from_doi()`](https://lumicks-pylake.readthedocs.io/en/latest/_api/lumicks.pylake.download_from_doi.html#lumicks.pylake.download_from_doi).
* Added `err_amplitudes` and `err_lifetimes` to [`DwelltimeModel`](https://lumicks-pylake.readthedocs.io/en/latest/_api/lumicks.pylake.DwelltimeModel.html). These return asymptotic standard errors and should only be used for well identified models.

#### Improvements

Expand Down
1 change: 0 additions & 1 deletion lumicks/pylake/kymotracker/tests/test_kymotrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,6 @@ def test_fit_binding_times_nonzero(blank_kymo, blank_kymo_track_args):
np.testing.assert_equal(dwelltime_model.dwelltimes, [4, 4, 4, 4])
np.testing.assert_equal(dwelltime_model._observation_limits[0], 4)
np.testing.assert_allclose(dwelltime_model.lifetimes[0], [0.4])
np.testing.assert_allclose(dwelltime_model.err_lifetimes[0], 0.199994, rtol=1e-5)


def test_fit_binding_times_empty():
Expand Down
34 changes: 3 additions & 31 deletions lumicks/pylake/population/dwelltime.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def n_components(self):
"""Number of components in the model."""
return self.model.n_components

def plot(self, alpha=None, *, with_stderr=False, **kwargs):
def plot(self, alpha=None, **kwargs):
"""Plot the profile likelihoods for the parameters of a model.
Confidence interval is indicated by the region where the profile crosses the chi squared
Expand All @@ -209,11 +209,11 @@ def plot(self, alpha=None, *, with_stderr=False, **kwargs):
Significance level. Confidence intervals are calculated as 100 * (1 - alpha)%. The
default value of `None` results in using the significance level applied when
profiling (default: 0.05).
with_stderr : bool
Also show bounds based on standard errors.
"""
import matplotlib.pyplot as plt

with_stderr = kwargs.pop("with_stderr") if "with_stderr" in kwargs else False

std_errs = self.model._std_errs[~np.isnan(self.model._std_errs)]
if self.n_components == 1:
next(iter(self.profiles.values())).plot(
Expand Down Expand Up @@ -632,34 +632,6 @@ def lifetimes(self):
"""Lifetime parameter (in time units) of each model component."""
return self._parameters[self.n_components :]

@property
def err_amplitudes(self):
"""Asymptotic standard error estimate on the model amplitudes.
Returns an asymptotic standard error on the amplitude parameters. These error estimates
are only reliable for estimates where a lot of data is available and the model does
not suffer from identifiability issues. To verify that these conditions are met, please
use either :meth:`DwelltimeModel.profile_likelihood()` method or
:meth:`DwelltimeModel.calculate_bootstrap()`.
Note that `np.nan` will be returned in case the parameter was either not estimated or no
error could be obtained."""
return self._std_errs[: self.n_components]

@property
def err_lifetimes(self):
"""Asymptotic standard error estimate on the model lifetimes.
Returns an asymptotic standard error on the amplitude parameters. These error estimates
are only reliable for estimates where a lot of data is available and the model does
not suffer from identifiability issues. To verify that these conditions are met, please
use either :meth:`DwelltimeModel.profile_likelihood()` method or
:meth:`DwelltimeModel.calculate_bootstrap()`.
Note that `np.nan` will be returned in case the parameter was either not estimated or no
error could be obtained."""
return self._std_errs[self.n_components :]

@property
def rate_constants(self):
"""First order rate constant (units of per time) of each model component."""
Expand Down
2 changes: 0 additions & 2 deletions lumicks/pylake/population/tests/test_dwelltimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,6 @@ def test_std_errs(exponential_data, exp_name, n_components, ref_std_errs):
discretization_timestep=dataset["parameters"].dt,
)
np.testing.assert_allclose(fit._std_errs, ref_std_errs, rtol=1e-4)
np.testing.assert_allclose(fit.err_amplitudes, ref_std_errs[:n_components], rtol=1e-4)
np.testing.assert_allclose(fit.err_lifetimes, ref_std_errs[n_components:], rtol=1e-4)


@pytest.mark.parametrize("n_components", [2, 1])
Expand Down

0 comments on commit f04e1fe

Please sign in to comment.