-
Notifications
You must be signed in to change notification settings - Fork 15
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
feature request: Function to get distributional from family #131
Comments
Are you trying to obtain the function corresponding to a given family, or characterise a complete distribution? How do you use the |
Thanks for the quick response. I was messing around with doing some likelihood calculation "manually" while doing some MCMC sampling in connection with some bayesian GLM. In that task I have a function with usual However, for this use case I still need to reparametrise each density to accomodate the evaluation of it for my likelihood, meaning I think it will actually be easier to just revert to simple So to answer your question: Yes, I am trying to characterise the distribution, but from a bit more pondering I don't think I would end up using the implementation for my current purpose. That said, an as_distributional S3 generic could probably come in handy in some scenarios, so it's up to you if you want to close this issue or leave it for some time in the future :) |
Perhaps some conversion from I'm not quite sure how reparameterising each density conflicts with an |
Hmm I guess an log_likelihood <- function(formula, data, family, extra_args = list(prior_sigma) {
# Doing stuff to prepare data and calculate my `mu`
dist <- as_distributional(family, mu, extra_args)
return(sum(density(dist, Y, log = T)))
} And for this to work, the binomial density needs to take as first argument the density_parametrised_by_mu_glm <- function(family) {
switch(family$family,
gaussian = function(main_parameter, ...)
as_distributional(family, mean = main_parameter, ...),
binomial = function(main_parameter, ...)
as_distributional(family, prob = main_parameter, size = 1, ...)
)
} So that's my "issue" with having to "reparametrise the densities" even if there was an |
You might like to use As for handling library(distributional)
pred_dist <- function(family, eta) {
# Compute the predicted mean using the inverse link function
mu <- family$linkinv(eta)
# Switch for density calculation based on family
switch(family$family,
"gaussian" = dist_normal(mean = mu, sd = ???),
"binomial" = dist_binomial(size = 1, prob = mu),
"poisson" = dist_poisson(lambda = mu),
"inverse.gaussian" = dist_inverse_gaussian(mu, ???)
stop(paste("Density calculation not implemented for family:", family$family))
)
} I leave it to you to handle the variances / dispersion / etc. |
Ah okay, I didn't notice the existence of the Thanks for engaging with my problem! I'll leave it up to you whether to close the issue or keep it open in case it could be interesting to look into an implementation of |
Hi!
I found your package and have been enjoying it!
In my use case, I would like to be able to get a distributional object corresponding to a specified family. I have written a small piece of code (see below) within my package to enable this, but I wondered if it wouldn't be of interest to have implemented in the package.
What do you think?
The text was updated successfully, but these errors were encountered: