spatial-ews / spatialwarnings

An R package to compute spatial early-warning signals of ecosystem degradation
Other
14 stars 4 forks source link

Find a way to use the choice of xmin in plot_distr() #106

Closed alexgenin closed 9 months ago

alexgenin commented 2 years ago

Right now the points corresponding to the observed distribution of patch sizes do not reflect the choice of xmin set by the user. Those points should be either discarded from the plot, or distributions fits should be scaled down to reflect the fact that they only fit on a subset of the data (and make a plot à la Clauset 2009 Fig 8, with distributions overlaid only on a subset of the data).

There are also a few minor glitches due to the fact that iptpl()/ptpl()/etc. return different things for points below the xmin size (sometimes NA, sometimes bogus probabilities). This behavior should be made consistent.

jguerber commented 2 years ago

I tried some possibilities, i think a quite quick way to fix the y axis is to just shift the fitted distributions: #107 In my opinion, keeping all the data points is important to visualize the PL range, we kind of miss this information on the plot when we subset the observed data.

For the weird iptpl().. behavior i feel like predict() already does the work well. I haven't checked on a lot of cases though. Glitches appear sometimes when calling those functions separately but the package does not seem to be really meant to be used like this ?

alexgenin commented 2 years ago

Thanks Josquin! I'll have a look at your code when I can and come back to you ;)

jguerber commented 2 years ago

Thanks for having a look ! Using approx to get the intercept is really nice, i had forgotten it existed !

I hope that merging did not make any problems appear but from what i checked it looks correct.

alexgenin commented 9 months ago

Alright, I think this is fixed now, it will be included in the next spatialwarnings release.

alexgenin commented 9 months ago

It is actually already on CRAN, but closing anyway <3