-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bootstrap p_value, CI for hindcasts #108
Comments
@bradyrx could you please also provide the CESM-LE with all members?
|
Yes, I'll add that if I have time today. This is not required for #107, correct? |
no, just for this future PR about bootstraping uninit. I will also try to add some miklip global output. |
@bradyrx For the perfect-model I don't have different input lenghts. Therefore I also cannot reproduce |
I wrote a few tests which a The existing function based on # check for useful output? now only checks if gets through
def test_compute_reference_non_continuous():
"""Test non continuous inits."""
assert not compute_reference_mod(dple.sel(init=dple.init.values[::2]), ersst).isnull().any()
test_compute_reference_non_continuous()
def test_compute_reference_random_order():
"""Test random inits as in resampling without replacement."""
inits=np.copy(dple.init.values)
np.random.shuffle(inits)
assert not compute_reference_mod(dple.sel(init=inits), ersst.sel(time=inits)).isnull().any()
test_compute_reference_random_order()
# compute_reference gives results around 0 on not detrended inputs
def test_compute_reference_inits_with_replacement():
"""Test resampling with replacement as needed for bootstrapping."""
inits = dple.init.values
inits = np.random.choice(inits, size=len(inits))
assert not compute_reference_mod(dple.sel(init=inits), ersst).isnull().any()
test_compute_reference_inits_with_replacement()
def compute_reference_mod(ds,
reference,
metric='pearson_r',
comparison='e2r'):
check_xarray(ds)
check_xarray(reference)
nlags = ds.lead.size
comparison = get_comparison_function(comparison)
if comparison not in [_e2r, _m2r]:
raise ValueError("""Please input either 'e2r' or 'm2r' for your
comparison.""")
forecast, reference = comparison(ds, reference)
metric = get_metric_function(metric)
if metric not in [_pearson_r, _rmse, _mse, _mae]:
raise ValueError("""Please input 'pearson_r', 'rmse', 'mse', or
'mae' for your metric.""")
# think in real time dimension: real time = init + lag
forecast = forecast.rename({'init':'time'})
# take only inits for which we have references at all leads
imin = max(forecast.time.min(), reference.time.min())
imax = min(forecast.time.max(), reference.time.max()-nlags)
forecast = forecast.where(forecast.time <= imax, drop=True)
forecast = forecast.where(forecast.time >= imin, drop=True)
reference = reference.where(reference.time >= imin, drop=True)
assert forecast.time.max() - nlags <= reference.time.max()
plag = []
# iterate over all leads (accounts for lead.min() in [0,1])
for i in forecast.lead.values:
# take lead year i timeseries and convert to real time
a = forecast.sel(lead=i)
a['time']=[t+i for t in a.time.values]
# take real time reference of real time forecast years
b = reference.sel(time=a.time.values)
plag.append(metric(a, b, dim='time'))
skill = xr.concat(plag, 'lead')
skill['lead'] = dple.lead.values
return skill This new function gives (slightly) different results, as all lead years have the same number of init/time (see comment above). @bradyrx Is this new function acceptable to you? It follows the same line of thought as before, but doesnt trim time/init as before to get the most possible for each The bootstrapping then just follows naturally. |
Overview of results. I am unsure which of the results is more important to you. I tend to ignore the not detrended results as this skill is artificial due to external forcing. For CESM output the skill degrades compared to before (Just this GMSST case here!). I tried to compare The main reasoning behind my approach is that @bradyrx: Please have a look into the |
This was in the gitter, reproduced here. In answer to why I wrote it the way I did. Hopefully this is what you were asking.
|
If I have time at home tonight I will review your code snippet. Otherwise I will review once it is a PR. |
based on bootstrap_perfect_model (Goddard et al. 2013)
gives: p_value, skill, ci for init, uninit, pers
The text was updated successfully, but these errors were encountered: