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

fix age15plus indexing #5

Open
wants to merge 132 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
24590d6
implemented likelihood for age-specific prevalence and mortality
jeffeaton Sep 22, 2016
baab1e1
more efficient version of ageprev() function
jeffeaton Sep 24, 2016
b1093c0
estimate age-specific incidence rate ratios
jeffeaton Sep 24, 2016
3f6ec38
add fitmod() and specfit method for simfit()
jeffeaton Oct 6, 2016
75badae
add fastmatch dependency, bump version number
jeffeaton Oct 6, 2016
b39487c
fixed error in fitmod()
jeffeaton Oct 6, 2016
cf355d3
corrected default prior and likelihood functions to this package
jeffeaton Oct 6, 2016
3a206e1
added projection start year to state-space definition
jeffeaton Oct 7, 2016
1e33885
update ageprev() to accept age/sex/time arguments
jeffeaton Oct 10, 2016
0f08549
add plot functions to package, bump version number to 0.0.4
jeffeaton Oct 10, 2016
814e1c9
updated read_hivproj_X() to extract from PJNZ file, bump version numb…
jeffeaton Oct 31, 2016
a197aca
add methods for generics to calculate outputs from species
jeffeaton Oct 31, 2016
04f5c34
implemented binomial likelihood for age-specific prevalence
jeffeaton Oct 31, 2016
5ad6fc1
fixed bug in deff approximation data preparation
jeffeaton Oct 31, 2016
25c4c3c
fixed bug in control flow statement for choosing age-prevalence likel…
jeffeaton Nov 4, 2016
bd5aa3d
bug fixes to reading Spectrum results
jeffeaton Nov 27, 2016
4c8e9a6
added default parameters for subfertility by stage
jeffeaton Nov 27, 2016
7fdfea8
added piecewise linear incidence rate ratio
jeffeaton Nov 27, 2016
c7fb5ad
corrected to use control-flow version of logical operator (&&)
jeffeaton Nov 27, 2016
b467618
implement shifted lognormal age-IRR
jeffeaton Dec 12, 2016
5a4b186
add an optional third model fit to plot_agefit()
jeffeaton Dec 12, 2016
99fae62
add prepare_national_fit() to package
jeffeaton Dec 12, 2016
c53d097
Merge branch 'linear-incrr' into dev
jeffeaton Dec 14, 2016
bab029b
add some mortality calculation functions
jeffeaton Jan 19, 2017
01fa686
Merge branch 'master' into dev
jeffeaton Jan 19, 2017
c2351ae
Merge branch 'incid' into dev
jeffeaton Jan 19, 2017
4c31af1
Merge branch 'master' into dev
jeffeaton Feb 9, 2017
4cf6911
Merge branch 'dev' into allcausemx
jeffeaton Feb 9, 2017
a4772b5
Merge branch 'master' into dev
jeffeaton Feb 9, 2017
684e217
Merge branch 'master' into allcausemx
jeffeaton Feb 9, 2017
6a2be13
add specres option to age fit summary plot
jeffeaton Feb 21, 2017
26de2c4
Merge branch 'master' into dev
jeffeaton Mar 25, 2017
8eba517
update likelihood to implement ANC-RT data
jeffeaton Mar 30, 2017
b5f140e
add plot_ancprev() function and other plot function updates
jeffeaton Mar 31, 2017
14008b0
update read_hivproj_output() for new DP files
jeffeaton Apr 7, 2017
a873d83
update posterior epidemic plots ylim to end of epidemic
jeffeaton Apr 23, 2017
1d57f8d
update DP file parser to handle <BigPop MV2>, option to read .ep5 file
jeffeaton Apr 23, 2017
2f97bfb
update read_hivproj_output() to handle <BigPop3> from <Spectrum5> files
jeffeaton Apr 25, 2017
9936294
fix typo in previous commit update of read_hivproj_output()
jeffeaton Apr 26, 2017
6ada675
allow penalty order and numKnots to vary in spline model
jeffeaton Apr 27, 2017
641abff
Merge branch 'ord1-spline' into dev
jeffeaton Apr 27, 2017
30eda0d
fix bug in ANC likelihood calc -- ll_anc() not used
jeffeaton Apr 29, 2017
6564b5d
more constrained prior for ANC-RT bias parameters
jeffeaton Apr 29, 2017
9344d0e
added O-spline model
jeffeaton Apr 29, 2017
d96a09c
add option to estimate ratio of r(t0) and initial pulse (logiota)
jeffeaton May 1, 2017
93a5217
Merge branch 'ospline' into dev
jeffeaton May 1, 2017
fa67f03
add option to plot ANC data on plot_prev()
jeffeaton May 2, 2017
d90558e
add ageprev.specres()
jeffeaton May 2, 2017
c349716
Merge branch 'change-eqprior' into dev
jeffeaton May 2, 2017
b7df803
bug fix: remove non-used ANC sites
jeffeaton May 7, 2017
1f35173
Merge branch 'est-frr' into dev
jeffeaton May 7, 2017
7d9da8e
implement natmx model -- work in progress
jeffeaton May 7, 2017
34e1dc4
Merge branch 'dev' into allcausemx
jeffeaton May 7, 2017
819c680
add option to likelihood() and prior() to return log value
jeffeaton May 8, 2017
392c9c6
remove likedat from prepare_national_fit(), change agemx.specres() de…
jeffeaton May 8, 2017
52b2bcf
implement log-linear non-HIV mortality decline
jeffeaton May 11, 2017
5590a27
add mortality analysis to simfit(), add a few other convenience funct…
jeffeaton May 12, 2017
0c099a7
estimate HIV FRR adjustment parameter from ANC-RT census data
jeffeaton May 12, 2017
bdf0065
merge commit 5590a27
jeffeaton May 12, 2017
2ee3c9b
added functions for analysis of aggregated regional fits
jeffeaton May 12, 2017
6fb9905
add option to likelihood() and prior() to return log value
jeffeaton May 8, 2017
98d8240
catch error if NA values in age-specific prevalence
jeffeaton May 13, 2017
988880c
implement household survey incidence likelihood
jeffeaton May 13, 2017
e28aea4
update transp() to simply be wrapper for adjustcolor()
jeffeaton May 15, 2017
77ca4c0
specify knot locations for o-spline model
jeffeaton May 15, 2017
fd8e1d8
fix error in ANC sample size in create_aggr_input()
jeffeaton May 15, 2017
d32425a
Merge branch 'dev' into est-frr
jeffeaton Aug 16, 2017
9dbdc59
Merge branch 'master' into dev
jeffeaton Aug 27, 2017
fd7fba0
bug fix if popsize = 0 in popadjust, check for NA in likelihood preva…
jeffeaton Aug 30, 2017
6b952fc
add check that prevalence not >=1 in ll_hhsage_binom
jeffeaton Aug 31, 2017
312dc74
bug fixes in ll_hhage_binom() and create_spectrum_fixpar()
jeffeaton Sep 9, 2017
78ba5cc
add IMIS to package
jeffeaton Sep 10, 2017
d90dc1d
Change EPP package from 'Depends' to 'Imports'
jeffeaton Sep 10, 2017
8e8ec4a
rename `eppasm`
jeffeaton Sep 10, 2017
b345386
Merge branch 'add-imis' into dev
jeffeaton Sep 10, 2017
d4150b1
update package Imports
jeffeaton Sep 10, 2017
bb929cd
add read_csavr_output()
jeffeaton Sep 18, 2017
995fa93
update for tag <BigPop MV3> (Spectrum 5.62 Beta 15)
jeffeaton Sep 21, 2017
275f35c
add function to aggregate regional fits (incomplete)
jeffeaton Sep 21, 2017
ce990bb
Merge branch 'dev' into incidence-adjustment
jeffeaton Sep 21, 2017
f643ed8
add read_dp() function
jeffeaton Sep 23, 2017
2748d2e
Merge branch 'incidence-adjustment' into dev
jeffeaton Sep 23, 2017
dfefebb
reversion 0.2.0 to 0.3.0
jeffeaton Sep 23, 2017
7dec213
add ANC-RT data to aggregated national fits
jeffeaton Sep 24, 2017
c52fe0e
handle input aggregation if ancrtcens is NULL
jeffeaton Sep 24, 2017
d5b22d2
fix age/sex indices in HH survey likelihood
jeffeaton Sep 26, 2017
4b5ab74
bump patch version number
jeffeaton Sep 26, 2017
61b7ac6
implement dsamp() to calculate IMIS initial sampling density
jeffeaton Sep 26, 2017
66bf81b
Merge branch 'est-frr' into dev
jeffeaton Sep 26, 2017
80b990f
integrate out spline penalty variance parameter
jeffeaton Sep 28, 2017
f660d12
add plot_log_rvec()
jeffeaton Sep 30, 2017
eeb17f7
Merge branch 'r-hybrid' into dev
jeffeaton Sep 30, 2017
57a64f1
bug fix: NaN with median CD4 calculation if no eligible persons
jeffeaton Oct 1, 2017
139afb7
add r-hybrid and log RW models
jeffeaton Oct 1, 2017
f91e74b
implement logistic model for r(t)
jeffeaton Oct 3, 2017
2fdaa30
plot log r(t) instead of r(t)
jeffeaton Oct 5, 2017
4d2f351
add functions to read country and region from PJN file
jeffeaton Oct 5, 2017
f4cf759
update to parse <HIVTFR MV3> tag (Spectrum v5.62beta22)
jeffeaton Oct 5, 2017
1d46de0
add dimnames on read_hivproj_param()
jeffeaton Oct 6, 2017
4ef0c5e
Implement logistic model with random walk (rlogistic_rw)
jeffeaton Oct 6, 2017
16f68ec
define SIM_YEARS to truncate projection
jeffeaton Oct 6, 2017
11e5f10
add optimization option to fitmod()
jeffeaton Oct 6, 2017
44844d2
Add optimization option to fitmod()
jeffeaton Oct 6, 2017
3275dc3
fit model without and site-level ANC data
jeffeaton Oct 6, 2017
5010805
Merge branch 'no-anc' into dev
jeffeaton Oct 6, 2017
0737921
Merge branch 'dev' into r-hybrid
jeffeaton Oct 7, 2017
5ed566f
modularize code for calculating new infections
jeffeaton Oct 7, 2017
662f545
implement sex-specific transmission rate
jeffeaton Oct 8, 2017
482faf1
implement effect of CD4 stage on contact rate
jeffeaton Oct 8, 2017
0323701
implement model fitting for simpletransm model
jeffeaton Oct 8, 2017
50b3c03
bug fix to create_spectrum_fixpar()
jeffeaton Oct 9, 2017
72c8a00
Merge branch 'r-hybrid' into transmission
jeffeaton Oct 9, 2017
0a4b703
bug fix in extend_projection() if no prior_args specified
jeffeaton Oct 10, 2017
a5a945c
Implement age 15 entrant prevalence and ART coverage inputs.
jeffeaton Oct 10, 2017
66f35dd
update r-hybrid model to use classic r-spline (not log o-spline)
jeffeaton Oct 13, 2017
f3e5b79
update plot functions to plot age-standardized prevalence
jeffeaton Oct 13, 2017
269c633
add age-specific incidence function
jeffeaton Oct 13, 2017
589000d
logit transformation of logiota parameter uniform prior.
jeffeaton Oct 13, 2017
de78f52
preliminary implementation of age-specific exposure model
jeffeaton Oct 13, 2017
65e3c94
bug fix to create_spectrum_fixpar()
jeffeaton Oct 9, 2017
6381b5b
Merge branch 'r-hybrid' into sexbehav
jeffeaton Oct 13, 2017
8d2b486
all M:F transmission rate to change over time
jeffeaton Oct 14, 2017
f6a9cb8
implement piecewise constant time-varying IRRs
jeffeaton Oct 14, 2017
5e57cdd
add cubic-spline interpolation of log age IRRs
jeffeaton Oct 14, 2017
0201f13
add functions to calculate age-specific number of new infections and …
jeffeaton Oct 29, 2017
64dd5d5
add new summary output functions and plot functions
jeffeaton Oct 29, 2017
5f15d50
bug fix: prior for piecewise-linear varying IRRs (commit f6a9cb8)
jeffeaton Oct 29, 2017
c5bd7ab
Updated default IRR priors to informative priors based on fits to cou…
jeffeaton Oct 29, 2017
1126188
Merge branch 'sexbehav' into r-hybrid
jeffeaton Oct 29, 2017
2daff80
Merge branch 'r-hybrid' into dev
jeffeaton Oct 29, 2017
629eeda
bug fix: indexing for age 15 plus population
jeffeaton Oct 30, 2017
3afabcb
implement annual incidence input option
jeffeaton Oct 30, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Package: eppspectrum
Package: eppasm
Title: Age-structured EPP Model for HIV Epidemic Estimates
Version: 0.1.1
Version: 0.4.0
Authors@R: person("Jeff", "Eaton", email = "[email protected]", role = c("aut", "cre"))
Description: What the package does (one paragraph).
Depends: R (>= 3.1.0), epp (>= 0.3),
Imports: fastmatch (>= 1.1), abind (>= 1.4)
Depends: R (>= 3.1.0),
Imports: epp (>= 0.3.3), fastmatch (>= 1.1), abind (>= 1.4), mgcv (>= 1.8), mvtnorm
LinkingTo: BH
License: GPL-3
Encoding: UTF-8
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Generated by roxygen2: fake comment so roxygen2 overwrites silently.
exportPattern("^[^\\.]")
useDynLib(eppspectrum, checkBoostAsserts, spectrumC)
useDynLib(eppasm, checkBoostAsserts, spectrumC)
65 changes: 64 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,70 @@

- Update to interface with `epp v0.3` which implements ANC routine testing (ANC-RT) likelihood in EPP 2017.


# eppspectrum 0.1.1

- Add option to use .ep5 file inputs instead of .DP file when preparing fit from PJNZ file. (use_ep5=FALSE by default.)
- update prepare_spec_fit() to not use popadjust if EPP projection has a single population.
- update prepare_spec_fit() to not use popadjust if EPP projection has a single population.

# eppspectrum 0.1.3

- EPP model setup occurs in fitmod()
- Allow order of spline model penalty to vary (fp$rtpenord)
- Allow number of knots to vary (fp$numKnots)
- Return spline coefficients in fnCreateParam()

# eppspectrum 0.1.5

- Implemented O-spline model (penalized B-spline) using mgcv to construct
- Added `r0logiotaratio` option to estimate ratio of r(t0) and log of initial seed, reduces correation. Not set as default.

# eppspectrum 0.1.6

- Bug fix: add check in ll_hhage_binom() that ldbinom() does not return NaN.
- Bug fix: in create_spectrum_fixpar(), handle case where ART initiation starts in different years for men and women.


# eppasm 0.3.0

- Rename package `eppasm`.
- Add IMIS function to eppasm package. In this version of IMIS, at each iteration a new mixture component is constructed either centered on input with greatest weight or based on optimizer. Allows optimizers to be run at arbitrary iterations, but doesn't implment multiple optimizers which might still be usful. Covariance for optimizer mixture component when Hessian is degenerate still needs further work.

- Change from dependency to imports epp package.
- Add ANC-RT data to aggregate national fits (prepare_national_fit() and create_aggr_input()).

- Implement dsamp() to calculate density for initial IMIS samples. This allows different initial sampling density from prior distribution.

- Specify knot locations for o-spline model
- Estimate HIV+:HIV- FRR adjustment.
- Specify knot locations for o-spline model

- Add functions to read country and subnational region from Spectrum PJN file.

# eppasm 0.3.2

- Integrate random effects variance parameter out of likelihood.
- Implement hybrid r-spline and RW model for r(t).
- Implement logistic model for log r(t) (rlogistic), and version with random walk (rlogistic_rw).
- Add optimization option to fitmod().

- Add option to fit without site-level ANC data.

# eppasm 0.3.3

- Modularize code for calculating new infections.

- Implement age 15 entrant prevalence and ART coverage inputs.
- Implement logit transformation for sampling from uniform logiota prior distribution.
- Set age IRR penalty variance at a fixed constant value (9003)

- Implement piecewise-linear time-varying M:F incidence/transmission ratio
and 15-24 incidence rate ratio. Knots fixed at 2002, 2007, and 2012.
- Modularize code for incidence rate ratio parameterization, now in infections.R.

- Updated default IRR priors to informative priors based on fits countries with several surveys.
- Add function to generate summary model outputs


# eppasm 0.4.0
- Add annual direct incidence input option.
59 changes: 59 additions & 0 deletions R/aggregate-fits.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
create_aggr_input <- function(inputlist){

val <- inputlist[[1]]

eppdlist <- lapply(inputlist, attr, "eppd")

## Only keep intersecting years
anc.prev.list <- lapply(eppdlist, "[[", "anc.prev")
anc.prev.list <- lapply(anc.prev.list, function(x) x[,Reduce(intersect, lapply(anc.prev.list, colnames))])

anc.n.list <- lapply(eppdlist, "[[", "anc.n")
anc.n.list <- lapply(anc.n.list, function(x) x[,Reduce(intersect, lapply(anc.n.list, colnames))])

ancrtsite.prev.list <- lapply(eppdlist, "[[", "ancrtsite.prev")
ancrtsite.prev.list <- lapply(ancrtsite.prev.list, function(x) x[,Reduce(intersect, lapply(ancrtsite.prev.list, colnames))])

ancrtsite.n.list <- lapply(eppdlist, "[[", "ancrtsite.n")
ancrtsite.n.list <- lapply(ancrtsite.n.list, function(x) x[,Reduce(intersect, lapply(ancrtsite.n.list, colnames))])


## aggregate census data across regions
ancrtcens <- do.call(rbind, lapply(eppdlist, "[[", "ancrtcens"))
if(!is.null(ancrtcens) && nrow(ancrtcens)){
ancrtcens$x <- ancrtcens$prev * ancrtcens$n
ancrtcens <- aggregate(cbind(x,n) ~ year, ancrtcens, sum)
ancrtcens$prev <- ancrtcens$x / ancrtcens$n
ancrtcens <- ancrtcens[c("year", "prev", "n")]
}

attr(val, "eppd") <- list(anc.used = do.call(c, lapply(eppdlist, "[[", "anc.used")),
anc.prev = do.call(rbind, anc.prev.list),
anc.n = do.call(rbind, anc.n.list),
ancrtsite.prev = do.call(rbind, ancrtsite.prev.list),
ancrtsite.n = do.call(rbind, ancrtsite.n.list),
ancrtcens = ancrtcens)

artnumperc <- !attr(inputlist[[1]], "specfp")$art15plus_isperc
artnumlist <- lapply(lapply(inputlist, attr, "specfp"), "[[", "art15plus_num")

art15plus_num <- artnumlist[[1]]
art15plus_num[artnumperc] <- Reduce("+", lapply(artnumlist, "[", artnumperc))

attr(val, "specfp")$art15plus_num <- art15plus_num

return(val)
}


fnAddHHSLikDat <- function(obj){
objcountry <- attr(obj, "country")
fp <- attr(obj, "specfp")
anchor.year <- as.integer(floor(min(fp$proj.steps)))

attr(obj, "eppd")$hhs <- subset(prev.15to49.nat, country==objcountry)
attr(obj, "eppd")$hhsage <- subset(prev.agesex.nat, country==objcountry)
## attr(obj, "eppd")$sibmx <- subset(sib.mx.tips, country==objcountry)

return(obj)
}
5 changes: 5 additions & 0 deletions R/cluster-functions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

pick_maxlpd <- function(set){set <- set[!sapply(set, is.null)]; set[[which.max(sapply(set, function(x) tail(x$stat,1)[1]))]]}
get_imisiter <- function(x) nrow(x$stat)
get_logmargpost <- function(x) tail(x$stat, 1)[1]
get_nunique <- function(x) tail(x$stat, 1)[2]
48 changes: 48 additions & 0 deletions R/directincid.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
calc_entrantprev <- function(specres){
ageprev1 <- function(specres, str){colSums(specres$hivpop[str,,,drop=FALSE],,2) / colSums(specres$totpop[str,,,drop=FALSE],,2)}
prev14 <- ageprev1(specres, "14")
prev13 <- ageprev1(specres, "13")
Sx <- c(0, prev14[-1] / prev13[-length(prev13)]) # assume that survival from age 14 to 15 is the same as 13 to 14
Sx <- ifelse(is.na(Sx), 0, Sx)
return(Sx*prev14)
}

calc_entrantartcov <- function(specres){
## Assume uniform ART coverage among age 10-14
artcov <- with(specres, ((artnum.f+artnum.m)/(hivnum.f+hivnum.m))["10-15",])
artcov <- ifelse(is.nan(artcov), 0, artcov)
artcov
}

create_specfp <- function(pjnz, upd.path=NULL, hiv_steps_per_year = 10L, use_ep5=FALSE){

## demographic inputs
if(!is.null(upd.path))
demp <- read_demog_param(upd.path) # from UPD file
else
demp <- read_specdp_demog_param(pjnz, use_ep5=use_ep5) # from DP file or ep5 file

## HIV projection parameters (most AIM adult parameters)
projp <- read_hivproj_param(pjnz, use_ep5=use_ep5)

## HIV projection results
specres <- read_hivproj_output(pjnz)

specfp <- create_spectrum_fixpar(projp, demp, hiv_steps_per_year= hiv_steps_per_year)
specfp$entrantprev <- calc_entrantprev(specres)
specfp$entrantartcov <- calc_entrantartcov(specres)

attr(specfp, "country") <- read_country(pjnz)
attr(specfp, "country") <- read_country(pjnz)
attr(specfp, "region") <- read_region(pjnz)

return(specfp)
}

prepare_directincid <- function(pjnz){
specfp <- create_specfp(pjnz)
specfp$eppmod <- "directincid"
specfp$incidinput <- read_incid_input(pjnz)
specfp$incidpopage <- attr(specfp$incidinput, "incidpopage")
return(specfp)
}
Loading