news.utdallas.edu!convex!tchrist Tue Dec 15 10:08:26 CST 1992 Article: 64 of comp.lang.perl Xref: feenix.metronet.com comp.lang.perl:64 Newsgroups: comp.lang.perl Path: feenix.metronet.com!news.utdallas.edu!convex!tchrist From: Tom Christiansen #Subject: Re: Statistic routines ? Originator: tchrist@pixel.convex.com Sender: usenet@news.eng.convex.com (news access account) Message-ID: <1992Dec15.155017.14450@news.eng.convex.com> Date: Tue, 15 Dec 1992 15:50:17 GMT Reply-To: tchrist@convex.COM (Tom Christiansen) References: Nntp-Posting-Host: pixel.convex.com Organization: Convex Computer Corporation, Colorado Springs, CO Keywords: statistic X-Disclaimer: This message was written by a user at CONVEX Computer Corp. The opinions expressed are those of the user and not necessarily those of CONVEX. Lines: 65 >From the keyboard of lendl@cosy.sbg.ac.at (Otmar Lendl): :I have to do some statistical analysis of data I gather with :perl scripts, so it would be convenient to use perl for that :purpose, too. : :Before I start to write my own set of functions (Mean, standard-deviation, :histograms, ...) I better ask if there are already such beasts. :I checked the script-archives listed in the FAQs (convex, ohio-state), :but could not find anything suitable. Here's something I hacked out yesterday. The format is titlea b c d e where the letters are the number of scores of value 1..5; --tom #/usr/bin/perl $[ = 1; while (<>) { if (/^\s*$/) { print; next; } $v = $mean = $sum = $n = $sdev = 0; ($title, $figures) = /^([^\t]+)\t+(.*)/; split(' ',$figures); for ($i = 1; $i <= 5; $i++) { $n += $_[$i]; $sum += $i * $_[$i]; } $mean = $sum / $n; for ($i = 1; $i <= 5; $i++) { for ($j = 0; $j < $_[$i]; $j++) { $v += ($mean - $i) ** 2; } } $v /= $n; $sdev = sqrt($v); write; } format STDOUT_TOP = Course Title N Mean Std Dev ========================== === ===== ======= . format STDOUT = @<<<<<<<<<<<<<<<<<<<<<<<<< @## @#.## @#.## $title, $n, $mean, $sdev . -- Tom Christiansen tchrist@convex.com convex!tchrist Even if you aren't in doubt, consider the mental welfare of the person who has to maintain the code after you, and who will probably put parens in the wrong place. --Larry Wall in the perl man page