I am trying to send to R a big function,it has only three variables but output is quite big.So when i "translate" that code from mathematica to look like R code and input it in REvaluate i get the popup window thats telling me that java(tm) platform se binary has stopped working.I succeeded the similar thing with same amount of code length but with this one I can't and I can't figure out what's wrong.
Here is the code that's making trouble:
ClearAll[sigmasqr, a, ll, sll];
s = FinancialData["^gspc", "FractionalChange", {"2005/01/01", "2009/12/31"}][[All, 2]];
R[t_] := s[[t]]
sigmasqr[1, w_, a_, b_] = Variance[s]
sigmasqr[t_, w_, a_, b_] := w + a R[t - 1]^2 + b sigmasqr[t - 1, w, a, b]
ll[t_, w_, a_, b_] := -.5 (Log[2 \[Pi]] + Log[sigmasqr[t, w, a, b]] + R[t]^2/
sigmasqr[t, w, a, b]) // N
sll = Sum[ll[t, w, a, b], {t, 2, 100}];
So sll is a log likelihood sum for 100 returns,now I want to create a function that can be used in R's optim from this sll.Here is the code:
REvaluate["a1=function(w,a,b){" <> StringReplace[ToString[sll//InputForm], {"[" -> "(", "]" -> ")",
"L" -> "l", "*^" -> "*10^"}] <> "}"]
And here is where problem starts.. I found that the troublesome part starts from part 48 of the sum
REvaluate["a1=function(w,a,b){" <> StringReplace[ToString[sll[[1;;47]]//InputForm], {"[" -> "(", "]" -> ")",
"L" -> "l", "*^" -> "*10^"}] <> "}"]
If you check you will see that it runs perfectly,but now if you run:
REvaluate["a1=function(w,a,b){" <> StringReplace[ToString[sll[[48]]//InputForm], {"[" -> "(", "]" -> ")",
"L" -> "l", "*^" -> "*10^"}] <> "}"]
you will get a java platform stop working message.Is there a solution to this problem? I should say that I pasted the troublesome part in R to check did I forgat to change something in the form of code but,no it's working in R.
Logfunctions etc. Besides, this is most definitely not the recommended way to construct an R function with RLink. What you should be doing is to transfer data to R, and then construct the R function to operate on that data. – Leonid Shifrin Apr 10 '14 at 23:32