[R] Error: evaluation nested too deeply

abotaha yaseen0202 at gmail.com
Thu Aug 12 15:42:26 CEST 2010


Hi guys, 
I have a code in R and it was work well but when I decrease the epsilon
value (indicated in the code) , then I am getting this error
Error: evaluation nested too deeply: infinite recursion /
options(expressions=)? 
any help please 


y = 6.8; 
w = 7.4;
z = 5.7;
muy = 7; 
muw = 7; 
muz = 6; 
sigmay = 0.8; 
sigmaz = 0.76; 
sigmaw = 0.3;
betayx = 0.03; 
betayz = 0.3; 
betayw = 0.67

s = c(3.2,0.8)

em = function(W,s) {
a= 1/2*(1/s[2]^2+betayx^2/sigmay^2); 
b=
(y-muy+betayx*s[1]-betayz*(z-muz)-betayw*(w-muw))*betayx/sigmay^2+s[1]/s[2]^2; 
c=(1/2)*((y-muy+betayx*s[1]-betayz*(z-muz)-betayw*(w-muw))*betayx/sigmay^2+s[1]/s[2]^2)^2/(1/s[2]^2+betayx^2/sigmay^2);
V = exp(-c+b^2/(4*a))/sqrt(pi/(1/(2*s[2]^2)+(1/2)*betayx^2/sigmay^2)); 
Omega = V*sqrt(pi/a);

A = 4*a^2*Omega*betayx^2/sigmay^2; 
B = 4*a^2; 
C = 2*a*b*Omega; 
d =
(2*a*b*Omega*betayx^2/sigmay^2)-(4*a^2*Omega*(y-muy-betayz*(z-muz)-betayw*(w-muw))*betayx/sigmay^2);
E = 2*a*Omega+b^2*Omega;
lambda = A*B; 
alpha = 2*A*C+d*B; 
delta = A*E+B^2+2*d*C; 
eta = C*B+d*E;
s[1]=(1/6)*(-36*delta*alpha*lambda+108*eta*lambda^2+8*alpha^3+12*sqrt(3)*sqrt(4*delta^3*lambda-delta^2*alpha^2-18*delta*alpha*lambda*eta+27*eta^2*lambda^2+4*eta*alpha^3)*lambda)^(1/3)/lambda+(2/3)*(-3*delta*lambda+alpha^2)/(lambda*(-36*delta*alpha*lambda+108*eta*lambda^2+8*alpha^3+12*sqrt(3)*sqrt(4*delta^3*lambda-delta^2*alpha^2-18*delta*alpha*lambda*eta+27*eta^2*lambda^2+4*eta*alpha^3)*lambda)^(1/3))+(1/3)*alpha/lambda;
s[2]=sqrt((B*s[1]^2-2*C*s[1]+E)/B);
 s
 }
epsilon =0.0005
iter = function(W, s) {
 s1 = em(W,s)
 for (i in 1:2) {
 if (abs(s[i]-s1[i]) > epsilon) {
 s=s1
 iter(W,s)
 }
 else s1
 }
 s1
 }

iter(W,s)

-- 
View this message in context: http://r.789695.n4.nabble.com/Error-evaluation-nested-too-deeply-tp2322701p2322701.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list