[R] Simulating a Poisson Process in R by calling C Code over .Call
Fabian Zäpernick
fab.zaep at web.de
Sun Jun 13 15:54:17 CEST 2010
Hi
I want to write a C function for the R Code below and call it with .Call:
SimPoisson <- function(lambda,tgrid,T2M)
#Simulation eines Poissonprozesses
{
NT <- 0
Ni <- rep(0,length(tgrid))
tau <- 0
sign <- 0
if(lambda != 0)
{
i=1
j=1
while (1)
{
EVar <- rexp(1,lambda)
sign <- sign + EVar
if (sign > T2M)
{
break
}
tau[i] <- sign
i = i+1
for (j in j:length(tgrid))
{
if (tgrid[j] < sign)
{
Ni[j] <- NT
}else
{
break
}
}
NT <- NT + 1
}
for (j in j:length(tgrid))
{
Ni[j] <- NT
}
}
return(list(NT=NT,Ni=Ni,tau=tau))
}
I read the manual "writing R extensions" over and over again, but i have
no idea, how to solve the problem with tau because i dont no the length
of tau at the begining of the function
Fabian
More information about the R-help
mailing list