Coder Social home page Coder Social logo

pash's Introduction

pash - Pace and Shape Analysis in R

Build Status

pash lets you perform pace-shape analysis on life tables. Calculate a wide array of pace and shape metrics and use them to standardize and compare your data.

Install with r devtools::install_github("jschoeley/pash").

  • Step 1: Create a pace-shape object from life table columns using Inputlx() or Inputmx().
  • Step 2: Using the pace-shape object as argument, calculate pace measures with GetPace(), calculate shape measures with GetShape(), standardize a life table by pace and shape with StandardizeLT(), rebase your life table to a different age with RebaseLT().

pash's People

Contributors

jschoeley avatar mpascariu avatar

Stargazers

Yu-Teng Yan avatar Ugofilippo Basellini avatar

Watchers

James Cloos avatar  avatar

pash's Issues

ndx is named dx

This package uses demographic interval notation where applicable. The number of deaths of the life table population within interval [x, x+n) should therefore be ndx and not dx, which in turn would be the density of the ages at death for the life table population.

ex might become NaN

from Francisco Villavicencio: When dealing with very high death rates or death probabilities, the lx function may become 0 in the last age group (or even earlier). Therefore, the life expectancy (ex = Tx/lx) in the last age groups becomes NaN. We should modify the output such that when ex = NaN transform it into a 0.

Chiang's formula produces nqx above 1 in certain cases

It may produce probabilities > 1 in cases where age groups are wide, hazards are high and the nax is approximated using the uniform distribution of deaths or the constant force of mortality assumption. Therefore in these cases we should use other conversion formulas:

nqx = 1 - exp(-nmx*nx),
assuming a constant force of mortality within the age interval [x, x+n), and
nqx = 1 - (1-nmx / (1+0.5*nmx))^nx,
assuming a uniform distribution of deaths within the age interval [x, x+n).

nax in last age group may be NA

foo = subset(sweden5x5, period == "1755-1759" & sex == "female")
Inputnmx(x = foo$x, nmx = foo$nmx, nax = "udd", last_open = TRUE)

Implement ax calculation based on constant nmx assumption

Complements the "midpoint" method already implemented. Preston (2001), p. 46 gives an nax expression for the case where nmx is assumed to be constant over [x, x+n):

npx = exp(-n_nmx),
which implies,
nax = n + 1/nmx - n/(1 - exp(-n_nmx))

This can be used to get nax when nmx are provided.

If only lx or qx are provided as input and one makes the constant mx assumption we can use the following expressions derived from the above:

nmx = - ln(npx) / n
nax = -n/nqx - n/ln(npx) + n

Life-table Print Method Returns Incoherent Values

The life-table print method may produce incoherent ndx and lx values because it truncates to the lowest integer, e.g.

         x nax       nmx       nqx       npx     lx   ndx    nLx      Tx    ex
 [105,110) 2.5 3.836e-01 9.791e-01 2.087e-02      1     1      2       2  2.60
 [110,NA)  2.5 4.005e-01 1.000e+00 0.000e+00      1     1      1       1  2.50

Change the truncation to a rounding.

Shape measures return NA if last age group is open

Some shape measures depend on nx. If the last nx is NA then the shape measure will become NA.

foo = Inputlx(x = prestons_lx$x, lx = prestons_lx$lx, last_open = TRUE)
GetShape(foo)
   Entropy       Gini         CV   Variance     mu_bar    mxRatio    exRatio       ACFM      PSMAD      Gini2 
        NA         NA         NA         NA 0.01370616 0.85328792 0.85778984 0.99309819 1.52981405         NA 
     Gini3     Gini_v 
        NA         NA 

We need to find shape measure expression which do not depend on nx.

Error in Inputnmx() in defining lx

The lx is not correctly computed in Inputnmx() (line 378). We are deleting the k-th element - instead of the (k+1) - of a vector of k+1 cells. It should read lx = c(1, cumprod(npx)[-k]) instead of lx = c(1, 1*cumprod(npx))[-k].

Handling of open last age group in Inputlx() is crude

The width of the last age group (which is unknown for an open last age group) is simply set to the width of the preceding age group.

A better solution would be to extrapolate the last nmx based on the preceeding nmx and calculate the last nLx, using the constant hazard assumption, as 1/[last nmx].

`SurvivalQuantile` may output NA

Current implementation of survival quantile pace measure:

# Survival Quantile
SurvivalQuantile <- function (x, lx, q) {
  return(x[lx<=q][1])
}

Open ended life tables might very well end with an lx value higher than q. In this case NA is returned, whereas we may want to return the starting age of the last age group?

> SurvivalQuantile(1:9, seq(1, 0.1, -0.1), 0.1)
[1] NA
}

Shape measures return transformed values

The values returned by the various shape measures are transformed in order to harmonize them. The downside is that the transformed values don't represent what the name of the shape measure suggests. We should, by default, return an un-transformed value based on the common definition of the measure and give the option to return transformed values.

These are the transformations as we have them right now in the package, with x being the common definition of the measure.

LT Variance: x
Entropy: 1-x
Gini: x
Gini2: x
Gini3: x
Gini_v: 1-2x
CoefVar: 1-x
mx_ratio: 1-x
ex_ratio: 1-x
ACFM: 1-e^(-x)
PSMAD: 1-log(x)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.