How to define a customized probability distribution in a "R-standard way"? I know my cumulative distribution function(cdf) and random sampling function(rsf), say pnewdist and rnewdist. It is needed to define a probability distribution in R like it is done in the standard R case, viz, normal distribution where rnorm or pnorm are the rsf and cdf respectively. So, how to define my distribution newdist and link its cdf and rsf with pnewdist and rnewdist?
Ideally for using the rnewdist or pnewdist I dont need to do so but I want to use the R package HiddenMarkov with customized/user defined probability distribution for the observables instead of the available distributions in R(like normal or poisson etc.) so that in the command dthmm, I can use distn=newdist. Thanks.
ecdf uses a user-defined distribution to give you a function based on that distribution.
Related
I'm wondering if there is an R package which can help me to get the correct parameters for a distribution of my choice and for intervals of my choice.
For Instance, here Betancourt is looking at inverse gamma and he wants to learn which set of parameters will give >1% below 2 and >1% above 20 (like the graph below). Stan's solver returns the parameters for inv-gamma which results the intervals of interest. Is there any solution applied directly on R?
Or in other words,
I have the distribution
I have the intervals
Can I learn the correct parameters?
Thanks
I want to find out if a given distribution follows a power law. My question is, can we use a qq plot to do this?
I first estimate the xmin by integrating over the entire dataset. Following which, I found alpha using MLE. (xmin and alpha are explained at the following link :- https://en.wikipedia.org/wiki/Power_law
under the section Power-law probability distributions)
Next I plan to use a qqplot of the empirical distribution and theoretical distribution(with the computed alpha and xmin).
Am I on the right track ?
Also, what reference line( corresponding to qqline) should be used in the case of power law?
Also we can use a log log plot to find out if a distribution is following a power law. My query is, will the qqplot analysis augment the log log plot analysis ? Is it valid to do a qqplot analysis for a power law distribution?
I am trying to calibrate parameters in a probabilistic cost-effective model I built. The model is a discrete state-transition (Markov) model. Before building models in R, I used the software TreeAge Pro. There one could set the model to run using the distribution means for each parameter, instead of drawing random values from the distributions. This made it easy see how varying single input parameters affected certain outcome variables.
My model uses many different distribution draws with Beta, Gamma and Normal distributions (rbeta, rgamma, rnorm). I would like to be able to set them to take their mean value using one command and setting them back to draw values with another. Does something like this exist?
E.g. the Beta distribution rbeta(1, 45, 55) would then take the value 0.45, when it is called, as long as it is set to take the mean.
I tried temporarily replacing the rbeta(1,, rgamma(1, etc. and parts of the distributions with qbeta(0.5 and qgamma(0.5 but this does not give me the means. For qbeta(0.5, 45,55) it gave me 0.4496653 instead of 0.45; for qbeta(0.5, 1,99) it gave me 0.006977 instead of 0.01.
The question is if there is a function in R that tells all distributions that draw random values to return the mean instead of random values, thereby avoiding having to replace every single distribution manually with its mean value.
I appreciate any hint on how to set the distributions to take their mean values. Does anyone know of any package that would be able to help?
I am interested in frequency distributions that are not normally distributed.
If I have a frequency distributions table which is not normally distributed.
Is there a function or package that will identify the type of distribution for me?
You can use the fitdistr function (library MASS i think) and check for yourself if you find a 'fitting' distribution. However i suggest that you plot the function first and see how it looks like. This approach is generally not recommended as you always can use different parameters to fit a distribution and thus confuse one distribution with another. If you have found a suited distribution you should test it against data.
Edit: For instance a normal distribution may look like a poisson distribution. Fitting is in my oppinion only useful if you have enough random variables. Otherwise just draw variables from your data if you need to
You can always try to test whether a distribution is adequate for your data with QQ plot. If you have data that is dynamic, I would suggest that you use ECDF (Empirical Cumulative Distribution Function) which will give you more precise distributions as your data grows. You can use ECDF in R with the ecdf() function.
Mathematica has a four-parameter generalized inverse gamma distribution:
http://reference.wolfram.com/mathematica/ref/InverseGammaDistribution.html
and gives its PDF on that page too. Has anyone implemented the density, distribution, quantile, and sampling-from functions for that in R?
I did make a quick start (the PDF is just the equations on that page translated into R) but if its done already I'll not bother with implementing the CDF and the quantile function.
Does a general function for computing the CDF (by integration of PDF) and the Quantile (by inversion of the CDF) of any distribution given the PDF exist?
[Note this is not the generalized inverse Gaussian]
Note also the 'Properties and Relations' dropdown on the Mathematica page, which seems to imply its not a special case or generalisation of anything (apart from the inverse gamma).
I started a package to implement this:
https://github.com/barryrowlingson/geninvgamma
Its only using simple inversion and integration of the density, so nothing clever. Currently random samples from the distribution are done by generating a U(0,1) and getting the quantile, which isn't very efficient or very accurate it seems..
Anyway, its a start.
According to this vignette (Appendix C2), the inverse gamma distribution is a special case of the generalized hyperbolic distribution which is implemented by the ghyp package.