1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#!/bin/sh
# use multimix to separate observations into two groups
# to see how the data file simple.dat was created, see simple.c
# to see how the parameter file simple.param was created, see simple.log
if [ ! -f simple.dat ]; then gunzip *.gz; fi
# is this directory writable?
if [ ! -w . ]; then
echo "permission denied."
echo 'please copy simple* to a directory where you have write permission'
exit 1
fi
# output files may not already exist
rm -f GROUPS.OUT GENERAL.OUT
# use multimix to find the groups
multimix <<EOF
simple.dat
simple.param
EOF
# separate the oservations into two files,
# depending on the group assigned by multimix
awk '
{
group_number=$1;
getline data < "simple.dat";
print data > "group" group_number;
}' GROUPS.OUT
# display the original data (under X windows)
gnuplot -persist <<\EOF
set key bottom
set title "original data"
set parametric; set trange [0:6.28]
plot "simple.dat", \
0+2.45*sin(t),1+2.45*cos(t) title 'hint 1' with lines, \
7+2.45*sin(t),5+2.45*cos(t) title 'hint 2' with lines
EOF
# display the two groups in different colors (under X windows)
cat GENERAL.OUT | awk '
BEGIN{
printf("set key bottom\n");
printf("set title \"groups found by Multimix\"\n");
printf("set parametric; set trange [0:6.28]\n");
printf("plot \\\n");
}
/^THE CURRENT ESTIMATES FOR GROUP/{
group=$6; partition=$9;
getline;
getline;
getline;
mean[group partition]=$1;
}
/^ THE CURRENT ESTIMATE OF THE COVARIANCE MATRIX FOR GROUP/{group=$NF}
/^ AND PARTITION/{
partition=$NF;
getline;
variance[group partition]=$1;
}
END {
for (group=1; group<3; group++){
if (group>1) printf(",\\\n");
lonmean=mean[group 1]; lonsd=sqrt(variance[group 1]);
latmean=mean[group 2]; latsd=sqrt(variance[group 2]);
printf("%s+2.45*%s*sin(t),%s+2.45*%s*cos(t) title \"group %d 95%% contour\",\\\n",
lonmean, lonsd, latmean, latsd, group);
printf(" \"group%d\" title \"group %d members\"", group, group);
}
printf("\n");
}' | gnuplot -persist
|