Commit ed53d0d3 by Reinhold Kainhofer

Add "log" argument to whittaker.mortalityTable that controls whether the...

Add "log" argument to whittaker.mortalityTable that controls whether the log-values or the values itself are smoothed (e.g. qx are log-smoothed, hx are smoothed directly)
parent b64e75b5
 ... ... @@ -22,6 +22,8 @@ #' or equal weights are used. Weight 0 for a certain age indicates #' that the observation will not be used for smoothing at all, #' and will rather be interpolated from the smoothing of all other values. #' @param log Whether the smoothing should be applied to the logarithms of the #' table values or the values itself #' @param ... additional arguments (currently unused) #' #' @references ... ... @@ -64,7 +66,7 @@ #' #' @import scales #' @export whittaker.mortalityTable = function(table, lambda = 10, d = 2, name.postfix = ", smoothed", ..., weights = NULL) { whittaker.mortalityTable = function(table, lambda = 10, d = 2, name.postfix = ", smoothed", ..., weights = NULL, log = TRUE) { if (!is(table, "mortalityTable")) { stop("Table object must be an instance of mortalityTable in whittaker.mortalityTable.") } ... ... @@ -84,9 +86,12 @@ whittaker.mortalityTable = function(table, lambda = 10, d = 2, name.postfix = ", weights = table@exposures } } # Missing values are always interpolated, i.e. assigned weight 0; Similarly, # ignore zero probabilities (cause problems with log) weights = weights * (!is.na(probs) & (probs > 0)) # Missing values are always interpolated, i.e. assigned weight 0; weights = weights * !is.na(probs) # Similarly, for log-smoothing ignore zero probabilities (cause problems with log) if (log) { weights = weights * (probs > 0) } weights[is.na(weights)] = 0 if (sum(probs > 0, na.rm = TRUE) < d) { warning("Table '", table@name, "' does not have at least ", d, " finite, non-zero probabilities. Unable to graduate. The original probabilities will be retained.") ... ... @@ -99,7 +104,11 @@ whittaker.mortalityTable = function(table, lambda = 10, d = 2, name.postfix = ", # We cannot pass NA to whittaker, as this will result in all-NA graduated values. # However, if prob==NA, then weight was already set to 0, anyway probs[is.na(probs)] = 0 if (log) { probs.smooth = exp(whittaker.interpolate(log(probs), lambda = lambda, d = d, weights = weights)) } else { probs.smooth = whittaker.interpolate(probs, lambda = lambda, d = d, weights = weights) } # Do not extrapolate probabilities, so set all ages below the first and # above the last raw probability to NA ... ...
 ... ... @@ -5,7 +5,7 @@ \title{Smooth a life table using the Whittaker-Henderson method, intepolation possibly missing values} \usage{ whittaker.mortalityTable(table, lambda = 10, d = 2, name.postfix = ", smoothed", ..., weights = NULL) name.postfix = ", smoothed", ..., weights = NULL, log = TRUE) } \arguments{ \item{table}{Mortality table to be graduated. Must be an instance of a ... ... @@ -24,6 +24,9 @@ will be interpolated. If not given, the exposures of the table or equal weights are used. Weight 0 for a certain age indicates that the observation will not be used for smoothing at all, and will rather be interpolated from the smoothing of all other values.} \item{log}{Whether the smoothing should be applied to the logarithms of the table values or the values itself} } \description{ \code{whittaker.mortalityTable} uses the Whittaker-Henderson graduation method ... ...
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.9217251539230347, "perplexity": 10326.165483169025}, "config": {"markdown_headings": false, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2020-40/segments/1600401583556.73/warc/CC-MAIN-20200928010415-20200928040415-00706.warc.gz"}