# # simula_panjer.R - A set of R functions for studying Panjer # aggregation method # #Copyright (C) 2005 Fernando Henrique F. P. Rosa # # #This program is free software; you can redistribute it and/or #modify it under the terms of version 2 of the GNU General Public License #as published by the Free Software Foundation. A copy of this license should #be included in the file COPYING. # #This program is distributed in the hope that it will be useful, #but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GNU General Public License for more details. # #You should have received a copy of the GNU General Public License #along with this program; if not, write to the Free Software #Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # simula <- function(N) { sn.obs <- function(x) { sum(sample(1:4,size=x,prob=c(1/8,1/4,1/4,3/8),replace=T)) } tam <- rpois(N,2) obs <- sapply(tam,sn.obs) obs } calcula.g <- function(R) { f <- function(k) { dist <- numeric(4) dist[1] <- 1/8 dist[2] <- 1/4 dist[3] <- 1/4 dist[4] <- 3/8 if (k < 5 & k > 0) { dist[k] } else { 0 } } g <- numeric(R+1) g[0+1] <- exp(-2) b <- 2 for (r in 1:R) { for (i in 1:r) { g[r+1] <- g[r+1] + (b*(i/r) * f(i)*g[r-i+1]) } } g }