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
947298d2
Commit
947298d2
authored
7 years ago
by
Reinhold Kainhofer
Browse files
Options
Downloads
Patches
Plain Diff
Use the mortalityTable's @data$dim list/data.frame as further dimensions/factors in makeQxDataFrame
parent
09a0d925
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
R/makeQxDataFrame.R
+13
-10
13 additions, 10 deletions
R/makeQxDataFrame.R
with
13 additions
and
10 deletions
R/makeQxDataFrame.R
+
13
−
10
View file @
947298d2
...
@@ -24,42 +24,45 @@ makeQxDataFrame = function(..., YOB = 1972, Period = NA, reference = NULL) {
...
@@ -24,42 +24,45 @@ makeQxDataFrame = function(..., YOB = 1972, Period = NA, reference = NULL) {
data
=
unlist
(
list
(
...
));
data
=
unlist
(
list
(
...
));
if
(
is.null
(
data
))
return
(
data.frame
(
x
=
double
(),
y
=
double
(),
group
=
character
()))
if
(
is.null
(
data
))
return
(
data.frame
(
x
=
double
(),
y
=
double
(),
group
=
character
()))
names
(
data
)
=
lapply
(
data
,
function
(
t
)
t
@
name
);
reference_ages
=
NULL
;
reference_ages
=
NULL
;
if
(
missing
(
Period
))
{
if
(
missing
(
Period
))
{
# If reference is given, normalize all probabilities by that table!
# If reference is given, normalize all probabilities by that table!
if
(
!
missing
(
reference
))
{
if
(
!
missing
(
reference
)
&&
!
is.null
(
reference
)
)
{
reference_ages
=
ages
(
reference
);
reference_ages
=
ages
(
reference
);
reference
=
deathProbabilities
(
reference
,
YOB
=
YOB
);
reference
=
deathProbabilities
(
reference
,
YOB
=
YOB
);
}
}
data
=
lapply
(
data
,
function
(
t
)
{
data
=
lapply
(
data
,
function
(
t
)
{
normalize_deathProbabilities
(
normalize_deathProbabilities
(
cbind
(
x
=
ages
(
t
),
y
=
`names<-`
(
deathProbabilities
(
t
,
YOB
=
YOB
),
NULL
)),
if
(
is.data.frame
(
t
@
data
$
dim
)
||
is.list
(
t
@
data
$
dim
))
{
cbind
(
x
=
ages
(
t
),
y
=
`names<-`
(
deathProbabilities
(
t
,
YOB
=
YOB
),
NULL
),
group
=
t
@
name
,
as.data.frame
(
t
@
data
$
dim
))
}
else
{
cbind
(
x
=
ages
(
t
),
y
=
`names<-`
(
deathProbabilities
(
t
,
YOB
=
YOB
),
NULL
),
group
=
t
@
name
)
},
reference
=
reference
,
reference
=
reference
,
referenceAges
=
reference_ages
)
referenceAges
=
reference_ages
)
});
});
}
else
{
}
else
{
if
(
!
missing
(
reference
))
{
if
(
!
missing
(
reference
)
&&
!
is.null
(
reference
)
)
{
reference_ages
=
ages
(
reference
);
reference_ages
=
ages
(
reference
);
reference
=
periodDeathProbabilities
(
reference
,
Period
=
Period
);
reference
=
periodDeathProbabilities
(
reference
,
Period
=
Period
);
}
}
data
=
lapply
(
data
,
function
(
t
)
{
data
=
lapply
(
data
,
function
(
t
)
{
normalize_deathProbabilities
(
normalize_deathProbabilities
(
cbind
(
x
=
ages
(
t
),
y
=
periodDeathProbabilities
(
t
,
Period
=
Period
)),
ifelse
(
is.data.frame
(
t
@
data
$
dim
)
||
is.list
(
t
@
data
$
dim
),
cbind
(
x
=
ages
(
t
),
y
=
`names<-`
(
periodDeathProbabilities
(
t
,
Period
=
Period
),
NULL
),
group
=
t
@
name
,
as.data.frame
(
t
@
data
$
dim
)),
cbind
(
x
=
ages
(
t
),
y
=
`names<-`
(
periodDeathProbabilities
(
t
,
Period
=
Period
),
NULL
),
group
=
t
@
name
)
),
reference
=
reference
,
reference
=
reference
,
referenceAges
=
reference_ages
)
referenceAges
=
reference_ages
)
});
});
}
}
list.names
=
names
(
data
)
lns
<-
sapply
(
data
,
nrow
)
data
<-
as.data.frame
(
do.call
(
"rbind"
,
data
))
data
<-
as.data.frame
(
do.call
(
"rbind"
,
data
))
data
$
group
<-
rep
(
list.names
,
lns
)
data
data
}
}
normalize_deathProbabilities
=
function
(
data
,
reference
=
NULL
,
referenceAges
=
NULL
)
{
normalize_deathProbabilities
=
function
(
data
,
reference
=
NULL
,
referenceAges
=
NULL
)
{
if
(
missing
(
reference
)
||
missing
(
referenceAges
)
||
is.null
(
reference
)
||
is.null
(
referenceAges
))
{
if
(
missing
(
reference
)
||
missing
(
referenceAges
)
||
is.null
(
reference
)
||
is.null
(
referenceAges
))
{
return
(
data
);
return
(
data
);
}
}
...
@@ -71,7 +74,7 @@ normalize_deathProbabilities = function (data, reference = NULL, referenceAges =
...
@@ -71,7 +74,7 @@ normalize_deathProbabilities = function (data, reference = NULL, referenceAges =
# Find which ages in data do NOT exist in the reference ages (and are thus NOT normalized at all)
# Find which ages in data do NOT exist in the reference ages (and are thus NOT normalized at all)
# Print a warning!
# Print a warning!
missingrefs
=
setdiff
(
data
[,
"x"
],
referenceAges
)
missingrefs
=
setdiff
(
data
[,
"x"
],
referenceAges
)
if
(
length
(
missingrefs
)
>
0
)
{
if
(
length
(
missingrefs
)
>
0
)
{
warning
(
"Reference mortality table does not contain ages "
,
warning
(
"Reference mortality table does not contain ages "
,
missingrefs
,
missingrefs
,
" required for normalization. These ages will not be normalized!"
)
" required for normalization. These ages will not be normalized!"
)
...
...
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