User Tools

Site Tools



This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
gams:compute_the_median_of_a_parameter_s_values [2009/05/29 12:52]
support created
— (current)
Line 1: Line 1:
-====== How do I compute the median of a parameter'​s values? ====== 
-The code fragment below  was contributed by Tom Rutherford to the[[http://​​maillist/​gams_l.htm|GAMS User List]], an example for multidimensional data is available on his web site [[http://​​mdrank.htm|]]. 
-$title ​ Finding the Median of a Distribution in GAMS 
-set     ​i ​      ​Individuals /i1*i1000/; 
-alias (i,j); 
-parameter ​      ​income(i) ​      ​Personal income, 
-                rank(i) ​        ​Income rank, 
-                median ​         Median income; 
-*       Make it random for the purpose of illustration:​ 
-income(i) = uniform(0,​1);​ 
-*       This is ugly and slow, but it works: 
-rank(i) = sum(j$(income(j) gt income(i)), 1) + 1; 
-* In this example there will be no ties, there could be a tie in an arbitrary 
-* application. ​ Just to be safe,  divide through by the number of 
-* median individuals:​ 
-median = sum(i$(rank(i) eq round(card(i)/​2)),​ income(i)) 
-            / sum(i$(rank(i) eq round(card(i)/​2)),​ 1); 
-display median; 
IMPRESSUM / LEGAL NOTICEPRIVACY POLICY gams/compute_the_median_of_a_parameter_s_values.1243594343.txt.gz ยท Last modified: 2009/05/29 12:52 by support