help!! I can’t do the iteration

I want to make the panjer model for the Poisson but my problem is that I do not know how to iterate for the previous ones ,ie for x=2 it comes out but for x=3 no, I need to save the result of x=2 to add it to x=3 and so on,here is the code I did.

poispanjer<-function(x,lamda){
if (x>0){
g<- numeric(x+1)
g[1]<-dpois(0,lamda)
g[2]<-lamda*dpois(1,lamda)g[1]
gf<- numeric(x)
for (i in 1:x){
gf[x-i+1]<-(lamda
(x-i+1)/x)*dpois((x-i+1),lamda)*g[i]
}
g[i+1] <- sum(gf)
print(g[x+1])}
else {print(dpois(0,lamda))}
}

A reprex with the highlighted statement's syntax corrected is required.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.