#!/usr/bin/perl -w # reads taalperc.log questionnaire data, # normalizes and pools it. EA 5 Dec 2001. my $nr = 1; my %sentences; # $hash(index) my %users; my $NONE = 99; # value for "n/a" my $maxsent = 0; ############################################################ open(LOGFILE,") { chomp; tr/\&/\;/; $dings = $_; if ($dings =~ /=/) { @parts = split(/\;/,$dings); foreach (@parts) { ($a,$b) = split(/=/,$_); if ($a eq "who") { print "Results of $b\n"; } else { ($a1,$a2,$a3,$a4) = split(/\./,$a); # sentence.intended.script.selection # scripts 1..3 are experiment 1, 4..6 are experiment 2 $a3 =~ tr/123456/111222/; if ($a1 > $maxsent) { $maxsent = $a1; } if (($a2 < 1) || ($a2 > 3)) { die "Ouch... case not 1..3\n"; } if (($a3 < 1) || ($a3 > 2)) { die "Ouch... experiment 1..2\n"; } if (($a4 < 1) || ($a4 > 3)) { die "Ouch... case not 1..3\n"; } $sentences{$nr . "." . $a1 . "." . $a2 . "." . $a3 . "." . $a4} = $b; # subject.and-so-on # store value for one item } } $nr = $nr+1; # next subject }; # else date } close(LOGFILE); my $subj = $nr; $maxsent = $maxsent + 1; ############################################################ # next, we normalize the data for each subject $nr = 1; my $sum = 0; my $cnt = 0; my $adj = 0; my $i; my $j; for ($s=1;$s<$subj;$s++) # for all subjects { print "Normalizing Subject $s ... "; $sum = 0.0; $cnt = 0; $adj = 0.0; for ($sent=1;$sent<$maxsent;$sent++) { # for all sentences for ($i=1;$i<=3;$i++) { # for all intended cases for ($j=1;$j<=2;$j++) { # for all scripts for ($case=1;$case<=3;$case++) { # for all cases $a = "" . $s . "." . $sent . "." . $i . "." . $j . "." . $case; if (defined $sentences{$a}) { $sum = $sum + $sentences{$a}; $cnt = $cnt + 1 } } } } } if ($cnt==0) { die "Div by zero in average\n"; } $adj = 0.0 - ($sum / $cnt); # subtract average to make it 0 printf "Sum %3.3f in %3.3f, Adjust: add %3.3f\n", $sum, $cnt, $adj; $sum = 0; for ($sent=1;$sent<$maxsent;$sent++) { # for all sentences for ($i=1;$i<=3;$i++) { # for all intended cases for ($j=1;$j<=2;$j++) { # for all scripts for ($case=1;$case<=3;$case++) { # for all cases $a = "" . $s . "." . $sent . "." . $i . "." . $j . "." . $case; if (defined $sentences{$a}) { $sentences{$a} = $sentences{$a} + $adj; $sum = $sum + ($sentences{$a} * $sentences{$a}); # sum squares of (value-mean) after making mean 0 } } } } } if (($cnt==0) || ($sum==0)) { die "Div by zero in variance\n"; } $sum = $sum / (0.0 + $cnt); printf "Variance is %5.5f ", $sum; $sum = sqrt($sum); $adj = 1.0 / $sum; # divide by std dev to make std dev 1.0 printf "Standard Deviation is %5.5f, Adjust: multiply by %5.5f\n", $sum, $adj; for ($sent=1;$sent<$maxsent;$sent++) { # for all sentences for ($i=1;$i<=3;$i++) { # for all intended cases for ($j=1;$j<=2;$j++) { # for all scripts for ($case=1;$case<=3;$case++) { # for all cases $a = "" . $s . "." . $sent . "." . $i . "." . $j . "." . $case; if (defined $sentences{$a}) { $sentences{$a} = $sentences{$a} * $adj; } } } } } } # subject loop ############################################################ ############################################################ # next, we are lazy and combine to get the mean and sd for # each outcome (of 3) for each intension (of 3) # in each experiment (of 2), not caring for sentences and # subjects in particular. NEW! # we do, however, count the data points on which we are based. my %results; # a hash my $dst = ""; for ($case=1;$case<=3;$case++) { # outcomes for ($i=1;$i<=3;$i++) { # intensions for ($j=1;$j<=2;$j++) { # experiments $dst = "" . $j . "." . $i . "." . $case; $results{$dst . ".mean"} = 0.0; $results{$dst . ".sqsum"} = 0.0; $results{$dst . ".count"} = 0; } } } print "Calculating mean and standard deviation per \n"; for ($case=1;$case<=3;$case++) { # outcomes for ($i=1;$i<=3;$i++) { # intensions for ($j=1;$j<=2;$j++) { # experiments for ($s=1;$s<$subj;$s++) { # subjects for ($sent=1;$sent<$maxsent;$sent++) { # sentences $a = "" . $s . "." . $sent . "." . $i . "." . $j . "." . $case; $dst = "" . $j . "." . $i . "." . $case; if (defined($sentences{$a})) { $results{$dst . ".mean"} += $sentences{$a}; $results{$dst . ".count"} = $results{$dst . ".count"} + 1; } } } } } } for ($case=1;$case<=3;$case++) { # outcomes for ($i=1;$i<=3;$i++) { # intensions for ($j=1;$j<=2;$j++) { # experiments $dst = "" . $j . "." . $i . "." . $case; if ($results{$dst . ".count"} == 0) { die "Average: No data for $a\n"; } $results{$dst . ".mean"} /= $results{$dst . ".count"}; } } } for ($case=1;$case<=3;$case++) { # outcomes for ($i=1;$i<=3;$i++) { # intensions for ($j=1;$j<=2;$j++) { # experiments for ($s=1;$s<$subj;$s++) { # subjects for ($sent=1;$sent<$maxsent;$sent++) { # sentences $a = "" . $s . "." . $sent . "." . $i . "." . $j . "." . $case; $dst = "" . $j . "." . $i . "." . $case; if (defined($sentences{$a})) { $results{$dst . ".sqsum"} += ( ($sentences{$a} - $results{$dst . ".mean"}) * ($sentences{$a} - $results{$dst . ".mean"}) ); } } } } } } open (MEASFILE,">results-perc.txt") || die "results-perc.txt write error\n"; print "Storing the overall results in results-perc.txt\n"; for ($case=1;$case<=3;$case++) { # outcomes for ($i=1;$i<=3;$i++) { # intensions for ($j=1;$j<=2;$j++) { # experiments $dst = "" . $j . "." . $i . "." . $case; $results{$dst . ".sd"} = sqrt( $results{$dst . ".sqsum"} / $results{$dst . ".count"}); # the square root of the variance is the standard deviation } } } for ($j=1;$j<=2;$j++) { # experiments if ($j == 1) { print "Without RC:\n"; } else { print "\nWith RC:\n"; } for ($i=1;$i<=3;$i++) { # intensions print "\nIntended attachment/stress on NP $i:\n"; for ($case=1;$case<=3;$case++) { # outcomes print "Perceived attachment/stress for NP $case:\n"; $dst = "" . $j . "." . $i . "." . $case; printf "mean: %3.3f std dev: %3.3f data points: %3d" . " sum of squared diff: %3.3f\n", $results{$dst . ".mean"}, $results{$dst . ".sd"}, $results{$dst . ".count"}, $results{$dst . ".sqsum"}; printf MEASFILE "%d;%d;%d%3.3f;%3.3f;%3d;%3.3f\n",$j,$i,$case, $results{$dst . ".mean"}, $results{$dst . ".sd"}, $results{$dst . ".count"}, $results{$dst . ".sqsum"}; } } } close(MEASFILE); # F value calculations my $gmean = 0.0; my $msw = 0.0; my $gcnt = 0.0; my $msb = 0.0; for ($j=1;$j<=2;$j++) { # experiments if ($j == 1) { print "Without RC:\n"; } else { print "\nWith RC:\n"; } for ($i=1;$i<=3;$i++) { # intensions print "\nIntended attachment/stress on NP $i:\n"; $gmean = 0.0; $msw = 0.0; $gcnt = 0; for ($case=1;$case<=3;$case++) { # outcomes $dst = "" . $j . "." . $i . "." . $case; $gmean = $gmean + $results{$dst . ".mean"}; if ($case==1) { $gcnt = $results{$dst . ".count"}; } else { if ($gcnt != $results{$dst . ".count"}) { print "<" . $gcnt . "," . $results{$dst . ".count"} . ">"; } } $msw = $msw + $results{$dst . ".sqsum"}; } $gmean *= 1.0/3.0; printf " gmean %3.3f gsqsum,msw %3.3f gcnt %3d\n", $gmean, $msw, $gcnt; # MSB is sum of sqare(mean-gmean) # MSW is just gsqsum # F is (count-3)MSB / (3-1)MSW $msb = 0.0; for ($case=1;$case<=3;$case++) { # outcomes $dst = "" . $j . "." . $i . "." . $case; $msb += ($results{$dst . ".mean"}-$gmean)**2; } printf "MSB %3.3f MSW %3.3f df1 (%d-2) df2 (3-1)\n", $msb, $msw, $gcnt; printf "F %3.3f\n", ($gcnt-3)*$msb / ($msw + $msw); } } exit 0;