Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
R - Mortality Tables
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
R
R - Mortality Tables
Commits
0ff21de2
Commit
0ff21de2
authored
6 years ago
by
Reinhold Kainhofer
Browse files
Options
Downloads
Patches
Plain Diff
Add function mT.round to round all base probabilities and trends to a given number of digits
parent
1f14254e
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
NAMESPACE
+1
-0
1 addition, 0 deletions
NAMESPACE
R/utilityFunctions.R
+69
-2
69 additions, 2 deletions
R/utilityFunctions.R
man/setModification.Rd
+6
-1
6 additions, 1 deletion
man/setModification.Rd
with
76 additions
and
3 deletions
NAMESPACE
+
1
−
0
View file @
0ff21de2
...
...
@@ -63,6 +63,7 @@ exportMethods(getCohortTable)
exportMethods(getOmega)
exportMethods(getPeriodTable)
exportMethods(lifeTable)
exportMethods(mT.round)
exportMethods(mortalityImprovement)
exportMethods(periodDeathProbabilities)
exportMethods(periodTransitionProbabilities)
...
...
This diff is collapsed.
Click to expand it.
R/utilityFunctions.R
+
69
−
2
View file @
0ff21de2
...
...
@@ -190,9 +190,9 @@ mT.extrapolateTrendExp = function(table, idx, up = TRUE) {
if
(
!
is
(
table
,
"mortalityTable"
))
stop
(
"First argument must be a mortalityTable or a list of mortalityTable objects."
)
if
(
.hasSlot
(
table
,
"trend"
)
&&
!
is.null
(
table
@
trend
))
if
(
.hasSlot
(
table
,
"trend"
)
&&
!
is.null
(
table
@
trend
)
&&
length
(
table
@
trend
)
>
1
)
table
@
trend
=
fitExpExtrapolation
(
table
@
trend
,
idx
=
idx
,
up
=
up
)
if
(
.hasSlot
(
table
,
"trend2"
)
&&
!
is.null
(
table
@
trend2
))
if
(
.hasSlot
(
table
,
"trend2"
)
&&
!
is.null
(
table
@
trend2
)
&&
length
(
table
@
trend2
)
>
1
)
table
@
trend2
=
fitExpExtrapolation
(
table
@
trend2
,
idx
=
idx
,
up
=
up
)
table
}
...
...
@@ -327,3 +327,70 @@ pT.getSubTable = function(table, subtable = "qx") {
NULL
}
#' @exportMethod mT.round
setGeneric
(
"mT.round"
,
function
(
object
,
digits
=
8
)
standardGeneric
(
"mT.round"
));
#' @describeIn setModification Return the life table with the given modification set
setMethod
(
"mT.round"
,
"mortalityTable"
,
function
(
object
,
digits
=
8
)
{
object
})
setMethod
(
"mT.round"
,
"mortalityTable.period"
,
function
(
object
,
digits
=
8
)
{
o
=
callNextMethod
()
o
@
deathProbs
=
round
(
o
@
deathProbs
,
digits
=
digits
)
o
@
loading
=
round
(
o
@
loading
,
digits
=
digits
)
o
})
setMethod
(
"mT.round"
,
"mortalityTable.trendProjection"
,
function
(
object
,
digits
=
8
)
{
o
=
callNextMethod
()
if
(
!
is.null
(
o
@
trend
)
&&
!
is.na
(
o
@
trend
))
{
o
@
trend
=
round
(
o
@
trend
,
digits
=
digits
)
}
if
(
!
is.null
(
o
@
trend2
)
&&
!
is.na
(
o
@
trend2
))
{
o
@
trend2
=
round
(
o
@
trend2
,
digits
=
digits
)
}
o
})
setMethod
(
"mT.round"
,
"mortalityTable.improvementFactors"
,
function
(
object
,
digits
=
8
)
{
o
=
callNextMethod
()
o
@
improvement
=
round
(
o
@
improvement
,
digits
=
digits
)
if
(
!
is.null
(
o
@
loading
)
&&
!
is.na
(
o
@
loading
))
{
o
@
loading
=
round
(
o
@
loading
,
digits
=
digits
)
}
o
})
setMethod
(
"mT.round"
,
"array"
,
function
(
object
,
digits
=
8
)
{
array
(
lapply
(
object
,
mT.round
,
digits
=
digits
),
dim
=
dim
(
object
),
dimnames
=
dimnames
(
object
))
})
setMethod
(
"mT.round"
,
"list"
,
function
(
object
,
digits
=
8
)
{
lapply
(
object
,
mT.round
,
digits
=
digits
)
})
setMethod
(
"mT.round"
,
"pensionTable"
,
function
(
object
,
digits
=
8
)
{
object
@
qx
=
mT.round
(
object
@
qx
,
digits
=
digits
)
object
@
ix
=
mT.round
(
object
@
ix
,
digits
=
digits
)
object
@
qix
=
mT.round
(
object
@
qix
,
digits
=
digits
)
object
@
rx
=
mT.round
(
object
@
rx
,
digits
=
digits
)
object
@
apx
=
mT.round
(
object
@
apx
,
digits
=
digits
)
object
@
qpx
=
mT.round
(
object
@
qpx
,
digits
=
digits
)
object
@
hx
=
mT.round
(
object
@
hx
,
digits
=
digits
)
object
@
qwy
=
mT.round
(
object
@
qwy
,
digits
=
digits
)
object
@
qgx
=
mT.round
(
object
@
qgx
,
digits
=
digits
)
object
})
# pensionTables.list()
# pensionTables.load("*")
# library(tidyverse)
# AVOe2008P.male %>% mT.round(digits = 2)
This diff is collapsed.
Click to expand it.
man/setModification.Rd
+
6
−
1
View file @
0ff21de2
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/setModification.R
% Please edit documentation in R/setModification.R
, R/utilityFunctions.R
\docType{methods}
\name{setModification}
\alias{setModification}
\alias{setModification,mortalityTable-method}
\alias{mT.round,mortalityTable-method}
\title{Return a copy of the table with the given modification function added}
\usage{
setModification(object, modification = 0)
\S4method{setModification}{mortalityTable}(object, modification = 0)
\S4method{mT.round}{mortalityTable}(object, digits = 8)
}
\arguments{
\item{object}{A life table object (instance of a \code{mortalityTable} class)}
...
...
@@ -20,6 +23,8 @@ Return a copy of the table with the given modification function added
}
\section{Methods (by class)}{
\itemize{
\item \code{mortalityTable}: Return the life table with the given modification set
\item \code{mortalityTable}: Return the life table with the given modification set
}}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment