JeschkeLab / DeerLab-Matlab

Data analysis and method development toolbox for dipolar EPR spectroscopy
MIT License
4 stars 2 forks source link

Parse CI-fit to fitsignal #95

Closed laenan8466 closed 4 years ago

laenan8466 commented 4 years ago

Current Design

Currently the CI is only given as CI parameters as return value of fitsignal:

[Vfit,Pfit,Bfit,parfit,parci,stats] = fitsignal(V,t,r,dd,bg,ex,par0)

parci contains the CI of background (depends on selected model, e.g. concentration), experiment (e.g. modulation depth) and distance distribution (none in case of regularization).

As far as I understood, fitsignal calls fitregmodel or fitparamodel internally, also using several performance boosters. (Does a great job btw. Amazing work!) Output of these functions are fitci or Pci (same thing I guess). This output goes without performance loss. These parameters aren't passed as output of fitsignal. More important in my point of view would be the CI for regularization methods, as parametrized models have CI for the dd-parameters included.

Proposed behavior

When my assumptions above are valid (are they? 😄 ), these could easily passed as output. This is clearly connected to Issue #90 and would be propably solved by the reffered issue. Adding the output on a short notice would be a workaround and should only be implemented, if it doesn't take a long time.

Further missing outputs

I didn't found an output for alpha as well.

My current Workaround

Warning: Will not work with current version. See as outdated. Here is my current workaround for this. Clearly this yields different CI than the original fitsignal (tested for a parametrized model with the parci.dd) but the difference is only small.

Parametrized models

As I'm mainly intersted in the parameters, I use the from fitsignal given ci-parameters. This is fine so far. If this is not enough, one could use this:

%% Confidence interval
% Calculate Kernel with background from fitsignal
K = dipolarkernel(t,r,parfit.ex(1),bg_hom3d(t,parfit.bg,parfit.ex(1)));

% Do another fit with start parameters from fitsignal (parfit.dd).
[~,~,~,fitci,~] = fitparamodel(V,gausswlc,r,K,parfit.dd');

Regularization models

%% Confidence interval
% Calculate Kernel with background from fitsignal
K = dipolarkernel(t,r,parfit.ex(1),bg_hom3d(t,parfit.bg,parfit.ex(1)));

% Do another fit with background fit from fitsignal.
[~,fitci,alpha,~] = fitregmodel(V,K,r,'tikhonov','aic');

Downside in this case could be the visible increase in calculation time.

laenan8466 commented 4 years ago

Update: In the current version 0.9.1 (7cc4f309412ed4d14aa10856a51dd77fa73619fb), the parci-output of fitsignal gives back the upper and lower limit of Vfit, Bfit and Pfit. Thank's for implementing this! Two things I noticed:

  1. ~fitsignal is now missing the parameter CIs. So for background, experiment, distance model (distance model only with parametric fit) uncertainties we do not get the upper and lower limit from fitsignal. That would be great to reimplement.~ Update: This is now in an additional output haven't looked there. [Vfit,Pfit,Bfit,parfit,modfitci,parci,stats]. Related to #92
  2. The cell structure is a bit nested. Whereas Pfit is a 1x2 cell for upper and lower, Vfit and Bfit are within a 1x1 cell, containing a 1x2 cell. I would prefer the Pfit-version with a 1x2-cell on top.
  3. In the cell structure there are two nx2 arrays contained. Both containing upper/lower limits, I guess with different confident intervalls. Not sure which one is which. Related to #92 Update: Having looked into the source: ConfidenceLevel = [0.95 0.5];
luisfabib commented 4 years ago

With the new system for confidence intervals and al the changes in fitsignal these issues have been solved.