[ 
https://issues.apache.org/jira/browse/MATH-1551?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17165142#comment-17165142
 ] 

institute for information industry edited comment on MATH-1551 at 7/26/20, 1:05 
AM:
------------------------------------------------------------------------------------

I have fixed the errors you mentioned and add test functions.

[Code|[https://github.com/iii-org-tw/commons-math/blob/MATH-1551-WeightedPercentile/src/main/java/org/apache/commons/math4/stat/descriptive/rank/Percentile.java]]

[Test|#L868https://github.com/iii-org-tw/commons-math/blob/MATH-1551-WeightedPercentile/src/test/java/org/apache/commons/math4/stat/descriptive/rank/PercentileTest.java]

By the way, I found the original code will cause unexpected results.

 
{code:java}
Percentile p = new Percentile(). Percentile p = new Percentile().    
                                                
withEstimationType(Percentile.EstimationType.R_7).
                                                
withNaNStrategy(NaNStrategy.MAXIMAL);
double[] dataset = { 3, 4, Double.NaN };
p.setData(dataset);
System.out.println(p.evaluate(50));
-------------------------------------------------------------------------------------------
NaN{code}
 

It got NaN which we expect to be Infinity because getWorkArray

do nothing when the input array is the storedData.


was (Author: iii-org-tw):
I have fixed the errors you mentioned and add test functions.

[Percentile|[https://github.com/iii-org-tw/commons-math/blob/MATH-1551-WeightedPercentile/src/main/java/org/apache/commons/math4/stat/descriptive/rank/Percentile.java]]

[Test|[https://github.com/iii-org-tw/commons-math/blob/b6594baec8b6666d96ea7ecac1880e9b6999c369/src/test/java/org/apache/commons/math4/stat/descriptive/rank/PercentileTest.java#L868https://github.com/iii-org-tw/commons-math/blob/MATH-1551-WeightedPercentile/src/test/java/org/apache/commons/math4/stat/descriptive/rank/PercentileTest.java|https://github.com/iii-org-tw/commons-math/blob/MATH-1551-WeightedPercentile/src/test/java/org/apache/commons/math4/stat/descriptive/rank/PercentileTest.java]]

 

By the way, I found the original code will cause unexpected results.

 
{code:java}
Percentile p = new Percentile(). Percentile p = new Percentile().    
                                                
withEstimationType(Percentile.EstimationType.R_7).
                                                
withNaNStrategy(NaNStrategy.MAXIMAL);
double[] dataset = { 3, 4, Double.NaN };
p.setData(dataset);
System.out.println(p.evaluate(50));
-------------------------------------------------------------------------------------------
NaN{code}
 

It got NaN which we expect to be Infinity because getWorkArray

do nothing when the input array is the storedData.

> Compute Percentile with Weighted Samples
> ----------------------------------------
>
>                 Key: MATH-1551
>                 URL: https://issues.apache.org/jira/browse/MATH-1551
>             Project: Commons Math
>          Issue Type: New Feature
>    Affects Versions: 4.0
>            Reporter: institute for information industry
>            Priority: Major
>              Labels: features, newbie
>             Fix For: 4.0
>
>         Attachments: Percentile.java
>
>
> The class Percentile only support estimation on non-weighted samples.
> I've implement some function to estimate percentiles of weighted samples.
> here is the reference: 
> [https://stats.stackexchange.com/questions/13169/defining-quantiles-over-a-weighted-sample]!https://mail.google.com/mail/u/0?ui=2&ik=6059a2f2a6&attid=0.1&permmsgid=msg-a:r-8896240918589631988&th=1737bdaafc3e228f&view=fimg&sz=s0-l75-ft&attbid=ANGjdJ_GwCQ-hqi0o7ZJTEqcl6JLYbFiR2Y1sqxPL8jDNzheraAkX0beEUtAM4BYI2v_5XGvzCPj2gTBQutHT9bF8hYh7MgdiGYZhn0HtDuVswuCSuwy8aJVsvy3EqI&disp=emb&realattid=ii_kcyrjgea0!
>  
> When all weights are equal to each other, it works like estimation on 
> non-weighted samples under R-7.
> I can't find formulas for other rules but at least, now it can evaluate 
> percentile for weighted samples.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to