Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pace & Shape #47

Closed
iainmstott opened this issue Feb 4, 2019 · 8 comments
Closed

Pace & Shape #47

iainmstott opened this issue Feb 4, 2019 · 8 comments
Assignees

Comments

@iainmstott
Copy link
Collaborator

Hi all

I'm currently working on my fork adding Pace & Shape measurements to Rage that Annette Baudisch and I have been developing; if we want, these can eventually be incorporated into the package itself (alongside other more standard ones we'll either have or would make sense, e.g. life expectancy, Keyfitz Delta, Gini).

For the new measures (which [humble brag] if I say so myself are more generalisable and comparable than many other shape measures), I need to calculate area under a curve. The only function I know of (MESS::auc) has a lot of dependencies at 10 or more. I wanna either ask whether people are OK with this, or whether they know of a lighter option (or want to press me to find one), if indeed these measures would be useful in the package eventually.

@jonesor
Copy link
Owner

jonesor commented Feb 4, 2019

I am OK with that. Adding this extra functionality will be awesome!

@patrickbarks
Copy link
Collaborator

Awesome, I would love to have shape functions in Rage!

Perhaps the integrate function in stats would work for area under the curve?

# integrate unit normal from 0 to infinity
fn_to_integrate <- function (t) dnorm(t, 0, 1)
integrate(fn_to_integrate, lower = 0, upper = Inf)$value

@levisc8
Copy link
Collaborator

levisc8 commented Feb 4, 2019

Does the curve in question always have finite limits? and would midpoint rule approximations be acceptably accurate? If yes to both, then I think it could be written using just base R.

On the other hand, I have no idea if Pace and Shape metrics satisfy both requirements above ;)

@iainmstott
Copy link
Collaborator Author

Depends how you want to do it. The curves will always be simple life-table-type-things (lx for sure, and some fertility analogue to lx that we've developed). They should always have evenly spaced categories for x, but in theory don't have to. Area under curve is an exact measure assuming constant mortality / fertility within discrete intervals, midpoint... I don't know. I didn't immediately turn to integration as the data aren't functions, but the stats option might work. I'll take a look... would be preferable to having so many dependencies. I can compare the results to the ones I get from area under curve.

@patrickbarks
Copy link
Collaborator

If you assume a constant rate of change over discrete intervals, then I think MESS::auc, the midpoint rule, and the trapezoid rule are all equivalent. There's an implementation of the trapezoid rule within kEntropy.R that you might be able to recycle:

x <- 0:5
lx <- c(1, 0.8, 0.7, 0.2, 0.1, 0.002)

TrapezoidRule(lx) # 2.301
MESS::auc(x, lx)  # 2.301

Though this example assumes a constant rate of change in lx within intervals rather than a constant hazard within intervals, per se.

@iainmstott
Copy link
Collaborator Author

Good point. In that case it becomes a question of whether we want to support only evenly spaced intervals or some more funky things. Life tables should never be mahoosive, so to be honest I might just write my own function which calculates the area: it's just a bunch of different size trapezoids...

@iainmstott
Copy link
Collaborator Author

...which is equivalent to a bunch of different size rectangles, I guess!

@jonesor
Copy link
Owner

jonesor commented Feb 18, 2021

@iainmstott Can you update me with the status of your pace/shape functions?
I'm wondering if I can close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants