-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathestimnetdirectedEstimation2textableMultiModels.sh
executable file
·154 lines (140 loc) · 5.8 KB
/
estimnetdirectedEstimation2textableMultiModels.sh
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
#
# File: estimnetdirectedEstimation2textableMultiModels.sh
# Author: Alex Stivala
# Created: Februrary 2017
#
#
# Read output of computeEstimNetDirectedCovariance.R with the estimate,
# estimated std. error and t-ratio computed from EstimNetDirected results
# and build LaTeX table for multiple different models
#
# Usage: estimnetdirectedEstimation2textableMultiModels.sh [-m <basemodelnum] estimationoutputfile_model1 estimationoutputfile_model2 ...
#
# If the -m <basemodelnum> option is specfieid, then the model numbers start
# at <basemodelnum> rather than 1.
#
# E.g.:
# estimnetdirectedEstimation2textableMultiModels.sh estimation.out model2/estimation.out
#
# Output is to stdout
#
# Uses various GNU utils options on echo, etc.
zSigma=2 # multiplier of estimated standard error for nominal 95% C.I.
tratioThreshold=0.3 # t-ratio must be <= this for significance
usage() { echo "usage: $0 [-m <basemodelnum>] estimation1.out estimation2.out ..." >&2 ; exit 1; }
basemodelnum=1
while getopts "m:" opt; do
case "${opt}" in
m)
basemodelnum=${OPTARG}
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
num_models=`expr $#`
if [ $num_models -lt 1 ]; then
usage
fi
estimnet_tmpfile=`mktemp`
echo "% Generated by: $0 $*"
echo "% At: " `date`
echo "% On: " `uname -a`
echo -n '\begin{tabular}{l'
i=1
while [ $i -le $num_models ]
do
echo -n r
i=`expr $i + 1`
done
echo '}'
echo '\hline'
echo -n 'Effect '
i=1
while [ $i -le $num_models ]
do
echo -n " & Model " `expr ${basemodelnum} - 1 + $i`
i=`expr $i + 1`
done
echo '\\'
echo '\hline'
# new version has results starting at line following "Pooled" at start
# of line (pooling the individual run estimates values printed earlier) and
# 5 columns:
# Effect estimate sd(theta) est.std.err t.ratio
# (and maybe *) plus
# TotalRuns and ConvergedRuns e.g.:
#Diff_completion_percentage -0.002270358 0.005812427 0.01295886 0.021386
#TotalRuns 2
#ConvergedRuns 2
# (see computeEstimNetDirectedCovariance.R)
model=1
for estimationresults in $*
do
# https://unix.stackexchange.com/questions/78472/print-lines-between-start-and-end-using-sed
cat ${estimationresults} | sed -n -e '/^Pooled/,${//!p}' | tr -d '*' | fgrep -vw AcceptanceRate | awk '{print $1,$2,$4,$5}' | tr ' ' '\t' | sed "s/^/${model}\t/" >> ${estimnet_tmpfile}
model=`expr $model + 1`
done
effectlist=`cat ${estimnet_tmpfile} | fgrep -vw TotalRuns | fgrep -vw ConvergedRuns | awk '{print $2}' | sort | uniq`
for effect in ${effectlist} ConvergedRuns TotalRuns
do
if [ ${effect} = "ConvergedRuns" ]; then
echo '\hline'
fi
model=1
echo -n "${effect} " | tr '_' ' '
while [ $model -le $num_models ];
do
if [ ${effect} = "ConvergedRuns" -o ${effect} = "TotalRuns" ]; then
runs=`grep -w ${effect} ${estimnet_tmpfile} | awk -vmodel=$model '$1 == model {print $3}'`
echo -n " & ${runs}"
else
estimnet_point=`grep -w ${effect} ${estimnet_tmpfile} | awk -vmodel=$model '$1 == model {print $3}'`
estimnet_stderr=`grep -w ${effect} ${estimnet_tmpfile} | awk -vmodel=$model '$1 == model {print $4}'`
estimnet_tratio=`grep -w ${effect} ${estimnet_tmpfile} | awk -vmodel=$model '$1 == model {print $5}'`
if [ "${estimnet_point}" == "" ]; then
echo -n " & ---"
else
# put statistically significant results in "\heavy",
# which might be defined as e.g.
# \newcommand{\heavy}[1]{\mathbf{#1}}
# and others
# in "\light" which might be defined as e.g.
# \newcommand{\light}[1]{\textcolor{gray}{#1}}
# which requires \usepackage{xcolor} (NB color package does not have gray)
# (note usually
# one of \heavy or \light could just be defined as e.g.
# \newcommand{\light}[1]{#1}
# so that (in this case) light is normal, heavy is bold).
# bc cannot handle scientific notation so use sed to convert it
estimnet_lower=`echo "${estimnet_point} - ${zSigma} * ${estimnet_stderr}" | sed -e 's/[eE]+*/*10^/' | bc -l`
estimnet_upper=`echo "${estimnet_point} + ${zSigma} * ${estimnet_stderr}" | sed -e 's/[eE]+*/*10^/' | bc -l`
estimnet_point_scinotation="${estimnet_point}"
estimnet_point=`echo "${estimnet_point}" | sed -e 's/[eE]+*/*10^/'`
estimnet_tratio=`echo "${estimnet_tratio}" | sed -e 's/[eE]+*/*10^/'`
estimnet_stderr=`echo "${estimnet_stderr}" | sed -e 's/[eE]+*/*10^/'`
echo AAA "${estimnet_point}">&2
abs_estimate=`echo "if (${estimnet_point} < 0) -(${estimnet_point}) else ${estimnet_point}" | bc -l`
abs_tratio=`echo "if (${estimnet_tratio} < 0) -(${estimnet_tratio}) else ${estimnet_tratio}" | bc -l`
echo YYY ${abs_estimate} >&2
echo QQQ ${abs_tratio} >&2
echo XXX "${abs_tratio} <= ${tratioThreshold} && ${abs_estimate} > ${zSigma} * ${estimnet_stderr}" >&2
signif=`echo "${abs_tratio} <= ${tratioThreshold} && ${abs_estimate} > ${zSigma} * ${estimnet_stderr}" | bc -l`
echo ZZZ ${signif} >&2
if [ ${signif} -eq 0 ]; then
printf ' & $\\light{\\underset{(%.3f, %.3f)}{%.3f}}$' ${estimnet_lower} ${estimnet_upper} ${estimnet_point_scinotation}
else
printf ' & $\\heavy{\\underset{(%.3f, %.3f)}{%.3f}}$' ${estimnet_lower} ${estimnet_upper} ${estimnet_point_scinotation}
fi
fi
fi
model=`expr $model + 1`
done
echo '\\'
done
echo '\hline'
echo '\end{tabular}'
rm ${estimnet_tmpfile}