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

Solution for natural scale outputs #169

Closed
athowes opened this issue Jul 15, 2024 · 3 comments · Fixed by #170
Closed

Solution for natural scale outputs #169

athowes opened this issue Jul 15, 2024 · 3 comments · Fixed by #170

Comments

@athowes
Copy link
Collaborator

athowes commented Jul 15, 2024

We have a function add_natural_scale_mean_sd. It takes the meanlog and sdlog of the lognormal and transforms to the natural scale.

function(dt) {
  nat_dt <- data.table::copy(dt)
  nat_dt <- nat_dt[, mean := exp(meanlog + sdlog ^ 2 / 2)]
  nat_dt <- nat_dt[, sd := mean * sqrt(exp(sdlog ^ 2) - 1)]
  return(nat_dt[])
}

It would be nice to:

  1. Have this function not be lognormal. Move from internal to external "natural scale" parameters automatically
  2. Move this functionality closer in to the model so that a user doesn't have to call it

I think that 2. is somewhat easy but 1. is difficult.

Some options and considerations:

  • Could make add_natural_scale a generic function with classes for family (see Add family class functionality #98 for previous issue on this)
  • Could move add_natural_scale function into epidist::epidist making the called family available
  • Need to think about names of inputs and outputs here
  • Want to transform all draws and keep it within the brms object. Like it's a transformed parameter. There should exist functionality to do this
  • Is there any automated way to get the tranformations from the family object in brms? Sam thinks answer is no but it'd be very nice if there were
@athowes
Copy link
Collaborator Author

athowes commented Jul 16, 2024

Right now I'm thinking:

  1. Put a family class onto the object at epidist_family stage
  2. Implement add_natural_scale for however many families we care to
  3. Put add_natural_scale into epidist
  4. Have the default output for add_natural_scale to be to do nothing so that non-supported families just have no change
  5. Could include message that "non-supported family, if you would like to transform to the natural scale consider the following steps (and submit a PR)"

@athowes
Copy link
Collaborator Author

athowes commented Jul 16, 2024

@athowes
Copy link
Collaborator Author

athowes commented Jul 16, 2024

I think as a part of this issue also need to be looking to replace extract_lognormal_draws with something more generic. Can use the family information stored in the brmsfit to have automatic link function transformation. Question about how early to move to use the posterior object transformation

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 a pull request may close this issue.

1 participant