Masked density output for normal mixture #145
Open
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.
Bug Report
When I try to use the
get_densityfunction in the package to plot the density of a mixture of half-normal distributions, I get a (perfectly) symmetric distribution even though the input data is not symmetric around zero. Theget_densityfunction also cannot handle more than one input value when using the half-normal prior.Replication Steps
First, I simulate some data that is clearly skewed.
Next, I fit ASH using the half-normal prior.
I expect the following command to work, but it throws an error.
The function works for individual values, but the density is the same at -3 and 3 (very unlikely based on the data).
If I evaluate
get_densityone-value-at-a-time usingsapply, I get a symmetric distribution.Proposed Fix
I believe the issue lies in the
comp_dens.tnormalmixfunction inR/tnormalmix.Rfile. Previously, this function returned a matrix of density values for each component (the matrix is component by target values). However, the output is not masked by the support of the mixture components. I add this masking in the fix.Concerns
I'm not sure if this is the right place to implement the masking.
Replicating the Fix
First, generate the skewed data and fit the model.
Now,
get_densityworks properly with vector-valued targets.Furthermore, the density looks non-symmetric around zero.