"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "addons/SVAR/SVAR_plots.inp" between
gretl-2020a.tar.xz and gretl-2020b.tar.xz

About: gretl (Gnu Regression, Econometrics and Time-series Library) is a cross-platform statistical package mainly for econometric analysis.

SVAR_plots.inp  (gretl-2020a.tar.xz):SVAR_plots.inp  (gretl-2020b.tar.xz)
skipping to change at line 21 skipping to change at line 21
return 0 return 0
end function end function
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
/* --- IRF core graphing function --------------------------------------- */ /* --- IRF core graphing function --------------------------------------- */
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
function string IRFgrph(matrix IRFmat, int snum, int vnum, scalar scale, \ function string IRFgrph(matrix IRFmat, int snum, int vnum, scalar scale, \
string sname, string vname, int keypos[0:2:1], \ string sname, string vname, int keypos[0:2:1], \
matrix *cumul[null], bundle *boot[null], \ matrix *cumul[null], bundle *boot[null], \
int bc[0:2:0]) int bc[0:2:0], int whichdraw[0::0])
# bc: bias correction choice # bc: bias correction choice
# FIXME: We should get rid of sname/vname args and get them automatically
# via snum/vnum
# (the number of args here is horrible...)
scalar flip = (snum < 0) if whichdraw && (exists(boot) || bc)
scalar snum = abs(snum) funcerr "cannot have SR/whichdraw and bootstrap options together"
scalar n = round(sqrt(cols(IRFmat))) endif
flip = (snum < 0)
snum = abs(snum)
n = round(sqrt(cols(IRFmat)))
# bootrep = exists(boot) ? boot.rep : 0 # doesn't work due to gretl bug+
bootrep = 0
if exists(boot) if exists(boot)
scalar bootrep = boot.rep bootrep = boot.rep
scalar alpha = boot.alpha
else
scalar bootrep = 0
endif endif
# anything to cumulate? # anything to cumulate?
scalar cumulate = exists(cumul) ? sumr(sumc(cumul .= vnum)) > 0 : 0 cumulate = exists(cumul) ? sumr(sumc(cumul .= vnum)) > 0 : 0
scalar tmpfname = int(1000*muniform(1,1)) tmpfname = int(1000 * muniform(1,1))
string tmpfile = $windows ? sprintf("@dotdir\\irf%d.gp", tmpfname) : \ string tmpfile = $windows ? sprintf("@dotdir\\irf%d.gp", tmpfname) : \
sprintf("@dotdir/irf%d.gp", tmpfname) sprintf("@dotdir/irf%d.gp", tmpfname)
scalar k = (snum-1)*n + vnum k = (snum-1) * n + vnum
scalar h = rows(IRFmat) h = rows(IRFmat)
matrix x = flip ? -IRFmat[,k]./scale : IRFmat[,k]./scale # matrix? matrix x = flip ? -IRFmat[,k]./scale : IRFmat[,k]./scale # matrix?
if bootrep > 0 if bootrep > 0
matrix hicb = flip ? -boot.lo_cb : boot.hi_cb # matrix? matrix hicb = flip ? -boot.lo_cb : boot.hi_cb # matrix?
matrix locb = flip ? -boot.hi_cb : boot.lo_cb matrix locb = flip ? -boot.hi_cb : boot.lo_cb
matrix mdn = flip ? -boot.mdns : boot.mdns matrix mdn = flip ? -boot.mdns : boot.mdns
matrix locb = locb[,k] ./ scale matrix locb = locb[,k] ./ scale
matrix hicb = hicb[,k] ./ scale matrix hicb = hicb[,k] ./ scale
matrix mdn = mdn[,k] ./ scale matrix mdn = mdn[,k] ./ scale
scalar miny = minc((locb | x)) scalar miny = minc((locb | x))
scalar maxy = maxc((hicb | x)) scalar maxy = maxc((hicb | x))
else else
scalar miny = minc(x) scalar miny = minc(x)
scalar maxy = maxc(x) scalar maxy = maxc(x)
endif endif
scalar miny = (miny>0) ? 0 : miny miny = (miny>0) ? 0 : miny
scalar maxy = (maxy<0) ? 0 : maxy maxy = (maxy<0) ? 0 : maxy
set force_decpoint on set force_decpoint on
## write the raw gnuplot code
outfile "@tmpfile" --write outfile "@tmpfile" --write
printf "set yrange [%g:%g]\n", miny*1.05, maxy*1.05 printf "set yrange [%g:%g]\n", miny*1.05, maxy*1.05
printf "set xrange [%g:%g]\n", 0, (h-1)*1.05 printf "set xrange [%g:%g]\n", 0, (h-1)*1.05
printf "set xzeroaxis\n" printf "set xzeroaxis\n"
string l_sname = sname=="" ? sprintf("%d", snum) : sname string l_sname = sname=="" ? sprintf("%d", snum) : sname
string l_vname = vname=="" ? sprintf("%d", vnum) : vname string l_vname = vname=="" ? sprintf("%d", vnum) : vname
printf "set title \"IRF: %s -> %s", l_sname, l_vname printf "set title \"IRF: %s -> %s", l_sname, l_vname
if bc == 1 if bc == 1
printf "; bias-correction = partial" printf "; bias-correction = partial"
elif bc == 2 elif bc == 2
printf "; bias-correction = full" printf "; bias-correction = full"
elif whichdraw
printf " (draw %d)", whichdraw
endif endif
if cumulate > 0 if cumulate > 0
printf " (cumulated)" printf " (cumulated)"
endif endif
printf "\"\n" printf "\"\n"
if keypos == 0
printf "set key off\n"
elif keypos == 1
printf "set key outside\n"
elif keypos == 2
printf "set key below\n"
endif
if bootrep > 0 if bootrep > 0
if keypos == 0
printf "set key off\n"
elif keypos == 1
printf "set key outside\n"
elif keypos == 2
printf "set key below\n"
endif
printf "set style fill solid 0.125\n" printf "set style fill solid 0.125\n"
printf "plot '-' using 1:2:3 w filledcurve t " printf "plot '-' using 1:2:3 w filledcurve t "
printf "'Bstrap %d%% CI', \\\n", floor(100*alpha) printf "'Bstrap %d%% CI', \\\n", floor(100 * boot.alpha)
printf "'-' w l lw 1 lc 1 t 'Bstrap median', \\\n" printf "'-' w l lw 1 lc 1 t 'Bstrap median', \\\n"
printf "'-' w l lw 2 lc -1 t 'IRF'\n" printf "'-' w l lw 2 lc -1 t 'IRF'\n"
loop i=1..h -q loop i=1..h -q
printf "%d\t%g\t%g\n", i-1, locb[i,], hicb[i,] printf "%d\t%g\t%g\n", i-1, locb[i,], hicb[i,]
endloop endloop
printf "e\n" printf "e\n"
loop i=1..h -q loop i=1..h -q
printf "%d\t%g\n", i-1, mdn[i,] printf "%d\t%g\n", i-1, mdn[i,]
endloop endloop
printf "e\n" printf "e\n"
skipping to change at line 128 skipping to change at line 138
set force_decpoint off set force_decpoint off
return tmpfile return tmpfile
end function end function
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
/* --- IRF public graphing functions ------------------------------------ */ /* --- IRF public graphing functions ------------------------------------ */
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
function void IRFsave(string outfilename, bundle *obj, int snum, function void IRFsave(string outfilename, bundle *obj, int snum,
int vnum, int keypos[0:2:1]) int vnum, int keypos[0:2:1], int drawix[0::0])
# negative snum is allowed and means to flip the shock # negative snum is allowed and means to flip the shock
# copy and prepare some input # copy and prepare some input
string tmpfile, tmpout string tmpfile, tmpout
n = obj.n n = obj.n
matrix IRFmat = obj.IRFs whichdraw = drawix ? drawix : obj.bestdraw
if obj.type == 10 # SR
errchkSRhisto(&obj, drawix)
putIrf_to_accdraw(&obj, whichdraw)
matrix IRFmat = obj.acc_draws[whichdraw].IRFs
else
matrix IRFmat = obj.IRFs
endif
scale = 1 # possibly changed later scale = 1 # possibly changed later
if obj.normalize == 1 if obj.normalize == 1
matrix tmp = mshape(IRFmat[1,], n, n) matrix tmp = mshape(IRFmat[1,], n, n)
endif endif
if obj.nboot if obj.nboot
boot = obj.bootdata # bundle? boot = obj.bootdata # bundle?
bc = boot.biascorr bc = boot.biascorr
endif endif
skipping to change at line 179 skipping to change at line 198
if err == 2 if err == 2
printf "Variable number %d out of bounds\n", vnum printf "Variable number %d out of bounds\n", vnum
return return
endif endif
string yn = obj.Ynames[vnum] string yn = obj.Ynames[vnum]
# produce plots # produce plots
if obj.ncumul == 0 if obj.ncumul == 0
if obj.nboot == 0 if obj.nboot == 0
tmpfile = IRFgrph(IRFmat, snum, vnum, scale, sn, yn, keypos) tmpfile = IRFgrph(IRFmat, snum, vnum, scale, sn, yn, keypos,
\
null, null, , whichdraw)
else else
tmpfile = IRFgrph(IRFmat, snum, vnum, scale, sn, yn, keypos, \ tmpfile = IRFgrph(IRFmat, snum, vnum, scale, sn, yn, keypos, \
null, &boot, bc) null, &boot, bc, whichdraw)
endif endif
else else
matrix cumul = obj.cumul matrix cumul = obj.cumul
if obj.nboot == 0 if obj.nboot == 0
tmpfile = IRFgrph(IRFmat, snum, vnum, scale, sn, yn, keypos, \ tmpfile = IRFgrph(IRFmat, snum, vnum, scale, sn, yn, keypos, \
&cumul) &cumul, null, , whichdraw)
else else
tmpfile = IRFgrph(IRFmat, snum, vnum, scale, sn, yn, keypos, \ tmpfile = IRFgrph(IRFmat, snum, vnum, scale, sn, yn, keypos, \
&cumul, &boot, bc) &cumul, &boot, bc, whichdraw)
endif endif
endif endif
if (outfilename == "display") || (sfrom == sto && vfrom == vto) if (outfilename == "display") || (sfrom == sto && vfrom == vto)
# (single plot, no indices) # (single plot, no indices)
tmpout = outfilename tmpout = outfilename
else else
strings be = basename(outfilename) # gives 2-elem array strings be = basename(outfilename) # gives 2-elem array
if is_vrange # several v indices if is_vrange # several v indices
if is_srange # several s indices if is_srange # several s indices
skipping to change at line 218 skipping to change at line 238
else else
funcerr "shouldn't happen" funcerr "shouldn't happen"
endif endif
endif endif
gnuplot --input="@tmpfile" --output="@tmpout" gnuplot --input="@tmpfile" --output="@tmpout"
endloop endloop
endloop endloop
end function end function
function void IRFplot(bundle *obj, int snum, int vnum, int keypos[0:2:1]) function void IRFplot(bundle *obj, int snum[1], int vnum[1],
int keypos[0:2:1], int drawix[0::0])
IRFsave("display", &obj, snum, vnum, keypos) IRFsave("display", &obj, snum, vnum, keypos, drawix)
end function end function
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
/* --- FEVD core graphing function -------------------------------------- */ /* --- FEVD core graphing function -------------------------------------- */
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
function string FEVDgrph(matrix FEVDmat, scalar v, function string FEVDgrph(matrix FEVDmat, scalar v,
string vname, strings snames, int keypos[0:2:1]) string vname, strings snames, int keypos[0:2:1],
string titletail[null])
# Final arg 'titletail' is a hack originally meant to put the draw number
# in the output in the SR case. (In principle it can be anything.)
if !exists(titletail)
string titletail = ""
endif
n = round(sqrt(cols(FEVDmat))) n = round(sqrt(cols(FEVDmat)))
h = rows(FEVDmat) - 1 h = rows(FEVDmat) - 1
scalar tmpfname = int(10000*muniform(1,1)) scalar tmpfname = int(10000*muniform(1,1))
if $windows if $windows
sprintf datfile "@dotdir\\fevd%d.txt", tmpfname sprintf datfile "@dotdir\\fevd%d.txt", tmpfname
sprintf tmpfile "@dotdir\\fevd%d.gp", tmpfname sprintf tmpfile "@dotdir\\fevd%d.gp", tmpfname
else else
sprintf datfile "@dotdir/fevd%d.txt", tmpfname sprintf datfile "@dotdir/fevd%d.txt", tmpfname
skipping to change at line 258 skipping to change at line 287
printf "set key off\n" printf "set key off\n"
elif keypos == 1 elif keypos == 1
printf "set key outside\n" printf "set key outside\n"
elif keypos == 2 elif keypos == 2
printf "set key below\n" printf "set key below\n"
endif endif
printf "set yrange [0:100]\n" printf "set yrange [0:100]\n"
printf "set xrange [%g:%g]\n", 0, h printf "set xrange [%g:%g]\n", 0, h
printf "set xzeroaxis\n" printf "set xzeroaxis\n"
printf "set title \"FEVD for %s\"\n", vname printf "set title \"FEVD for %s%s\"\n", vname, titletail
printf "set style fill solid 0.25\n" printf "set style fill solid 0.25\n"
printf "set style histogram rowstacked\n" printf "set style histogram rowstacked\n"
printf "set style data histogram\n" printf "set style data histogram\n"
loop i=1..n --quiet loop i=1..n --quiet
string sname = snames[i] string sname = snames[i]
if i == 1 if i == 1
printf "plot '%s' using 2 t '%s', \\\n", datfile, sname printf "plot '%s' using 2 t '%s', \\\n", datfile, sname
elif i == n elif i == n
skipping to change at line 290 skipping to change at line 319
set force_decpoint off set force_decpoint off
return tmpfile return tmpfile
end function end function
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
/* --- FEVD public graphing functions ----------------------------------- */ /* --- FEVD public graphing functions ----------------------------------- */
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
function void FEVDsave(string outfilename, bundle *obj, int vnum[0], \ function void FEVDsave(string outfilename, bundle *obj, int vnum[0], \
int keypos[0:2:1]) int keypos[0:2:1], int drawix[0::0])
scalar n = obj.n scalar n = obj.n
scalar vfrom vto scalar vfrom vto
is_vrange = range(vnum, n, &vfrom, &vto) is_vrange = range(vnum, n, &vfrom, &vto)
matrix Fmat = FEVD(&obj) matrix Fmat = FEVD(&obj, drawix)
# prepare title amendment in SR case
string titletail = ""
if obj.type == 10
whichdraw = drawix ? drawix : obj.bestdraw
titletail = sprintf(" (draw %d)", whichdraw)
endif
loop vnum = vfrom..vto -q loop vnum = vfrom..vto -q
err = check_bounds(1, vnum, n) err = check_bounds(1, vnum, n)
if err == 2 if err == 2
printf "Variable number %d out of bounds\n", vnum printf "Variable number %d out of bounds\n", vnum
return return
endif endif
string tmpout = (outfilename == "display") ? "display" : \ string tmpout = (outfilename == "display") ? "display" : \
sprintf("%s_%d", outfilename, vnum) sprintf("%s_%d", outfilename, vnum)
string tmpfile = FEVDgrph(Fmat, vnum, obj.Ynames[vnum], obj.snames, keyp string tmpfile = FEVDgrph(Fmat, vnum, obj.Ynames[vnum], obj.snames, \
os) keypos, titletail)
gnuplot --input="@tmpfile" --output="@tmpout" gnuplot --input="@tmpfile" --output="@tmpout"
endloop endloop
end function end function
function void FEVDplot(bundle *obj, int vnum[0], int keypos[0:2:1]) function void FEVDplot(bundle *obj, int vnum[0], int keypos[0:2:1],
int drawix[0::0])
FEVDsave("display", &obj, vnum, keypos) FEVDsave("display", &obj, vnum, keypos, drawix)
end function end function
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
/* --- HD public graphing functions ------------------------------------- */ /* --- HD public graphing functions ------------------------------------- */
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
function void HDsave(string outfilename, bundle *obj, int vnum[0]) function void HDsave(string outfilename, bundle *obj, int vnum[0],
int drawix[0::0])
# more fashionable (=Dynare-like) style # more fashionable (=Dynare-like) style
# Interpret vnum==0 as meaning "all 1..n" # Interpret vnum==0 as meaning "all 1..n"
scalar n = obj.n scalar n = obj.n
scalar vfrom vto scalar vfrom vto
is_vrange = range(vnum, n, &vfrom, &vto) is_vrange = range(vnum, n, &vfrom, &vto)
loop vnum = vfrom..vto -q loop vnum = vfrom..vto -q
err = check_bounds(1, vnum, n) err = check_bounds(1, vnum, n)
if err == 2 if err == 2
printf "Variable number %d out of bounds\n", vnum printf "Variable number %d out of bounds\n", vnum
return return
endif endif
list tmp = SVAR_hd(&obj, vnum) list tmp = SVAR_hd(&obj, vnum, drawix)
# prepare extended plot title, only for SR
whichdraw = drawix ? drawix : obj.bestdraw
string drawinfo = obj.type == 10 ? sprintf(" (draw %d)", whichdraw) : ""
tmp -= tmp[1] # take away deterministic component tmp -= tmp[1] # take away deterministic component
loop i=1..nelem(tmp) --quiet loop i=1..nelem(tmp) --quiet
string sn = obj.snames[i] string sn = obj.snames[i]
setinfo tmp[i] --graph-name="@sn" setinfo tmp[i] --graph-name="@sn"
endloop endloop
series tmpvar = sum(tmp) series tmpvar = sum(tmp)
string gnam = sprintf("%s (stoch. component)", obj.Ynames[vnum]) string gnam = sprintf("%s (stoch. component)", obj.Ynames[vnum])
setinfo tmpvar --graph-name="@gnam" setinfo tmpvar --graph-name="@gnam"
tmp = tmpvar tmp # put the line with the target var name first tmp = tmp tmpvar
# (put the line with the target var (stoch.comp) _last_
# such that the shock colors match those in FEVD
string tmpout = (outfilename == "display") ? "display" : \ string tmpout = (outfilename == "display") ? "display" : \
sprintf("%s_%d", outfilename, vnum) sprintf("%s_%d", outfilename, vnum)
plot tmp plot tmp
option time-series option time-series
option single-yaxis option single-yaxis
option with-boxes option with-boxes
option with-lines=tmpvar option with-lines=tmpvar
printf "set title \"HD for %s\"", obj.Ynames[vnum] printf "set title \"HD for %s%s\"", obj.Ynames[vnum], drawinfo
end plot --output="@tmpout" end plot --output="@tmpout"
endloop endloop
end function end function
function void HDplot(bundle *obj, int vnum[0]) function void HDplot(bundle *obj, int vnum[0], int drawix[0::0])
HDsave("display", &obj, vnum) HDsave("display", &obj, vnum, drawix)
end function end function
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
/* --- GUI hook --------------------------------------------------------- */ /* --- GUI hook --------------------------------------------------------- */
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
function void GUI_plot(bundle *b, int ptype[0:2:0] \ function void GUI_plot(bundle *b, int ptype[0:2:0] \
"Plot type" {"IRF", "FEVD", "Historical decomposition"}) "Plot type" {"IRF", "FEVD", "Historical decomposition"})
if ptype == 0 if ptype == 0
IRFplot(&b, 0, 0) # all in one go IRFplot(&b, 0, 0, (b.nboot ? 2 : 0)) # all in one go / no key if no band s
elif ptype == 1 elif ptype == 1
FEVDplot(&b, 0) FEVDplot(&b, 0)
elif ptype == 2 elif ptype == 2
HDplot(&b, 0) HDplot(&b, 0)
endif endif
end function end function
 End of changes. 37 change blocks. 
45 lines changed or deleted 91 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)