Skip to content

Commit

Permalink
version 1.1-10
Browse files Browse the repository at this point in the history
  • Loading branch information
vigou3 authored and cran-robot committed Jul 22, 2015
1 parent e516d8c commit a5c1f7b
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 48 deletions.
10 changes: 5 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: actuar
Type: Package
Title: Actuarial Functions
Version: 1.1-9
Date: 2015-07-07
Title: Actuarial Functions and Heavy Tailed Distributions
Version: 1.1-10
Date: 2015-07-21
Author: Vincent Goulet, Sébastien Auclair, Christophe Dutang, Xavier Milhaud, Tommy Ouellet, Louis-Philippe Pouliot, Mathieu Pigeon
Maintainer: Vincent Goulet <[email protected]>
Description: Various actuarial science functionalities, mostly in the
Expand All @@ -18,6 +18,6 @@ Encoding: UTF-8
LazyLoad: yes
LazyData: yes
NeedsCompilation: yes
Packaged: 2015-07-07 04:39:21 UTC; vincent
Packaged: 2015-07-21 18:31:27 UTC; vincent
Repository: CRAN
Date/Publication: 2015-07-07 17:47:30
Date/Publication: 2015-07-22 05:39:47
20 changes: 10 additions & 10 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
6c98f190abfb9eaf689ba24b22453671 *DESCRIPTION
ee202b747521d14c0800420ac6225de7 *DESCRIPTION
f01ac1c1dbf0ba850ba9315e9543424d *NAMESPACE
2b47500be0644b64b6c9ab14f2356ac3 *R/BetaMoments.R
6d215e392a1b2b70f856cd1e49f6d99e *R/Burr.R
Expand Down Expand Up @@ -33,7 +33,7 @@ feff1a882dfe5ad292b24e7a46c6a031 *R/UniformSupp.R
6a6c80d4e9625d690d7edf2797539245 *R/adjCoef.R
89be0e9ee9c02d0cb5556c59242e2872 *R/aggregateDist.R
6003719eff1166bf3f15a1a549d35d7f *R/bstraub.R
0e4a3f079778ea08f0a1098131eed38c *R/cm.R
b439289d45a44970215a98b0c8b379c3 *R/cm.R
a998c2678650069ddf59ba3de5cb08e7 *R/coverage.R
c32846ed69862a886e61b7b3541a5d32 *R/discretize.R
db6e55d7e0892f18b8e1a3a59c349346 *R/elev.R
Expand All @@ -43,7 +43,7 @@ ad486fab27687ecdc47a75a88869f35f *R/emm.R
4f6f6db6a6319a9c7069e4627fe4d285 *R/hache.R
a7a0d7117b87cd6711d35f067735b625 *R/hache.barycenter.R
773e8ce24128753da4e171b20f930ba0 *R/hache.origin.R
e439b2ad83846d7de0a61f3a3653e820 *R/hierarc.R
0710727f28e9ebcc9e93fb591223ab58 *R/hierarc.R
edb051fc0253083324a5ec69089bf8ac *R/hist.grouped.data.R
ceec1a5dbf244493dd8152dc4d9ee7c2 *R/mde.R
d0a7c15fcdcc673220f8fed86d87a3df *R/mean.grouped.data.R
Expand All @@ -68,25 +68,25 @@ bba63751759ba972e59c0f726bec5793 *demo/credibility.R
f14c0b1400f7661fc5c6196ed3cb9fc9 *demo/risk.R
b80efa324a92b9837bac5dc570703220 *demo/simulation.R
72cebb6e34e6fc91c3f49e94076e49b3 *inst/CITATION
eac9e715aded68614c76bf5ae6cceeb6 *inst/NEWS.Rd
1be3a720a5cb8d727f3ce4bbccc26667 *inst/NEWS.Rd
e9e230719c1ce2dd97480f868a788a4a *inst/doc/actuar.R
1e75afa48b6e13b943ee62e8734c6d26 *inst/doc/actuar.Rnw
4bee2c3275abbe42f1bef5668f92230d *inst/doc/actuar.pdf
99e60a0ba98b7b20a8d8d83a33c971d4 *inst/doc/actuar.pdf
1b331713221e1e60f3ed2c76587f91d4 *inst/doc/coverage.R
78bbb13165709f6fa51a91828f2e47c7 *inst/doc/coverage.Rnw
3f5f36466d35e832ce87be6c9a2a96be *inst/doc/coverage.pdf
d56b7d6a8121eb110148c2a12f07d928 *inst/doc/coverage.pdf
095316e8b92f8ece50442242a605b0d9 *inst/doc/credibility.R
6a56532d23580a11645794c329bbc6f7 *inst/doc/credibility.Rnw
caf03d026b2d3f98172006d8a62a5833 *inst/doc/credibility.pdf
2903cd1c6c31813b60906d6767b266ea *inst/doc/credibility.pdf
e98c50c714c07c8f99344e672a4fd8ae *inst/doc/lossdist.R
1ff63cbe4a73147451f7807ebc26d704 *inst/doc/lossdist.Rnw
09095757912edc6c3e79c445c72d288a *inst/doc/lossdist.pdf
9003beacb4b6a3606b1224cb0fb80913 *inst/doc/lossdist.pdf
09ed3972808681d3f39d9d4ca1ef5680 *inst/doc/risk.R
030c28e042ad6fb45a3b63ec4a26e5ba *inst/doc/risk.Rnw
f0ccb55fe1b437c6361b595b05e7c4ca *inst/doc/risk.pdf
b5454a93dd4296842ef33ba4b92d63e8 *inst/doc/risk.pdf
5262b731901dd15c792ad62c7eaf81a9 *inst/doc/simulation.R
51441d46d497f553be2a62dc9a92fe6e *inst/doc/simulation.Rnw
4b6d0db334f4a020b37f2f589026b95c *inst/doc/simulation.pdf
9c62c737e6f23ced9ccd73fb00d9c61e *inst/doc/simulation.pdf
a58f13e70d228d4dc1d35fe01bd1df36 *inst/po/fr/LC_MESSAGES/R-actuar.mo
dd531e3860bcbe7a2f7d747b6f9894f4 *inst/po/fr/LC_MESSAGES/actuar.mo
4920e65f829fae0596babf70fc453816 *man/BetaMoments.Rd
Expand Down
2 changes: 1 addition & 1 deletion R/cm.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ cm <- function(formula, data, ratios, weights, subset,
## == DISPATCH TO APPROPRIATE CALCULATION FUNCTION ==
##
## Buhlmann-Straub models are handled by bstraub(), regression
## models by hache() and hierarcahical models by hierarc().
## models by hache() and hierarchical models by hierarc().
if (nlevels < 2) # one-dimensional model
{
## One-dimensional models accept only "unbiased" and
Expand Down
63 changes: 34 additions & 29 deletions R/hierarc.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ hierarc <- function(ratios, weights, classification,
## numbers, whereas 'classification' must be a matrix of integers
## giving the affiliation of each entity in the portfolio.
nlevels <- ncol(classification) # number of levels
nlevels1p <- nlevels + 1 # frequently used
nlevels1p <- nlevels + 1L # frequently used

## To symmetrize further calculations, bind a column of ones
## representing the affiliation to the global portfolio.
classification <- cbind(pf = 1, classification)
classification <- cbind(pf = 1L, classification)

## If weights are not specified, use equal weights.
if (missing(weights))
Expand Down Expand Up @@ -51,20 +51,25 @@ hierarc <- function(ratios, weights, classification,
## of nodes at one level [2] according to the number of nodes at
## the level below [c(3, 2)].
##
## 0. Initialization
fnodes <- nnodes <- vector("list", nlevels)

## 1. Calculation of the number of nodes: the main idea is to
## create a unique ID for each node by pasting together the
## elements in the rows of 'classification'. This is not required for the
## lowest level (the entities), though, since they are known to
## all be different.
## create a unique factor for each node using interaction()
## recursively on the columns of 'classification'. We can do
## something simpler for the lowest level (the entities), since we
## know the combinations of indexes to all be different at this
## level.
fx <- vector("list", nlevels1p)
fx[[nlevels1p]] <- factor(classification[, nlevels1p]) # entity level

fnodes <- nnodes <- vector("list", nlevels)

for (i in nlevels:1)
for (i in nlevels:1L)
{
fx[[i]] <- factor(apply(classification[, seq.int(i), drop = FALSE],
1, paste, collapse = ""))
## Function 'interaction' expects its arguments separately or
## as a list, hence the lapply() below.
fx[[i]] <- as.integer(interaction(lapply(seq.int(i),
function(j) classification[, j]),
drop = TRUE))
## 'as.vector' below is used to get rid of names
nnodes[[i]] <- as.vector(sapply(split(fx[[i + 1]], fx[[i]]),
function(x) length(unique(x))))
Expand All @@ -85,8 +90,8 @@ hierarc <- function(ratios, weights, classification,
## summary made using these factors will be sorted. This done, it
## is possible to use the command above for the upper levels.
fnodes[[nlevels]] <- as.integer(fx[[nlevels]])
fnodes[-nlevels] <-
lapply(nnodes[-nlevels], function(x) rep(seq_along(x), x))
fnodes[-nlevels] <- lapply(nnodes[-nlevels],
function(x) rep(seq_along(x), x))

## === PER ENTITY SUMMARIES ===
##
Expand All @@ -113,7 +118,7 @@ hierarc <- function(ratios, weights, classification,
## above.
eff.nnodes <- vector("list", nlevels)
w <- weights.s
for (i in nlevels:1)
for (i in nlevels:1L)
{
eff.nnodes[[i]] <- tapply(w, fnodes[[i]], function(x) sum(x > 0))
w <- tapply(w, fnodes[[i]], sum) # running totals
Expand All @@ -135,12 +140,12 @@ hierarc <- function(ratios, weights, classification,
## (effective) number of "sectors" - 1
##
## The 1 neither is included in 'eff.nnodes'.
denoms <- diff(c(1, sapply(eff.nnodes, sum), sum(!is.na(ratios))))
denoms <- diff(c(1L, sapply(eff.nnodes, sum), sum(!is.na(ratios))))

## Final sanity checks
if (any(!denoms))
stop("there must be at least two nodes at every level")
if (ncol(ratios) < 2)
if (ncol(ratios) < 2L)
stop("there must be at least one node with more than one period of experience")

## === ESTIMATION OF s^2 ===
Expand Down Expand Up @@ -189,33 +194,33 @@ hierarc <- function(ratios, weights, classification,
else # Ohlsson
bexp <- expression(b[i] <- sum(bi, na.rm = TRUE) / sum(ci, na.rm = TRUE))

for (i in nlevels:1)
for (i in nlevels:1L)
{
## Total weight of the level as per the rule above.
tweights[[i]] <- as.vector(tapply(tweights[[i + 1]], fnodes[[i]], sum))
tweights[[i]] <- as.vector(tapply(tweights[[i + 1L]], fnodes[[i]], sum))

## Calculation of the weighted averages of the level. Before
## the between variance is estimated, these use the total
## weights calculated above.
wmeans[[i]] <-
ifelse(tweights[[i]] > 0,
as.vector(tapply(tweights[[i + 1]] * wmeans[[i + 1]],
as.vector(tapply(tweights[[i + 1L]] * wmeans[[i + 1L]],
fnodes[[i]],
sum) / tweights[[i]]),
0)

## Latest non-zero between variance estimate -- the one used
## in the estimator and in the credibility factors.
between <- b[b != 0][1]
between <- b[b != 0][1L]

## Calculation of the per node variance estimate.
bi <- as.vector(tapply(tweights[[i + 1]] *
(wmeans[[i + 1]] - wmeans[[i]][fnodes[[i]]])^2,
bi <- as.vector(tapply(tweights[[i + 1L]] *
(wmeans[[i + 1L]] - wmeans[[i]][fnodes[[i]]])^2,
fnodes[[i]],
sum)) -
(eff.nnodes[[i]] - 1) * between
ci <- tweights[[i]] -
as.vector(tapply(tweights[[i + 1]]^2, fnodes[[i]], sum)) / tweights[[i]]
as.vector(tapply(tweights[[i + 1L]]^2, fnodes[[i]], sum)) / tweights[[i]]

## The final estimate is the average of all the per node estimates.
eval(bexp)
Expand All @@ -227,11 +232,11 @@ hierarc <- function(ratios, weights, classification,
#if (max(bu[i], 0)) # don't compute negative factors!
if (b[i])
{
cred[[i]] <- 1/(1 + between/(b[i] * tweights[[i + 1]]))
cred[[i]] <- 1/(1 + between/(b[i] * tweights[[i + 1L]]))
tweights[[i]] <- as.vector(tapply(cred[[i]], fnodes[[i]], sum))
wmeans[[i]] <-
ifelse(tweights[[i]] > 0,
as.vector(tapply(cred[[i]] * wmeans[[i + 1]],
as.vector(tapply(cred[[i]] * wmeans[[i + 1L]],
fnodes[[i]],
sum) / tweights[[i]]),
0)
Expand All @@ -254,8 +259,8 @@ hierarc <- function(ratios, weights, classification,
## the current level.
if (method == "iterative")
{
b <- pmax(b, 0) # truncation for starting values
if (any(head(b, -1) > 0)) # at least one non-zero starting value
b <- pmax(b, 0) # truncation for starting values
if (any(head(b, -1L) > 0)) # at least one non-zero starting value
.External("actuar_do_hierarc", cred, tweights, wmeans, fnodes, denoms,
b, tol, maxit, echo)
}
Expand All @@ -267,7 +272,7 @@ hierarc <- function(ratios, weights, classification,
iterative = if (method == "iterative") b,
cred = cred,
nodes = nnodes,
classification = classification[, -1],
classification = classification[, -1L],
ordering = fnodes),
class = "hierarc",
model = "hierarchical")
Expand Down Expand Up @@ -298,7 +303,7 @@ predict.hierarc <- function(object, levels = NULL, newdata, ...)
res <- vector("list", n)

## First level credibility premiums
res[[1]] <- means[[1]] + cred[[1]] * (means[[2]] - means[[1]])
res[[1L]] <- means[[1L]] + cred[[1L]] * (means[[2L]] - means[[1L]])

for (i in seq(2, length.out = n - 1))
{
Expand Down
17 changes: 14 additions & 3 deletions inst/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@
\title{actuar News}
\encoding{UTF-8}

\section{CHANGES IN VERSION 1.1-10}{
\subsection{BUG FIX}{
\itemize{
\item Results of 'cm' for hierarchical models would get
incorrectly sorted when there were 10 nodes or more at a given
level. Thanks to Dylan Wienke \email{dwienke2@gmail.com} for the
catch.
}
}
}

\section{CHANGES IN VERSION 1.1-9}{
\subsection{MAINTENANCE}{
\itemize{
\item Functions 'head' and 'tail' explicitly imported from package
utils in NAMESPACE to obey a new requirement of R 3.3.x.
utils in NAMESPACE as per a new requirement of R 3.3.x.
}
}
}
Expand All @@ -26,7 +37,7 @@
\subsection{BUG FIX}{
\itemize{
\item panjer() result was wrong for the "logarithmic" type of
frequency distribution. Thanks to <mmclaramunt@ub.edu> for the
frequency distribution. Thanks to \email{mmclaramunt@ub.edu} for the
catch.
}
}
Expand Down Expand Up @@ -75,7 +86,7 @@
GeneralizedHyperbolic on Solaris.
\item Wrong result given by levinvGauss() because the upper tail
of the normal distribution was used in the calculation instead of
the lower tail. Thanks to Dan Murphy <chiefmurphy@gmail.com> for
the lower tail. Thanks to Dan Murphy \email{chiefmurphy@gmail.com} for
the heads up.
}
}
Expand Down
Binary file modified inst/doc/actuar.pdf
Binary file not shown.
Binary file modified inst/doc/coverage.pdf
Binary file not shown.
Binary file modified inst/doc/credibility.pdf
Binary file not shown.
Binary file modified inst/doc/lossdist.pdf
Binary file not shown.
Binary file modified inst/doc/risk.pdf
Binary file not shown.
Binary file modified inst/doc/simulation.pdf
Binary file not shown.

0 comments on commit a5c1f7b

Please sign in to comment.