triangle S3 Methods | R Documentation |
Functions to ease the work with triangle shaped matrix data. A 'triangle' is a matrix with some generic functions.
triangle
creates a triangle from the given set of vectors of
observed data.
as.triangle
attempts to turn its argument into a triangle.
Triangles are usually stored in a “long” format in data bases. The
function can transform a data.frame
into a triangle shape.
as.data.frame
turns a triangle into a data frame.
triangle(..., bycol=FALSE, origin="origin", dev="dev", value="value")
## S3 method for class 'matrix'
as.triangle(Triangle, origin="origin", dev="dev", value="value", ...)
## S3 method for class 'data.frame'
as.triangle(Triangle, origin="origin", dev="dev", value="value", ...)
## S3 method for class 'triangle'
as.data.frame(x, row.names=NULL, optional, lob=NULL, na.rm=FALSE, ...)
as.triangle(Triangle, origin="origin", dev="dev", value="value", ...)
## S3 method for class 'triangle'
plot(x, type = "b", xlab = "dev. period", ylab = NULL, lattice=FALSE, ...)
Triangle |
a triangle |
bycol |
logical. If |
origin |
name of the origin period, default is |
dev |
name of the development period, default is |
value |
name of the value, default is |
row.names |
default is set to |
lob |
default is |
optional |
not used |
na.rm |
logical. Remove missing values? |
x |
a matrix of class 'triangle' |
xlab |
a label for the x axis, defaults to 'dev. period' |
ylab |
a label for the y axis, defaults to NULL |
lattice |
logical. If |
type |
type, see |
... |
vectors of data in |
Function triangle
builds a triangle matrix from the vectors of
known data provided in ...
. Normally, each of these
vectors should be one shorter than the preceeding one. The length of
the first vector dictates the number of development periods or origin
periods (respectively when bycol
is FALSE
or
TRUE
). As a special case, the function will build an n
\times n
triangle from a single vector of n(n + 1)/2
data
points.
The names of the arguments in ...
for function
triangle
(when there are more than one) are retained for
row/column names. Similarly, the names of the elements of the
first argument are used as column/row names.
Please note that for the function as.triangle
the origin and
dev. period columns have to be of type numeric or a character which can be
converted into numeric.
Also note that when converting from a data.frame to a matrix with
as.triangle
, multiple records with the same origin
and
dev
will be aggregated.
Markus Gesmann, Dan Murphy, Vincent Goulet
GenIns
plot(GenIns)
plot(GenIns, lattice=TRUE)
## Convert long format into triangle
## Triangles are usually stored as 'long' tables in data bases
head(GenInsLong)
as.triangle(GenInsLong, origin="accyear", dev="devyear", "incurred claims")
X <- as.data.frame(RAA)
head(X)
Y <- as.data.frame(RAA, lob="General Liability")
head(Y)
## Basic creation of a triangle from loss development data
triangle(c(100, 150, 175, 180, 200),
c(110, 168, 192, 205),
c(115, 169, 202),
c(125, 185),
150)
## Same, with named origin periods
triangle("2012" = c(100, 150, 175, 180, 200),
"2013" = c(110, 168, 192, 205),
"2014" = c(115, 169, 202),
"2015" = c(125, 185),
"2016" = 150)
## Again, with also named development periods
triangle("2012" = c("12 months" = 100,
"24 months" = 150,
"36 months" = 175,
"48 months" = 180,
"60 months" = 200),
"2013" = c(110, 168, 192, 205),
"2014" = c(115, 169, 202),
"2015" = c(125, 185),
"2016" = 150)
## Quick, simplified usage
triangle(c(100, 150, 175, 110, 168, 115))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.