prctile function vs excel percentile (2024)

30 views (last 30 days)

Show older comments

Nick on 24 Mar 2015

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/184895-prctile-function-vs-excel-percentile

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/184895-prctile-function-vs-excel-percentile

Answered: Chan Dennis on 23 Dec 2018

Accepted Answer: John D'Errico

Hi,

when I run the below,

A = [ 0.02; 0.01 ; 0.01; 0.01 ; 0.04 ]; B = prctile(A,99.95);

I get B = 0.0400, which seems rounded.

In excel the same percentile function produces a result of 0.03996

Is there a way to show a less rounded result in matlab? Any other function or calculation in matlab e.g. 65/43, will produce a result (1.5116) that doesn't round the decimals like prctile does.

(even if I try "format long" the result will still be 0.040000000...)

Many thanks

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Accepted Answer

John D'Errico on 24 Mar 2015

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/184895-prctile-function-vs-excel-percentile#answer_172541

Edited: John D'Errico on 24 Mar 2015

Open in MATLAB Online

This is the behavior as it is designed to do. READ THE HELP.

1) The sorted values in X are taken as the 100*(0.5/N), 100*(1.5/N),

..., 100*((N-0.5)/N) percentiles.

2) Linear interpolation is used to compute percentiles for percent

values between 100*(0.5/N) and 100*((N-0.5)/N)

3) The minimum or maximum values in X are assigned to percentiles

for percent values outside that range.

Thus, for 5 data points, anything above the 90th percentile is returned as the highest element in your vector.

In Excel, the difference is it is NOT the SAME percentile function. Two different people wrote those codes, to two different sets of specifications. The Excel percentile function treats 0.04 as the 100% point. In MATLAB, it is treated as the 90th percentile.

Think of it as if you put each of those numbers into bins. In MATLAB, when you have 5 numbers, MATLAB assigns the 80-100% bin to 0.04, the highest element in the vector, but above 90%, it chooses not to extrapolate. This was clearly a design choice.

B = prctile(A,79:100)

B =

Columns 1 through 11

0.029 0.03 0.031 0.032 0.033 0.034 0.035 0.036 0.037 0.038 0.039

Columns 12 through 22

0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04

Never make the mistake of assuming that two functions in two different languages are the same, that they should produce the same results, even if they have similar names and goals.

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

More Answers (2)

Chan Dennis on 23 Dec 2018

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/184895-prctile-function-vs-excel-percentile#answer_353667

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/184895-prctile-function-vs-excel-percentile#answer_353667

Open in MATLAB Online

Today, I also meet the issue, and find the article in Wikipedia (Percentile).

Clearly, both percentile alogrithms are the different cases of the linear interpolation between closest ranks method. More details in Percentile - Wikipedia.

  • When let C=0.5, the result is equal prctile function in matlab.
  • When let C=1, the result is equal excel percentile.

There are two matlab functions below, which are the implementations of the above algorithms.

prctile_one.m (resuls equal excel PERCENTILE and PERCENTILE.INC)

function V_x = prctile_one(V,p)

% The linear interpolation between closest ranks method in the case of `C=1`

