Rev 539 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
539 | bpr | 1 | !goto $wims_read_parm |
2 | |||
3 | :def |
||
4 | title=Data median |
||
5 | synonyme=statistic median, median of statistics |
||
6 | input=data1d |
||
7 | !exit |
||
8 | |||
9 | :proc |
||
10 | |||
11 | cnt=!itemcnt $formula |
||
12 | fml= |
||
13 | !for i=1 to $cnt |
||
14 | t=!item $i of $formula |
||
15 | fml=!append item $[$t] to $fml |
||
16 | !next i |
||
17 | fml=!sort numeric item $fml |
||
18 | !if $[$cnt%2]=1 |
||
19 | result=!item $[($cnt+1)/2] of $fml |
||
20 | !else |
||
21 | t1=!item $[$cnt/2] of $fml |
||
22 | t2=!item $[$cnt/2+1] of $fml |
||
23 | result=$[($t1+$t2)/2] |
||
24 | !endif |
||
25 | |||
26 | !exit |
||
27 | |||
28 | :output |
||
29 | |||
6515 | bpr | 30 | <p class="wimscenter"> |
539 | bpr | 31 | Median = |
32 | !htmlmath $result |
||
6515 | bpr | 33 | </p> |
539 | bpr | 34 | Data: $cnt numbers { $formula } |
35 | <p> |
||
6515 | bpr | 36 | The <em>median</em> of sorted data |
37 | \(\{x_1, x_2, ..., x_n\}\) |
||
38 | is equal to |
||
539 | bpr | 39 | !set ins_align=middle |
6515 | bpr | 40 | !insmath \frac{x_{n/2}+x_{n/2+1}}{2} |
41 | when \(n\) is even, or to \(x_{\frac{n+1}{2}}\) |
||
42 | when \(n\) is odd. |
||
43 | </p> |
||
539 | bpr | 44 | !exit |