-
Notifications
You must be signed in to change notification settings - Fork 35
Feature/182 add statisticswellbeingjava to calculate statistics #183
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
Merged
andrewbaxter439
merged 19 commits into
develop
from
feature/182-add-statisticswellbeingjava-to-calculate-statistics
Jun 2, 2025
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9d95175
new health statistics file
andrewbaxter439 8fe4742
add health stats calls to collector
andrewbaxter439 29809d8
fuller health stats calculations
andrewbaxter439 fccbd5a
add qaly and wellby calcs
andrewbaxter439 e51fd65
remove redundant benefit statistics
andrewbaxter439 1eee849
Update src/main/java/simpaths/data/statistics/HealthStatistics.java
andrewbaxter439 169b5f8
switch eq5d process to end of year
andrewbaxter439 289f667
add gender filter to SimPathsCollector for wellbeing statistics
andrewbaxter439 2a6a1e2
move adjustmant variable to class
andrewbaxter439 461bb43
alternate age+gender filter
andrewbaxter439 c31a7ed
re-insert adjustment variable
andrewbaxter439 7486ae9
apply gender filter
andrewbaxter439 1410ca9
tidy file header
andrewbaxter439 d8bb52c
added health statistics to testing
andrewbaxter439 07520f0
update expected health statistics
andrewbaxter439 6c476e7
remove failing test
andrewbaxter439 6252f69
Merge branch 'develop' into feature/182-add-statisticswellbeingjava-t…
andrewbaxter439 6ab56af
Revert "remove failing test"
andrewbaxter439 6741ffd
corrected health statistics test file
andrewbaxter439 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/main/java/simpaths/data/filters/AgeGenderCSfilter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package simpaths.data.filters; | ||
|
|
||
| import microsim.statistics.ICollectionFilter; | ||
| import simpaths.model.Person; | ||
| import simpaths.model.enums.Gender; | ||
|
|
||
| public class AgeGenderCSfilter implements ICollectionFilter { | ||
|
|
||
| private final Gender gender; | ||
| private final int ageFrom; | ||
| private final int ageTo; | ||
| public AgeGenderCSfilter(int ageFrom, int ageTo) { | ||
| super(); | ||
| this.ageFrom = ageFrom; | ||
| this.ageTo = ageTo; | ||
| this.gender = null; | ||
| } | ||
| public AgeGenderCSfilter(int ageFrom, int ageTo, Gender gender) { | ||
| super(); | ||
| this.ageFrom = ageFrom; | ||
| this.ageTo = ageTo; | ||
| this.gender = gender; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isFiltered(Object object) { | ||
| Person person = (Person) object; | ||
| if (this.gender == null) | ||
| return ( (person.getDag() >= ageFrom) && (person.getDag() <= ageTo) ); | ||
| else | ||
| return ( (person.getDag() >= ageFrom) && (person.getDag() <= ageTo) && (person.getDgn().equals(gender))); | ||
| } | ||
| } |
338 changes: 338 additions & 0 deletions
338
src/main/java/simpaths/data/statistics/HealthStatistics.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,338 @@ | ||
| package simpaths.data.statistics; | ||
|
|
||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.Transient; | ||
| import microsim.data.db.PanelEntityKey; | ||
| import microsim.statistics.CrossSection; | ||
| import microsim.statistics.IDoubleSource; | ||
| import microsim.statistics.functions.MeanArrayFunction; | ||
| import microsim.statistics.functions.PercentileArrayFunction; | ||
| import microsim.statistics.functions.SumArrayFunction; | ||
| import simpaths.data.filters.AgeGenderCSfilter; | ||
| import simpaths.model.Person; | ||
| import simpaths.model.SimPathsModel; | ||
| import simpaths.model.enums.Gender; | ||
|
|
||
| @Entity | ||
| public class HealthStatistics { | ||
|
|
||
| @Id | ||
| private PanelEntityKey key = new PanelEntityKey(1L); | ||
|
|
||
| @Column(name = "gender") | ||
| private String gender; | ||
|
|
||
| // mental health numeric | ||
| @Column(name = "dhm_mean") | ||
| private double dhm_mean; | ||
|
|
||
| @Column(name = "dhm_median") | ||
| private double dhm_median; | ||
|
|
||
| @Column(name = "dhm_p_10") | ||
| private double dhm_p_10; | ||
|
|
||
| @Column(name = "dhm_p_90") | ||
| private double dhm_p_90; | ||
|
|
||
| @Column(name = "dhm_p_25") | ||
| private double dhm_p_25; | ||
|
|
||
| @Column(name = "dhm_p_75") | ||
| private double dhm_p_75; | ||
|
|
||
| // MCS score numeric | ||
| @Column(name = "dhe_mcs_mean") | ||
| private double dhe_mcs_mean; | ||
|
|
||
| @Column(name = "dhe_mcs_median") | ||
| private double dhe_mcs_median; | ||
|
|
||
| @Column(name = "dhe_mcs_p_10") | ||
| private double dhe_mcs_p_10; | ||
|
|
||
| @Column(name = "dhe_mcs_p_90") | ||
| private double dhe_mcs_p_90; | ||
|
|
||
| @Column(name = "dhe_mcs_p_25") | ||
| private double dhe_mcs_p_25; | ||
|
|
||
| @Column(name = "dhe_mcs_p_75") | ||
| private double dhe_mcs_p_75; | ||
|
|
||
| // PCS score numeric | ||
| @Column(name = "dhe_pcs_mean") | ||
| private double dhe_pcs_mean; | ||
|
|
||
| @Column(name = "dhe_pcs_median") | ||
| private double dhe_pcs_median; | ||
|
|
||
| @Column(name = "dhe_pcs_p_10") | ||
| private double dhe_pcs_p_10; | ||
|
|
||
| @Column(name = "dhe_pcs_p_90") | ||
| private double dhe_pcs_p_90; | ||
|
|
||
| @Column(name = "dhe_pcs_p_25") | ||
| private double dhe_pcs_p_25; | ||
|
|
||
| @Column(name = "dhe_pcs_p_75") | ||
| private double dhe_pcs_p_75; | ||
|
|
||
| // Life Satisfaction numeric | ||
| @Column(name = "dls_mean") | ||
| private double dls_mean; | ||
|
|
||
| @Column(name = "dls_median") | ||
| private double dls_median; | ||
|
|
||
| @Column(name = "dls_p_10") | ||
| private double dls_p_10; | ||
|
|
||
| @Column(name = "dls_p_90") | ||
| private double dls_p_90; | ||
|
|
||
| @Column(name = "dls_p_25") | ||
| private double dls_p_25; | ||
|
|
||
| @Column(name = "dls_p_75") | ||
| private double dls_p_75; | ||
|
|
||
| @Column(name = "qualys") | ||
| private double qalys; | ||
|
|
||
| @Column(name = "wellbys") | ||
| private double wellbys; | ||
|
|
||
| //N | ||
| @Column(name = "N") | ||
| private int N; | ||
|
|
||
| @Transient | ||
| final static double WELLBEING_MEASURE_ADJUSTMENT = (double) 11 / 7; | ||
|
|
||
| public void setGender(String gender) { | ||
| this.gender = gender; | ||
| } | ||
|
|
||
| public void setDhm_mean(double dhm_mean) { | ||
| this.dhm_mean = dhm_mean; | ||
| } | ||
|
|
||
| public void setDhm_median(double dhm_median) { | ||
| this.dhm_median = dhm_median; | ||
| } | ||
|
|
||
| public void setDhm_p_10(double dhm_p_10) { | ||
| this.dhm_p_10 = dhm_p_10; | ||
| } | ||
|
|
||
| public void setDhm_p_90(double dhm_p_90) { | ||
| this.dhm_p_90 = dhm_p_90; | ||
| } | ||
|
|
||
| public void setDhm_p_25(double dhm_p_25) { | ||
| this.dhm_p_25 = dhm_p_25; | ||
| } | ||
|
|
||
| public void setDhm_p_75(double dhm_p_75) { | ||
| this.dhm_p_75 = dhm_p_75; | ||
| } | ||
|
|
||
| public void setDhe_mcs_mean(double dhe_mcs_mean) { | ||
| this.dhe_mcs_mean = dhe_mcs_mean; | ||
| } | ||
|
|
||
| public void setDhe_mcs_median(double dhe_mcs_median) { | ||
| this.dhe_mcs_median = dhe_mcs_median; | ||
| } | ||
|
|
||
| public void setDhe_mcs_p_10(double dhe_mcs_p_10) { | ||
| this.dhe_mcs_p_10 = dhe_mcs_p_10; | ||
| } | ||
|
|
||
| public void setDhe_mcs_p_90(double dhe_mcs_p_90) { | ||
| this.dhe_mcs_p_90 = dhe_mcs_p_90; | ||
| } | ||
|
|
||
| public void setDhe_mcs_p_25(double dhe_mcs_p_25) { | ||
| this.dhe_mcs_p_25 = dhe_mcs_p_25; | ||
| } | ||
|
|
||
| public void setDhe_mcs_p_75(double dhe_mcs_p_75) { | ||
| this.dhe_mcs_p_75 = dhe_mcs_p_75; | ||
| } | ||
|
|
||
| public void setDhe_pcs_mean(double dhe_pcs_mean) { | ||
| this.dhe_pcs_mean = dhe_pcs_mean; | ||
| } | ||
|
|
||
| public void setDhe_pcs_median(double dhe_pcs_median) { | ||
| this.dhe_pcs_median = dhe_pcs_median; | ||
| } | ||
|
|
||
| public void setDhe_pcs_p_10(double dhe_pcs_p_10) { | ||
| this.dhe_pcs_p_10 = dhe_pcs_p_10; | ||
| } | ||
|
|
||
| public void setDhe_pcs_p_90(double dhe_pcs_p_90) { | ||
| this.dhe_pcs_p_90 = dhe_pcs_p_90; | ||
| } | ||
|
|
||
| public void setDhe_pcs_p_25(double dhe_pcs_p_25) { | ||
| this.dhe_pcs_p_25 = dhe_pcs_p_25; | ||
| } | ||
|
|
||
| public void setDhe_pcs_p_75(double dhe_pcs_p_75) { | ||
| this.dhe_pcs_p_75 = dhe_pcs_p_75; | ||
| } | ||
|
|
||
| public void setDls_mean(double dls_mean) { | ||
| this.dls_mean = dls_mean; | ||
| } | ||
|
|
||
| public void setDls_median(double dls_median) { | ||
| this.dls_median = dls_median; | ||
| } | ||
|
|
||
| public void setDls_p_10(double dls_p_10) { | ||
| this.dls_p_10 = dls_p_10; | ||
| } | ||
|
|
||
| public void setDls_p_90(double dls_p_90) { | ||
| this.dls_p_90 = dls_p_90; | ||
| } | ||
|
|
||
| public void setDls_p_25(double dls_p_25) { | ||
| this.dls_p_25 = dls_p_25; | ||
| } | ||
|
|
||
| public void setDls_p_75(double dls_p_75) { | ||
| this.dls_p_75 = dls_p_75; | ||
| } | ||
|
|
||
| public void setN(int n) { | ||
| N = n; | ||
| } | ||
|
|
||
| public void setQalys(double qalys) { | ||
| this.qalys = qalys; | ||
| } | ||
|
|
||
| public void setWellbys(double wellbys) { | ||
| this.wellbys = wellbys; | ||
| } | ||
|
|
||
| public void update(SimPathsModel model, String gender_s) { | ||
|
|
||
|
|
||
| AgeGenderCSfilter ageGenderCSfilter; | ||
|
|
||
| if (gender_s.equals("Total")) { | ||
| ageGenderCSfilter = new AgeGenderCSfilter(18, 65); | ||
| } else { | ||
| ageGenderCSfilter = new AgeGenderCSfilter(18, 65, Gender.valueOf(gender_s)); | ||
| } | ||
|
|
||
| // set gender | ||
| setGender(gender_s); | ||
|
|
||
| // dhm score | ||
| CrossSection.Double personsDhm = new CrossSection.Double(model.getPersons(), Person.DoublesVariables.Dhm); // Get cross section of simulated individuals and their mental health using the IDoubleSource interface implemented by Person class. | ||
| personsDhm.setFilter(ageGenderCSfilter); | ||
|
|
||
|
|
||
| MeanArrayFunction dhm_mean_f = new MeanArrayFunction(personsDhm); // Create MeanArrayFunction | ||
| dhm_mean_f.applyFunction(); | ||
| setDhm_mean(dhm_mean_f.getDoubleValue(IDoubleSource.Variables.Default)); | ||
|
|
||
| PercentileArrayFunction percDhm_f = new PercentileArrayFunction(personsDhm); | ||
| percDhm_f.applyFunction(); | ||
|
|
||
| setDhm_p_10(percDhm_f.getDoubleValue(PercentileArrayFunction.Variables.P10)); | ||
| setDhm_p_25(percDhm_f.getDoubleValue(PercentileArrayFunction.Variables.P25)); | ||
| setDhm_median(percDhm_f.getDoubleValue(PercentileArrayFunction.Variables.P50)); | ||
| setDhm_p_75(percDhm_f.getDoubleValue(PercentileArrayFunction.Variables.P75)); | ||
| setDhm_p_90(percDhm_f.getDoubleValue(PercentileArrayFunction.Variables.P90)); | ||
|
|
||
andrewbaxter439 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // mcs score | ||
| CrossSection.Double personsMCS = new CrossSection.Double(model.getPersons(), Person.DoublesVariables.Dhe_mcs); | ||
| personsMCS.setFilter(ageGenderCSfilter); | ||
|
|
||
|
|
||
| MeanArrayFunction dhe_mcs_mean_f = new MeanArrayFunction(personsMCS); // Create MeanArrayFunction | ||
| dhe_mcs_mean_f.applyFunction(); | ||
| setDhe_mcs_mean(dhe_mcs_mean_f.getDoubleValue(IDoubleSource.Variables.Default)); | ||
|
|
||
| PercentileArrayFunction perc_dhe_mcs_f = new PercentileArrayFunction(personsMCS); | ||
| perc_dhe_mcs_f.applyFunction(); | ||
|
|
||
| setDhe_mcs_p_10(perc_dhe_mcs_f.getDoubleValue(PercentileArrayFunction.Variables.P10)); | ||
| setDhe_mcs_p_25(perc_dhe_mcs_f.getDoubleValue(PercentileArrayFunction.Variables.P25)); | ||
| setDhe_mcs_median(perc_dhe_mcs_f.getDoubleValue(PercentileArrayFunction.Variables.P50)); | ||
| setDhe_mcs_p_75(perc_dhe_mcs_f.getDoubleValue(PercentileArrayFunction.Variables.P75)); | ||
| setDhe_mcs_p_90(perc_dhe_mcs_f.getDoubleValue(PercentileArrayFunction.Variables.P90)); | ||
|
|
||
| // pcs score | ||
| CrossSection.Double personsPCS = new CrossSection.Double(model.getPersons(), Person.DoublesVariables.Dhe_pcs); | ||
| personsPCS.setFilter(ageGenderCSfilter); | ||
|
|
||
|
|
||
| MeanArrayFunction dhe_pcs_mean_f = new MeanArrayFunction(personsPCS); // Create MeanArrayFunction | ||
| dhe_pcs_mean_f.applyFunction(); | ||
| setDhe_pcs_mean(dhe_pcs_mean_f.getDoubleValue(IDoubleSource.Variables.Default)); | ||
|
|
||
| PercentileArrayFunction perc_dhe_pcs_f = new PercentileArrayFunction(personsPCS); | ||
| perc_dhe_pcs_f.applyFunction(); | ||
|
|
||
| setDhe_pcs_p_10(perc_dhe_pcs_f.getDoubleValue(PercentileArrayFunction.Variables.P10)); | ||
| setDhe_pcs_p_25(perc_dhe_pcs_f.getDoubleValue(PercentileArrayFunction.Variables.P25)); | ||
| setDhe_pcs_median(perc_dhe_pcs_f.getDoubleValue(PercentileArrayFunction.Variables.P50)); | ||
| setDhe_pcs_p_75(perc_dhe_pcs_f.getDoubleValue(PercentileArrayFunction.Variables.P75)); | ||
| setDhe_pcs_p_90(perc_dhe_pcs_f.getDoubleValue(PercentileArrayFunction.Variables.P90)); | ||
|
|
||
| // Life Satisfaction score | ||
| CrossSection.Double personsDls = new CrossSection.Double(model.getPersons(), Person.DoublesVariables.Dls); | ||
| personsDls.setFilter(ageGenderCSfilter); | ||
|
|
||
|
|
||
| MeanArrayFunction dls_mean_f = new MeanArrayFunction(personsDls); // Create MeanArrayFunction | ||
| dls_mean_f.applyFunction(); | ||
| setDls_mean(dls_mean_f.getDoubleValue(IDoubleSource.Variables.Default)); | ||
|
|
||
| PercentileArrayFunction perc_dls_f = new PercentileArrayFunction(personsDls); | ||
| perc_dls_f.applyFunction(); | ||
|
|
||
| setDls_p_10(perc_dls_f.getDoubleValue(PercentileArrayFunction.Variables.P10)); | ||
| setDls_p_25(perc_dls_f.getDoubleValue(PercentileArrayFunction.Variables.P25)); | ||
| setDls_median(perc_dls_f.getDoubleValue(PercentileArrayFunction.Variables.P50)); | ||
| setDls_p_75(perc_dls_f.getDoubleValue(PercentileArrayFunction.Variables.P75)); | ||
| setDls_p_90(perc_dls_f.getDoubleValue(PercentileArrayFunction.Variables.P90)); | ||
|
|
||
| // QALYS as sum of EQ5D | ||
| CrossSection.Double personEQ5D = new CrossSection.Double(model.getPersons(), Person.DoublesVariables.He_eq5d); | ||
| personEQ5D.setFilter(ageGenderCSfilter); | ||
|
|
||
| SumArrayFunction.Double qalys = new SumArrayFunction.Double(personEQ5D); | ||
| qalys.applyFunction(); | ||
| setQalys(qalys.getDoubleValue(IDoubleSource.Variables.Default)); | ||
|
|
||
| // WELLBYs as sum of 'points' in 0-10-scale life satisfaction (adjusted) | ||
|
|
||
| SumArrayFunction.Double wellbys = new SumArrayFunction.Double(personsDls); | ||
| wellbys.applyFunction(); | ||
|
|
||
|
|
||
| setWellbys(wellbys.getDoubleValue(IDoubleSource.Variables.Default) * WELLBEING_MEASURE_ADJUSTMENT); | ||
|
|
||
| // count | ||
| CrossSection.Integer n_persons = new CrossSection.Integer(model.getPersons(), Person.class, "getPersonCount", true); | ||
| n_persons.setFilter(ageGenderCSfilter); | ||
|
|
||
| SumArrayFunction.Integer count_f = new SumArrayFunction.Integer(n_persons); | ||
| count_f.applyFunction(); | ||
| setN(count_f.getIntValue(IDoubleSource.Variables.Default)); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.