User Tools

Site Tools


gams:compute_the_median_of_a_parameter_s_values

Differences

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

Link to this comparison view

gams:compute_the_median_of_a_parameter_s_values [2009/05/29 12:52] (current)
support created
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://​www.gams.com/​maillist/​gams_l.htm|GAMS User List]], an example for multidimensional data is available on his web site [[http://​www.mpsge.org/​mdrank.htm|mpsge.org]].
 +
 +<​code>​
 +$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;
 +</​code>​
IMPRESSUM / LEGAL NOTICEPRIVACY POLICY gams/compute_the_median_of_a_parameter_s_values.txt ยท Last modified: 2009/05/29 12:52 by support