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

Long, tidy version of tables #111

Open
3 tasks
alecloudenback opened this issue Sep 28, 2021 · 3 comments
Open
3 tasks

Long, tidy version of tables #111

alecloudenback opened this issue Sep 28, 2021 · 3 comments

Comments

@alecloudenback
Copy link
Member

End goal of #109

Preliminary work completed in example here: https://juliaactuary.org/tutorials/mortalitytablesdataframe/

"""
	long(m::MortalityTable)

Return an array of tuples containing `issue_age`,`attained_age`,`duration`,`select` rate, and `ultimate` rate.

"""
function long(m::MortalityTables.SelectUltimateTable)
	earliest_age = min(firstindex(m.select),firstindex(m.ultimate))
	last_age = max(lastindex(m.select),lastindex(m.ultimate))
	
	table = map(earliest_age:last_age) do issue_age
		map(issue_age:last_age) do attained_age
			# use `get` to provide default missing value
			ultimate = get(m.ultimate,attained_age,missing)
			if issue_age <= lastindex(m.select)
				select = get(m.select[issue_age],attained_age,missing)
			else
				select = missing
			end
			duration = attained_age - issue_age + 1
			(;issue_age,attained_age, duration, select,ultimate)
		end
	end
	
	vcat(table...)
		
	
end

"""
	long(m::MortalityTable)

Return an array of tuples containing `issue_age`,`attained_age`,`duration`,`select` rate, and `ultimate` rate.

"""
function long(m::MortalityTables.UltimateTable)
	earliest_age = firstindex(m.ultimate)
	last_age = lastindex(m.ultimate)
	
	table = map(earliest_age:last_age) do issue_age
		map(issue_age:last_age) do attained_age
			# use `get` to provide default missing value
			ultimate = get(m.ultimate,attained_age,missing)
			select = missing
			duration = attained_age - issue_age + 1
			(;issue_age,attained_age, duration, select,ultimate)
		end
	end
	
	vcat(table...)
		
	
end

To-dos

@MatthewCaseres
Copy link
Contributor

Would it make sense to provide the same tables from Pymort's "Relational Tables API"? Open to feedback on the structure of the tables.

@alecloudenback
Copy link
Member Author

alecloudenback commented Jun 12, 2022

@MatthewCaseres are you suggesting providing some sort of "table set" interface (e.g. a way to get all of CS0 2017 together) or about the layout of the tables themselves (i.e. how a "long" version of the tables should look)?

@MatthewCaseres
Copy link
Contributor

MatthewCaseres commented Jun 12, 2022

I think both? I reconsidered my original idea of what a long mortality table was, and now am just trying to replicate the structure of a relational database, so that is what influences the design of the Relational() object.

Table groupings are derived from the metadata table's study/group fields. I am about to ship this - actuarialopensource/pymort@8bdfec8 which takes the metadata table and provides the table set interface.

The end goal is that I can do this -

group = getGroup(3209)
ultimates = jnp.array([MortXML(id).tables[0].Table.numpy for id in group])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: New features
Development

No branches or pull requests

2 participants