[LON-CAPA-cvs] cvs: modules /gerd evaluate.pl
www
lon-capa-cvs@mail.lon-capa.org
Thu, 06 Jul 2006 19:02:06 -0000
www Thu Jul 6 15:02:06 2006 EDT
Modified files:
/modules/gerd evaluate.pl
Log:
* Library routine starts with array index 0
* Subroutine to produce scatter plots
Index: modules/gerd/evaluate.pl
diff -u modules/gerd/evaluate.pl:1.12 modules/gerd/evaluate.pl:1.13
--- modules/gerd/evaluate.pl:1.12 Thu Jul 6 13:39:15 2006
+++ modules/gerd/evaluate.pl Thu Jul 6 15:02:01 2006
@@ -628,6 +628,9 @@
print "\n";
+
+# &scatterplot(\%fcipost,'',\%mpexpostscore,'total',\@userkeys);
+
exit;
#
# Calculate correlation between two hashes
@@ -646,6 +649,16 @@
return " $label: $c ($n)";
}
+sub scatterplot {
+ my ($array1,$arrayidx1,$array2,$arrayidx2,$userkeys)=@_;
+ print "\nScatter\n\n";
+ my ($x,$y)=&buildarrays($array1,$arrayidx1,$array2,$arrayidx2,$userkeys);
+ for (my $idx=0;$idx<=$#$x;$idx++) {
+ print "\n".$$x[$idx].",".$$y[$idx];
+ }
+ print "\n";
+}
+
#
# Build arrays x and y
#
@@ -660,9 +673,9 @@
my $secondindex=$user;
if ($arrayidx2) { $secondindex.=':'.$arrayidx2; }
if ((defined($$array1{$firstindex})) && (defined($$array2{$secondindex}))) {
- $index++;
$x[$index]=$$array1{$firstindex};
$y[$index]=$$array2{$secondindex};
+ $index++;
}
}
return (\@x,\@y);
@@ -677,30 +690,3 @@
my $co= new Statistics::Basic::Correlation($x,$y);
return ($co->query,$#$x+1);
}
-
-
-sub old_correlation {
- my ($x,$y)=@_;
- my $sum_sq_x = 0;
- my $sum_sq_y = 0;
- my $sum_coproduct = 0;
- my $mean_x = $$x[1];
- my $mean_y = $$y[1];
- my $last_x = $$x[1];
- my $last_y = $$y[1];
- foreach my $i (2 .. $#$x) {
- my $sweep = ($i - 1.0) / $i;
- my $delta_x = $$x[$i] - $mean_x;
- my $delta_y = $$y[$i] - $mean_y;
- $sum_sq_x += $delta_x * $delta_x * $sweep;
- $sum_sq_y += $delta_y * $delta_y * $sweep;
- $sum_coproduct += $delta_x * $delta_y * $sweep;
- $mean_x += $delta_x / $i;
- $mean_y += $delta_y / $i;
- }
- if (($sum_sq_x==0) || ($sum_sq_y==0)) { return (0,$#$x); }
- my $pop_sd_x = sqrt( $sum_sq_x / $#$x );
- my $pop_sd_y = sqrt( $sum_sq_y / $#$x );
- my $cov_x_y=$sum_coproduct / $#$x;
- return ($cov_x_y / ($pop_sd_x * $pop_sd_y),$#$x+1);
-}