       Question on compiling a function with many subfunctions

• To: mathgroup at smc.vnet.net
• Subject: [mg84251] Question on compiling a function with many subfunctions
• From: "Mauricio Esteban Cuak" <cuak2000 at gmail.com>
• Date: Sun, 16 Dec 2007 05:34:54 -0500 (EST)

```Hi everyone.I was working on a function to produce recursive OLS parameters
and make the graphic test with one standard deviation up and down (I'm
sorry, I forgot the name :-(  ). By recursive I mean parameters that are
built by increasing the number of observations used to estimate them.
I built it by defining little functions first and then making my way to the
final one by writing it in terms of those others. This final one was very
slow to my taste, but then I had trouble compiling it because it had so many
subfunctions. I finally did it by writing all the functions out on my final
one, but it took a lot of time.
My question is rather general; Once I have a written function in terms of
other ones, can I compile it somehow without having to rewrite those
subfunctions?

I'll write out the functions I was working with as an example (I'm using
version 6), but I hope you can understand my question without having to read
this boring and ugly code:

recursiveBetas[x_, y_] :=

Table[LeastSquares[  Take[x, {1, i}, {1, Part[Dimensions[x], 2]}]  ,
Take[y, i]  ], {i, Part[Dimensions[x], 2] + 1,
Part[Dimensions[y], 1]} ]

selecBeta[x_, y_, k_] := Flatten[Part[recursiveBetas[x, y], All, k]];

grafBeta[x_, y_, k_] := ListPlot[selecBeta[x, y, k], PlotJoined -> True]

errorVar[x_,

y_] := ((y - x.LeastSquares[x, y]).(y - x.LeastSquares[x, y]))/(Length[y]
-
Length[LeastSquares[x, y]])                    (*The estimated variance
of my errors * )

estimatedMatrix [x_, y_] := (Inverse[Transpose[x].x])*
errorVar[x, y]       (* My variance-covariance matrix *)

varRecursiv[x_, y_] :=
Table[estimatedMatrix[  Take[x, {1, i}, {1, Part[Dimensions[x], 2]}]  ,
Take[y, i]  ], {i, Part[Dimensions[x], 2] + 1, Part[Dimensions[y], 1]} ]

sigmaParam[x_, y_, k_] :=
Sqrt[Flatten[
Table[Part[varRecursiv[x, y], i, k, k], {i, 1,
Part[Dimensions[x], 1]   -   Part[Dimensions[x], 2] }
]]]                       (* This gives me a list of the standard
deviations of a recursive parameter   k.    I find this function very slow
for large lists, but maybe I'm being too impatient *)

intervUp[x_, y_, k_] := selecBeta[x, y, k] + sigmaParam[x, y, k]
intervDown[x_, y_, k_] := selecBeta[x, y, k] - sigmaParam[x, y, k]

dibujoBeta[x_, y_, k_] :=
Show[ grafBeta[x, y, k], ListPlot[ intervDown[x, y, k] ],
ListPlot[ intervUp [x, y, k] ] ]                  (* this one draws the
graphic test * )

As always, thank you very much for your time!

cd

```

• Prev by Date: About ContourPlot
• Next by Date: ListPlot ignoring default options
• Previous by thread: Re: About ContourPlot
• Next by thread: ListPlot ignoring default options