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
03b2c5e7
Commit
03b2c5e7
authored
6 years ago
by
Reinhold Kainhofer
Browse files
Options
Downloads
Patches
Plain Diff
Allow list of mortalityTables objects in the mT.* utility functions
parent
fc41147e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
R/utilityFunctions.R
+34
-7
34 additions, 7 deletions
R/utilityFunctions.R
R/whittaker.mortalityTable.R
+4
-1
4 additions, 1 deletion
R/whittaker.mortalityTable.R
with
38 additions
and
8 deletions
R/utilityFunctions.R
+
34
−
7
View file @
03b2c5e7
...
@@ -76,8 +76,11 @@ fitExpExtrapolation = function(data, idx, up = TRUE, verbose = FALSE) {
...
@@ -76,8 +76,11 @@ fitExpExtrapolation = function(data, idx, up = TRUE, verbose = FALSE) {
#' @export
#' @export
mT.setName
=
function
(
table
,
name
=
table
@
name
)
{
mT.setName
=
function
(
table
,
name
=
table
@
name
)
{
if
(
is.list
(
table
))
{
return
(
lapply
(
table
,
mT.setName
,
name
=
name
))
}
if
(
!
is
(
table
,
"mortalityTable"
))
if
(
!
is
(
table
,
"mortalityTable"
))
stop
(
"First argument must be a mortalityTable."
)
stop
(
"First argument must be a mortalityTable
or a list of mortalityTable objects
."
)
table
@
name
=
name
table
@
name
=
name
table
table
...
@@ -87,8 +90,11 @@ mT.setName = function(table, name = table@name) {
...
@@ -87,8 +90,11 @@ mT.setName = function(table, name = table@name) {
#' @export
#' @export
mT.fillAges
=
function
(
table
,
neededAges
,
fill
=
0
)
{
mT.fillAges
=
function
(
table
,
neededAges
,
fill
=
0
)
{
if
(
is.list
(
table
))
{
return
(
lapply
(
table
,
mT.fillAges
,
neededAges
=
neededAges
,
fill
=
fill
))
}
if
(
!
is
(
table
,
"mortalityTable"
))
if
(
!
is
(
table
,
"mortalityTable"
))
stop
(
"First argument must be a mortalityTable."
)
stop
(
"First argument must be a mortalityTable
or a list of mortalityTable objects
."
)
existingAges
=
ages
(
table
)
existingAges
=
ages
(
table
)
if
(
.hasSlot
(
table
,
"ages"
))
if
(
.hasSlot
(
table
,
"ages"
))
...
@@ -110,6 +116,12 @@ mT.fillAges = function(table, neededAges, fill = 0) {
...
@@ -110,6 +116,12 @@ mT.fillAges = function(table, neededAges, fill = 0) {
#' @export
#' @export
mT.scaleProbs
=
function
(
table
,
factor
=
1.0
,
name.postfix
=
"scaled"
,
name
=
paste
(
table
@
name
,
name.postfix
))
{
mT.scaleProbs
=
function
(
table
,
factor
=
1.0
,
name.postfix
=
"scaled"
,
name
=
paste
(
table
@
name
,
name.postfix
))
{
if
(
is.list
(
table
))
{
return
(
lapply
(
table
,
mT.scaleProbs
,
factor
=
factor
,
name.postfix
=
name.postfix
,
name
=
name
))
}
if
(
!
is
(
table
,
"mortalityTable"
))
stop
(
"First argument must be a mortalityTable or a list of mortalityTable objects."
)
table
@
deathProbs
=
factor
*
table
@
deathProbs
table
@
deathProbs
=
factor
*
table
@
deathProbs
if
(
!
is.null
(
name
))
{
if
(
!
is.null
(
name
))
{
table
@
name
=
name
table
@
name
=
name
...
@@ -120,8 +132,11 @@ mT.scaleProbs = function(table, factor = 1.0, name.postfix = "scaled", name = pa
...
@@ -120,8 +132,11 @@ mT.scaleProbs = function(table, factor = 1.0, name.postfix = "scaled", name = pa
#' @export
#' @export
mT.setTrend
=
function
(
table
,
trend
,
trendages
=
ages
(
table
),
baseYear
=
table
@
baseYear
,
dampingFunction
=
identity
)
{
mT.setTrend
=
function
(
table
,
trend
,
trendages
=
ages
(
table
),
baseYear
=
table
@
baseYear
,
dampingFunction
=
identity
)
{
if
(
is.list
(
table
))
{
return
(
lapply
(
table
,
mT.setTrend
,
trend
=
trend
,
trendages
=
trendages
,
baseYear
=
baseYear
,
dampingFunction
=
dampingFunction
))
}
if
(
!
is
(
table
,
"mortalityTable"
))
if
(
!
is
(
table
,
"mortalityTable"
))
stop
(
"First argument must be a mortalityTable."
)
stop
(
"First argument must be a mortalityTable
or a list of mortalityTable objects
."
)
t
=
mortalityTable.trendProjection
(
t
=
mortalityTable.trendProjection
(
table
,
table
,
...
@@ -139,8 +154,11 @@ mT.addTrend = mT.setTrend
...
@@ -139,8 +154,11 @@ mT.addTrend = mT.setTrend
#' @export
#' @export
mT.extrapolateTrendExp
=
function
(
table
,
idx
,
up
=
TRUE
)
{
mT.extrapolateTrendExp
=
function
(
table
,
idx
,
up
=
TRUE
)
{
if
(
is.list
(
table
))
{
return
(
lapply
(
table
,
mT.extrapolateTrendExp
,
idx
=
idx
,
up
=
up
))
}
if
(
!
is
(
table
,
"mortalityTable"
))
if
(
!
is
(
table
,
"mortalityTable"
))
stop
(
"First argument must be a 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
))
table
@
trend
=
fitExpExtrapolation
(
table
@
trend
,
idx
=
idx
,
up
=
up
)
table
@
trend
=
fitExpExtrapolation
(
table
@
trend
,
idx
=
idx
,
up
=
up
)
...
@@ -152,8 +170,11 @@ mT.extrapolateTrendExp = function(table, idx, up = TRUE) {
...
@@ -152,8 +170,11 @@ mT.extrapolateTrendExp = function(table, idx, up = TRUE) {
#' @export
#' @export
mT.translate
=
function
(
table
,
baseYear
,
name
=
table
@
name
)
{
mT.translate
=
function
(
table
,
baseYear
,
name
=
table
@
name
)
{
if
(
is.list
(
table
))
{
return
(
lapply
(
table
,
mT.translate
,
baseYear
=
baseYear
,
name
=
name
))
}
if
(
!
is
(
table
,
"mortalityTable"
))
if
(
!
is
(
table
,
"mortalityTable"
))
stop
(
"First argument must be a mortalityTable."
)
stop
(
"First argument must be a mortalityTable
or a list of mortalityTable objects
."
)
table
@
deathProbs
=
periodDeathProbabilities
(
table
,
Period
=
baseYear
)
table
@
deathProbs
=
periodDeathProbabilities
(
table
,
Period
=
baseYear
)
table
@
baseYear
=
baseYear
table
@
baseYear
=
baseYear
...
@@ -164,8 +185,11 @@ mT.translate = function(table, baseYear, name = table@name) {
...
@@ -164,8 +185,11 @@ mT.translate = function(table, baseYear, name = table@name) {
#' @export
#' @export
mT.extrapolateProbsExp
=
function
(
table
,
age
,
up
=
TRUE
)
{
mT.extrapolateProbsExp
=
function
(
table
,
age
,
up
=
TRUE
)
{
if
(
is.list
(
table
))
{
return
(
lapply
(
table
,
mT.extrapolateProbsExp
,
age
=
age
,
up
=
up
))
}
if
(
!
is
(
table
,
"mortalityTable"
))
if
(
!
is
(
table
,
"mortalityTable"
))
stop
(
"First argument must be a mortalityTable."
)
stop
(
"First argument must be a mortalityTable
or a list of mortalityTable objects
."
)
if
(
.hasSlot
(
table
,
"deathProbs"
))
{
if
(
.hasSlot
(
table
,
"deathProbs"
))
{
idx
=
match
(
age
,
ages
(
table
))
idx
=
match
(
age
,
ages
(
table
))
...
@@ -222,8 +246,11 @@ mT.fitExtrapolationLaw = function(table, method = "LF2", law = "HP",
...
@@ -222,8 +246,11 @@ mT.fitExtrapolationLaw = function(table, method = "LF2", law = "HP",
#' @export
#' @export
mT.setDimInfo
=
function
(
table
,
...
,
append
=
TRUE
)
{
mT.setDimInfo
=
function
(
table
,
...
,
append
=
TRUE
)
{
if
(
is.list
(
table
))
{
return
(
lapply
(
table
,
mT.setDimInfo
,
...
,
append
=
append
))
}
if
(
!
is
(
table
,
"mortalityTable"
))
if
(
!
is
(
table
,
"mortalityTable"
))
stop
(
"First argument must be a mortalityTable."
)
stop
(
"First argument must be a mortalityTable
or a list of mortalityTable objects
."
)
if
(
append
)
{
if
(
append
)
{
table
@
data
$
dim
[
names
(
list
(
...
))]
=
list
(
...
)
table
@
data
$
dim
[
names
(
list
(
...
))]
=
list
(
...
)
...
...
This diff is collapsed.
Click to expand it.
R/whittaker.mortalityTable.R
+
4
−
1
View file @
03b2c5e7
...
@@ -67,8 +67,11 @@
...
@@ -67,8 +67,11 @@
#' @import scales
#' @import scales
#' @export
#' @export
whittaker.mortalityTable
=
function
(
table
,
lambda
=
10
,
d
=
2
,
name.postfix
=
", smoothed"
,
...
,
weights
=
NULL
,
log
=
TRUE
)
{
whittaker.mortalityTable
=
function
(
table
,
lambda
=
10
,
d
=
2
,
name.postfix
=
", smoothed"
,
...
,
weights
=
NULL
,
log
=
TRUE
)
{
if
(
is.list
(
table
))
{
return
(
lapply
(
table
,
whittaker.mortalityTable
,
lambda
=
lambda
,
d
=
d
,
name.postfix
=
name.postfix
,
...
,
weights
=
weights
,
log
=
log
))
}
if
(
!
is
(
table
,
"mortalityTable"
))
{
if
(
!
is
(
table
,
"mortalityTable"
))
{
stop
(
"Table object must be an instance of mortalityTable in whittaker.mortalityTable."
)
stop
(
"Table object must be an instance
(or list of instances)
of mortalityTable in whittaker.mortalityTable."
)
}
}
# append the postfix to the table name to distinguish it from the original (raw) table
# append the postfix to the table name to distinguish it from the original (raw) table
if
(
!
is.null
(
name.postfix
))
{
if
(
!
is.null
(
name.postfix
))
{
...
...
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