% [Percentile - Wikipedia](https://en.wikipedia.org/wiki/Percentile)

if ~isvector(p) || numel(p) == 0 || any(p < 0 | p > 1) || ~isreal(p)

error('Make sure the Second digit within the [0,1] interval');

end

V = sort(V,'ascend');

N = length(V);

x = p*(N-1)+1; % position x

if floor(x) < N

V_x = V(floor(x)) + mod(x,1)*(V(floor(x)+1) - V(floor(x))); % value

else

V_x = V(N); % position N

end

prctile_half.m (resuls equal matlab prctile)

function V_x = prctile_half(V,p)

% The linear interpolation between closest ranks method in the case of `C=0.5`

% [Percentile - Wikipedia](https://en.wikipedia.org/wiki/Percentile)

if ~isvector(p) || numel(p) == 0 || any(p < 0 | p > 1) || ~isreal(p)

error('Make sure the Second digit within the [0,1] interval');

end

V = sort(V,'ascend');

N = length(V);

p_1 = 1/(2*N); % position 1

p_N = 1 - 1/(2*N); % position N

if p_1<=p && p<=p_N

x = N*p + 0.5; % position x

V_x = V(floor(x)) + mod(x,1)*(V(floor(x)+1) - V(floor(x))); % value

else if 0<=p && p<p_1

V_x = V(1); % value 1

else if p_N<p && p<=1

V_x = V(N); % value N

end

end

end

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Nick on 24 Mar 2015

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/184895-prctile-function-vs-excel-percentile#answer_172568

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/184895-prctile-function-vs-excel-percentile#answer_172568

Edited: Nick on 24 Mar 2015

Thanks for the in depth reply. After doing some research, apparently there are at least 9 different methods to calculate percentiles, although excel's seems to be the most popular amongst software packages.

1 Comment

Show -1 older commentsHide -1 older comments

John D'Errico on 24 Mar 2015

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/184895-prctile-function-vs-excel-percentile#comment_274351

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/184895-prctile-function-vs-excel-percentile#comment_274351

Personally, I might have chosen the Excel scheme. The highest datapoint seems like it should be 100%, the smallest, 0%. But I can see entirely valid arguments for doing it other ways.

Of course, were I truly the author of the code, I would have offered multiple schemes, and let the user pick among them as options. But then I tend to overdo those things as an author.

Sign in to comment.

Sign in to answer this question.

See Also

Categories

AI, Data Science, and StatisticsStatistics and Machine Learning ToolboxDescriptive Statistics and VisualizationDescriptive Statistics

Find more on Descriptive Statistics in Help Center and File Exchange

Tags

  • prctile

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


prctile function vs excel percentile (6)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

Contact your local office

prctile function vs excel percentile (2024)

FAQs

Should I use percentile inc or exc? ›

You use the PERCENTILE. EXC function to determine the percentile exclusive of the first and last values in the array, and you use the PERCENTILE. INC function to determine the percentile inclusive of the first and last values in the array. Both formulas use the same arguments.

Does Excel percentile ignore blanks? ›

The PERCENTILE function will ignore blanks.

Does Excel have a percentile function? ›

The PERCENTILE Function[1] is categorized under Excel Statistical functions. PERCENTILE will return the k-th percentile of the values in a particular range. In corporate finance, we can use the function to analyze, for example, the number of employees who scored above a certain percentile on a test.

What is the difference between Inc and EXC in Excel percentile rank? ›

INC—includes the first and last values. PERCENTILE. EXC—excludes the first and last values.

Should I use quartile exc or inc? ›

EXC functions both find a requested quartile of a supplied data set. The difference between these two functions is that QUARTILE. INC bases its calculation on a percentile range of 0 to 1 inclusive, whereas QUARTILE. EXC bases its calculation on a percentile range of 0 to 1 exclusive.

What does percentile Inc tell you? ›

INC function. Returns the k-th percentile of values in a range, where k is in the range 0..1, inclusive.

Does percentile inc include blanks? ›

INC considers the blank values returned by Expression. This behavior is different from PERCENTILE. INC, which ignores the blank values.

What is the difference between quantile and percentile in Excel? ›

Quantiles are important statistical measures, they are simple to understand. The 0.5-quantile is the value such that half of the sample is below and the other half is above. It is also called the median. A quantile is called a percentile when it is based on a 0-100 scale.

What is the opposite of percentile function in Excel? ›

INC( <column>, k ). If k = 0.5 then they would return the 50th percentile. PERCENTRANK in Excel is the inverse of PERCENTILE in that, for a given value (that may not appear in the array) it returns the rank expressed as a percentage.

How do I rank data by percentile in Excel? ›

The syntax is =PERCENTRANK(range, value) . 'Range' represents the dataset, and 'value' is the specific data point for which you want to find the percentile rank.

What is the difference between percentile and percentage rank? ›

A percentage denotes a mathematical value taken out of 100, such as marks obtained in the exam by a student is 80%. The percentile will show rank-ordering out of others in a sample. For example, he has scored 40% more than other students.

What does 80th percentile mean? ›

For example, a data point that falls at the 80th percentile has a value greater than 80 percent of the data points within the dataset. Percentiles are frequently used when reporting on data, particularly in standardized testing, where a raw score may be less meaningful to educators and students than a percentile score.

When should I use percentile exc? ›

EXC interpolates to determine the value at the k-th percentile. PERCENTILE. EXC will interpolate when the value for the specified percentile lies between two values in the array. If it cannot interpolate for the percentile, k specified, Excel will return #NUM!

What is the difference between inclusive and exclusive percentiles in Excel? ›

Inclusive evaluate all values in the data from the smallest value to the largest value. Exclusive evaluates all values in the data between the smallest value and the largest value. The smallest value is calculated as 1/n and the largest value is calculated as 1-1/n where n is the number of listed items.

What is the formula for percentile? ›

How do you calculate percentile? Percentile is found with the equation: P = n/N * 100%. Where P is the percentile, lower case n is the number of data points below the data point of interest, and N is the total number of data points in the data set.

Is percentile inclusive or exclusive? ›

Percentile ranks are exclusive: if the percentile rank for a specified score is 90%, then 90% of the scores were lower. In contrast, for percentiles a percentage is given and a corresponding score is determined, which can be either exclusive or inclusive.

Is it better to score in a higher percentile? ›

For any given score, your percentile or percentile rank describes what percentage of the testing population you scored higher than. For example, a score in the 70th percentile is higher than 70% of all the scores for that population. When it comes to test scores, the higher the percentile, the better you are doing!

What is the rule for percentiles? ›

Percentiles show how a given value compares to others. The general rule is that if a value is in the kth percentile, it is greater than K per cent of the total values.

Which is more important percentile or percentage? ›

The key difference between percentage and percentile is the percentage is a mathematical value presented out of 100 and percentile is the per cent of values below a specific value. The percentage is a means of comparing quantities. A percentile is used to display position or rank.

Top Articles
Latest Posts
Article information

Author: The Hon. Margery Christiansen

Last Updated:

Views: 5865

Rating: 5 / 5 (70 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: The Hon. Margery Christiansen

Birthday: 2000-07-07

Address: 5050 Breitenberg Knoll, New Robert, MI 45409

Phone: +2556892639372

Job: Investor Mining Engineer

Hobby: Sketching, Cosplaying, Glassblowing, Genealogy, Crocheting, Archery, Skateboarding

Introduction: My name is The Hon. Margery Christiansen, I am a bright, adorable, precious, inexpensive, gorgeous, comfortable, happy person who loves writing and wants to share my knowledge and understanding with you.