[R] Incompatible types error

apellegrini001 apellegrini at students.colgate.edu
Fri Feb 5 21:57:55 CET 2010


I'm trying to write a loop for a series of nested functions. and I get an
incompatible types error when trying to run it. It's supposed to be a
simulation (1000 iterations) with a random value for "rand" being chosen
each time. After each rand value is chosen, the rest of the functions are
evaluated with this given rand value and their "Fitness" sum value is saved
and plotted against rand.

let me know if you see any obvious problems.

Below is the Script
"
#variables
Amp=3
n=0.5

#variables
nt<-200
z0=1
z<-rep(z0,nt)

#overlying function
  t<-seq(0,(2*pi),by=0.01)  
for(i in c(1:1000)){                
Et<-numeric(1000) 
fx<-numeric(1000)
Tx<-numeric(1000)
Fitness<-numeric(1000)
 Et[i]<-function(Eztx,t,A,n){
    A=Amp
    Eztx[i]<-A*sin(t)*n
     if(Tx[i]>1){Eztx[i]/Tx[i]
    } else {Eztx[i]<-Eztx[i]
  }
  fx[i]<-function(mea,rand,prob,Et){ 
    rand[i]<-runif[i](1,-50,50)
    mea=0
    prob[i]<-function(pi,rand,Et,mea){
     
(1/(2*pi*rand[i]))*exp((-(Et[i](Eztx[i],t,A,n))-mea)^2)/(2*(rand[i]^2))
     }
    prob(pi,rand[i],Et[i](Eztx[i],t,A,n),mea)
   }
  Tx[i]<-function(fx,cdist){
    cdist[i] <-(1-((pnorm(Et[i](Eztx[i],t,A,n),mea,rand[i],))
      	-(pnorm(mea,mea,rand[i],))))
    Tzx[i]<-fx[i](prob[i],rand[i],Et[i])*cdist[i]
    Tzx[i]
   }
  }
Fitness[i]<-function(Tx){
  f[i]<-Tx[i]
  Fit[i]<-sum(f[i])
 }
}
plot(Fit,rand)

"
-- 
View this message in context: http://n4.nabble.com/Incompatible-types-error-tp1470783p1470783.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list