[R] Simulating a Poisson Process in R by calling C Code over .Call

From: Fabian Zšpernick <fab.zaep_at_web.de>
Date: Sun, 13 Jun 2010 15:54:17 +0200


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



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 13 Jun 2010 - 13:51:01 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 13 Jun 2010 - 17:50:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive