Skip to content

Add functions to extract prep coverage and prep method mix#1

Open
rtesra wants to merge 1 commit into
masterfrom
extract-and-set-prep-coverage
Open

Add functions to extract prep coverage and prep method mix#1
rtesra wants to merge 1 commit into
masterfrom
extract-and-set-prep-coverage

Conversation

@rtesra

@rtesra rtesra commented Sep 11, 2025

Copy link
Copy Markdown
Collaborator

Added two new function to extract PrEP coverage and PrEP method mix from the Resource Needs module:

  • rn.prep.coverage() - extracts PrEP coverage
  • rn.prep.method.mix() - extracts PrEP method mix
  • Changes made to strata.labels - added RN risk group and PrEP methods with corresponding numerical encoding

@rtesra rtesra requested a review from rlglaubius September 11, 2025 17:25
@rtesra rtesra changed the title Adding function to extract prep coverage and prep method mix Add functions to extract prep coverage and prep method mix Sep 11, 2025
Comment thread R/extract-const.R
"MSM: med risk" = 8,
"MSM: high risk" = 9,
"MSM: PWID" = 10),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the assigned constants, I didn't know R supported that. risk.groups is duplicative of hv.pop.ext. I would prefer to just define one or the other, and would prefer using hv.pop.ext to avoid changing other functions.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll add in the encoding on hiv.pop.ext. Assuming All = 0 and Not at risk = 1 ?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, using All=0 and Not at risk=1 should be good.

Comment thread R/extract-rn.R
#' @param final.year Final year of the projection.
#' @return A data frame.
#' @export
rn.prep.coverage= function(rn.raw, direction="wide", first.year, final.year) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename to rn.inputs.prep.coverage for consistency with other methods.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread R/extract-rn.R
Comment thread R/extract-rn.R
Comment thread R/extract-rn.R
dat <- dat |> dplyr::select(sex, risk_group, dplyr::everything())

if (direction=="long") {
dat = reshape2::melt(raw, id.vars=c("sex", "risk_group", "prep_method"),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for now, but if we do move to tidyr we can replace all these melt calls with tidyr::pivot_longer and get rid of the reshape2 dependency.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can replace tidyr throughout?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep reshape2 here. My comment about tidyr was based on a misunderstanding. I thought the |> operator was defined in tidyr. Since that operator has been in base I don't think we need to add a dependency on tidyr or go through the testing process that replacing reshape2::melt would entail.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants