Analyze data with the Statistics software R: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
 
(8 intermediate revisions by one other user not shown)
Line 8: Line 8:
* radius-minimax estimator: green (optimally robust; cf. Rieder et al. (2008))<br /><br />
* radius-minimax estimator: green (optimally robust; cf. Rieder et al. (2008))<br /><br />
By changing the y-position of the four movable points you should recognize the instability (non-robustness) of mean and standard deviation in contrast to the robust estimates; e.g., move one of the four movable points to the top of the plot.<br /><br />
By changing the y-position of the four movable points you should recognize the instability (non-robustness) of mean and standard deviation in contrast to the robust estimates; e.g., move one of the four movable points to the top of the plot.<br /><br />
<html>
<link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/prototype.js"></script>
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
<div id="jxgbox" class="jxgbox" style="width:700px; height:400px;" onmouseup="doIt();"></div>
</html>
===Online results:===
===Online results:===
<html><script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/prototype.js"></script></html>
<pre id='output'>Statistics:<br></pre>
<pre id='output'>Statistics:<br></pre>
<html>
<jsxgraph width="700" height="400">
<script language="JavaScript">
         brd = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-0.15, 60, 11.15, -20],axis:true});
         brd = JXG.JSXGraph.initBoard('jxgbox', {originX: 20, originY: 300, unitX: 60, unitY: 5,axis:true});
         brd.suspendUpdate();
         brd.suspendUpdate();
         var graph1,graph2,graph3,graph4,graph5,graph6,graph7,graph8,graph9;
         var graph1,graph2,graph3,graph4,graph5,graph6,graph7,graph8,graph9;
Line 39: Line 33:
                 y[6+i] = 10+z2*3;
                 y[6+i] = 10+z2*3;
                 x[6+i] = 6+i;
                 x[6+i] = 6+i;
                 p[i] = brd.createElement('point', [x[i],y[i]],{name:' ',fixed:true,style:7});  
                 p[i] = brd.createElement('point', [x[i],y[i]],{name:' ',fixed:true,size:2,face:'[]'});  
                 p[6+i] = brd.createElement('point', [x[6+i],y[6+i]],{name:' ',fixed:true,style:7});
                 p[6+i] = brd.createElement('point', [x[6+i],y[6+i]],{name:' ',fixed:true,size:2,face:'[]'});
             }else{
             }else{
                 y[i] = 10+z1*3;
                 y[i] = 10+z1*3;
                 p[i] = brd.createElement('point', [x[i],y[i]],{name:' ',fixed:true,style:7});  
                 p[i] = brd.createElement('point', [x[i],y[i]],{name:' ',fixed:true,size:2,face:'[]'});  
             }
             }
         }
         }
Line 67: Line 61:
         brd.removeObject(p[9]);
         brd.removeObject(p[9]);
          
          
         p[0] = brd.createElement('glider', [x[0],y[0],l[0]],{name:' ',style:6});  
         p[0] = brd.createElement('glider', [x[0],y[0],l[0]],{name:' ',size:4,face:'o'});  
         p[10] = brd.createElement('glider', [x[10],y[10],l[1]],{name:' ',style:6});  
         p[10] = brd.createElement('glider', [x[10],y[10],l[1]],{name:' ',size:4,face:'o'});  
         p[8] = brd.createElement('glider', [x[8],y[8],l[2]],{name:' ',style:6});  
         p[8] = brd.createElement('glider', [x[8],y[8],l[2]],{name:' ',size:4,face:'o'});  
         p[9] = brd.createElement('glider', [x[9],y[9],l[3]],{name:' ',style:6});  
         p[9] = brd.createElement('glider', [x[9],y[9],l[3]],{name:' ',size:4,face:'o'});  
         brd.unsuspendUpdate();
         brd.unsuspendUpdate();


