alexkowa / EnvStats

EnvStats — Package for Environmental Statistics, Including US EPA Guidance. Homepage: http://www.probstatinfo.com
https://alexkowa.github.io/EnvStats/
26 stars 8 forks source link

Should there be a `enpar()` to match the other distributions? #22

Closed williamlai2 closed 6 months ago

williamlai2 commented 1 year ago

enparCensored() doesn't work with datasets where there are no censored values. Should there be something to match enorm(), egamma(), elnorm(), etc.?

Or should I be using some other function?

vals <- 1:10
cens <- rep(0, 10)
enparCensored(vals, cens, ci = TRUE)

Error in enparCensored(vals, cens, ci = TRUE) : No censored values indicated by 'censored'.

williamlai2 commented 1 year ago

Or perhaps we just ignore this as distchoose() is only meant to suggest normal, gamma and lognormal?

Though here is suggests 'Nonparametric'. https://github.com/alexkowa/EnvStats/issues/23

SteveMillard commented 7 months ago

Not sure we need a function enpar(). When there are not uncensored observations, you can consider the sample mean as a nonparametric estimator of the population mean, since the sample mean is simply the mean of the empirical cdf. See for example: https://en.wikipedia.org/wiki/Empirical_distribution_function

williamlai2 commented 7 months ago

Yes, I just bootstrapped the detected values to calculate the parameters, but I thought it would be good to have something in there to match the other functions.

SteveMillard commented 7 months ago

Yes, I just bootstrapped the detected values to calculate the parameters, but I thought it would be good to have something in there to match the other functions.

I'm not sure I understand what you mean. If there are no censored values, then you can estimate parameters for any particular distribution as usual. What exactly would you want enpar() to return? If you want to estimate the median and a CI for the median, you can use eqnapr():

> eqnpar(vals, ci = TRUE)

Results of Distribution Parameter Estimation
--------------------------------------------

Assumed Distribution:            None

Estimated Quantile(s):           Median = 5.5

Quantile Estimation Method:      Nonparametric

Data:                            vals

Sample Size:                     10

Confidence Interval for:         50'th %ile

Confidence Interval Method:      interpolate (Nyblom, 1992)

Confidence Interval Type:        two-sided

Confidence Level:                95%

Confidence Limit Rank(s):        2 3 9 8 

Confidence Interval:             LCL = 2.657658
                                 UCL = 8.342342
williamlai2 commented 7 months ago

I think I wanted the LCL and UCL of the mean. Similar to the other functions.

SteveMillard commented 7 months ago

Hi @williamlai2 and @alexkowa , I wrote a function called enpar() that does what I think William wants. Alex, if you want to add this to EnvStats, then I can write a companion Help file as well.

> set.seed(479)
> dat <- rgammaAlt(30, mean = 2, cv = 1)
> 
> enpar(dat)

Results of Distribution Parameter Estimation
--------------------------------------------

Assumed Distribution:            None

Estimated Parameter(s):          mean    = 2.0027422
                                 sd      = 2.0544111
                                 se.mean = 0.3750824

Estimation Method:               Sample Mean

Data:                            dat

Sample Size:                     30

> 
> enpar(dat, ci = TRUE)

Results of Distribution Parameter Estimation
--------------------------------------------

Assumed Distribution:            None

Estimated Parameter(s):          mean    = 2.0027422
                                 sd      = 2.0544111
                                 se.mean = 0.3750824

Estimation Method:               Sample Mean

Data:                            dat

Sample Size:                     30

Confidence Interval for:         mean

Confidence Interval Method:      Bootstrap

Number of Bootstraps:            1000

Confidence Interval Type:        two-sided

Confidence Level:                95%

Confidence Interval:             Pct.LCL = 1.339372
                                 Pct.UCL = 2.722864
                                 BCa.LCL = 1.298334
                                 BCa.UCL = 2.654668
                                 t.LCL   = 1.383849
                                 t.UCL   = 2.989514
alexkowa commented 7 months ago

yes, please. add it.