[LON-CAPA-cvs] cvs: modules /gerd/discussions eval.pl

www lon-capa-cvs@mail.lon-capa.org
Thu, 31 Mar 2005 16:47:04 -0000


www		Thu Mar 31 11:47:04 2005 EDT

  Modified files:              
    /modules/gerd/discussions	eval.pl 
  Log:
  Error calc
  
  
Index: modules/gerd/discussions/eval.pl
diff -u modules/gerd/discussions/eval.pl:1.6 modules/gerd/discussions/eval.pl:1.7
--- modules/gerd/discussions/eval.pl:1.6	Thu Mar 31 09:59:49 2005
+++ modules/gerd/discussions/eval.pl	Thu Mar 31 11:47:04 2005
@@ -43,16 +43,21 @@
     $disc{$i.'c'}=18+$i;
     $disc{$i.'d'}=26+$i;
 }
-# overall stats
+my $sumall=35;
+
+#
+# Read Files
+#
 my %questiontypes=();
 my %disctypes=();
-# read file
+
 foreach my $class ('lbs271','lbs272','phy231') {
     print "\nReading $class";
     open(IN,'raw/'.$class.'.csv');
     my $num=0;
     my $numdisc=0;
     while (my $line=<IN>) {
+        my $thisnumdisc=0;
 	$line=~s/\s+$//;
         my @entries=split(/\,/,$line);
         if ($entries[15]!~/^\d[a-d]$/) { next; }
@@ -70,7 +75,9 @@
 	    $newentry[$disc{$qtype}]++;
             $disctypes{$qtype}++;
             $numdisc++;
+            $thisnumdisc++;
 	}
+        $newentry[$sumall]=$thisnumdisc;
         push @q,join(',',@newentry);
     }
     close(IN);
@@ -78,35 +85,113 @@
 }
 print "\nReading done.\n";
 # Overall Stats
-print "\n==== Question Types\n";
-for (my $i=1;$i<=7;$i++) { print ','.$i; }
+print "\n==== Question Types\n".&padded();
+for (my $i=1;$i<=7;$i++) { print ','.&padded($i); }
 foreach ('a','b','c') {
-    print "\n$_";
+    print "\n".&padded($_);
     for (my $i=1;$i<=7;$i++) {
-	print ','.$questiontypes{$i.$_};
+	print ','.&padded($questiontypes{$i.$_});
     }
 }
-print "\n==== Discussion Types\n";
-for (my $i=1;$i<=8;$i++) { print ','.$i; }
+print "\n==== Discussion Types\n".&padded();
+for (my $i=1;$i<=8;$i++) { print ','.&padded($i); }
 foreach ('a','b','c','d') {
-    print "\n$_";
+    print "\n".&padded($_);
     for (my $i=1;$i<=8;$i++) {
-	print ','.$disctypes{$i.$_};
+	print ','.&padded($disctypes{$i.$_});
     }
 }
 #
 # Analysis
 #
+my %statmean=();
+my %staterr=();
+my %statsum=();
+my %statn=();
+my %statsumsquare=();
 
+#
+# Compute means and errors
+#
+
+foreach my $error (0,1) {
+    foreach (@q) {
+	my @entries=split(/\,/,$_);
+	my $diffidx=int($entries[$diff]*10+0.5);
+	&callsums('emotion&diff'.$diffidx,$error,@entries);
+	&callsums('procedural&diff'.$diffidx,$error,@entries);
+	&callsums('physics&diff'.$diffidx,$error,@entries);
+	&callsums('conceptual&diff'.$diffidx,$error,@entries);
+    }
+}
+
+#
+# Output
+#
+print "\n\n==== Difficulty\n";
+for (my $i=0;$i<=10;$i++) {
+    print "\n".&padded($i).','.
+                      &reportout('emotion&diff'.$i).',',
+                      &reportout('procedural&diff'.$i).',',
+                      &reportout('physics&diff'.$i).',',
+                      &reportout('conceptual&diff'.$i);
+}
 print "\n";
 
 
 # ======== End analysis, subroutines
 
-sub twodec {
-   my ($val,$count)=@_;
-   unless ($count) { return ''; }
-   return int($val/$count*100+0.5);
+sub callsums {
+    my ($which,$error,@entries)=@_;
+    unless ($error) {
+	&meansum($which,@entries);
+    } else {        
+	&meansumsquared($which,@entries);
+    }
+}
+
+sub meansum {
+   my ($which,@entries)=@_;
+   unless ($entries[$sumall]) { return; }
+   $statn{$which}++;
+   my ($routine,$cat)=split(/\&/,$which);
+   no strict 'refs';
+   my $num=&$routine(@entries);
+   use strict 'refs';
+   $statsum{$which}+=$num/$entries[$sumall];
+}
+
+sub meansumsquared {
+   my ($which,@entries)=@_;
+   unless ($entries[$sumall]) { return; }
+   unless ($statn{$which}) { return; }
+   my ($routine,$cat)=split(/\&/,$which);
+   no strict 'refs';
+   my $num=&$routine(@entries);
+   use strict 'refs';
+   $statsumsquare{$which}+=($num/$entries[$sumall]-$statsum{$which}/$statn{$which})**2;
+}
+
+sub reportout {
+   my $which=shift;
+   my $value='';
+   if ($statn{$which}>0) {
+       $value=&percent($statsum{$which}/$statn{$which});
+   }
+   my $error='';
+   if ($statn{$which}>1) {
+       $error=&percent(sqrt($statsumsquare{$which}/($statn{$which}*($statn{$which}-1))));
+   }
+   return &padded($value).','.&padded($error);
+}
+
+sub padded {
+   return substr('       '.shift,-5,5);
+}
+ 
+sub percent {
+    my $val=shift;
+   return int($val*1000+0.5)/10;
 }
 
 sub allcount {