Line 82: Line 76:
                 t += p[i].Y() + ';';
                 t += p[i].Y() + ';';
             }
             }
             new Ajax.Request('/~mkohl/rserv.php', {
             new Ajax.Request('/~alfred/jsxgraph/examples/rserv.php', {
                 method:'post',
                 method:'post',
                 parameters:'input='+escape(t),
                 parameters:'input='+escape(t),
Line 94: Line 88:
                         var sd = a[1]*1.0;
                         var sd = a[1]*1.0;
                         var med = a[2]*1.0;
                         var med = a[2]*1.0;
                        var mad = a[3]*1.0;
                         var mad = a[3]*1.0;
                         var mad = a[3]*1.0;
                         var est1 = a[4]*1.0;
                         var est1 = a[4]*1.0;
                         var est2 = a[5]*1.0;
                         var est2 = a[5]*1.0;
                         if (!graph2) {  
                         if (!graph2) {  
                             graph2 = brd.createElement('curve', [[x[0],x[x.length-1]],[m,m]], {strokecolor:'red'});  
                             graph2 = brd.createElement('curve', [[x[0],x[x.length-1]],[m,m]], {strokecolor:'red'});  
Line 120: Line 114:
                         }
                         }


                         $('output').innerHTML = '<b><font size="+1">Normal location and scale:</font></b><br /><br />'+  
                         document.getElementById('output').innerHTML = '<b><font size="+1">Normal location and scale:</font></b><br /><br />'+  
                                 '<b>Estimates for location (true value = 10):</b><br />' +
                                 '<b>Estimates for location (true value = 10):</b><br />' +
                                 'Mean = ' + brd.round(m,2) + '<br />' +
                                 'Mean = ' + Math.round(m,2) + '<br />' +
                                 'Median = ' + brd.round(med,2) + '<br />' +
                                 'Median = ' + Math.round(med,2) + '<br />' +
                                 'Radius-minimax estimator = ' + brd.round(est1,2) + '<br /><br />' +
                                 'Radius-minimax estimator = ' + Math.round(est1,2) + '<br /><br />' +
                                 '<b>Estimates for scale (true value = 3):</b><br />' +
                                 '<b>Estimates for scale (true value = 3):</b><br />' +
                                 'Standard deviation = ' + brd.round(sd,2) + '<br />' +
                                 'Standard deviation = ' + Math.round(sd,2) + '<br />' +
                                 'MAD = ' + brd.round(mad,2) + '<br />' +  
                                 'MAD = ' + Math.round(mad,2) + '<br />' +  
                                 'Radius-minimax estimator = ' + brd.round(est2,2) + '<br />';
                                 'Radius-minimax estimator = ' + Math.round(est2,2) + '<br />';
                         brd.update();
                         brd.update();
                     };
                     };
                 }});
                 }});
         }
         }
</script>
brd.addHook(doIt, 'mouseup');
</html>
</jsxgraph>


=== The underlying source code ===
=== The underlying source code ===
Line 151: Line 145:
* [http://en.wikipedia.org/wiki/Robust_statistics Wikipedia on Robust Statistics]
* [http://en.wikipedia.org/wiki/Robust_statistics Wikipedia on Robust Statistics]


[[Category:Examples]]
[[Category:Old]]
[[Category:Statistics]]

Latest revision as of 12:55, 18 October 2024

Normal Location and Scale

This litte application sends the y-coordinates of the points which are normal distributed (pseudo-)random numbers to the server.
There, location and scale of the sample are estimated using the Statistics software R.
The return values are plotted and displayed.

The computed estimates are:

  • mean, standard deviation: red (non-robust!)
  • median and MAD: black (most-robust!)
  • radius-minimax estimator: green (optimally robust; cf. Rieder et al. (2008))

By changing the y-position of the four movable points you should recognize the instability (non-robustness) of mean and standard deviation in contrast to the robust estimates; e.g., move one of the four movable points to the top of the plot.

Online results:

Statistics:<br>

The underlying source code

The underlying JavaScript and PHP code

The R script can be downloaded here.

References

  • The Costs of not Knowing the Radius, Helmut Rieder, Matthias Kohl and Peter Ruckdeschel, Statistical Methods and Application 2008 Feb; 17(1): p.13-40; cf. also [1] for an extended version.
  • Robust Asymptotic Statistics, Helmut Rieder, Springer, 1994.
  • Numerical Contributions to the Asymptotic Theory of Robustness, Matthias Kohl, PhD-Thesis, University of Bayreuth, 2005; cf. also [2].

External links