Build a function in R to calculate the mean and respectively, the variance where the distribution type of the v.a. is transmitted either by a name, or by the mass function in the discrete case, or by the probability density function in the continuous case.
so I have the idea,but I don't know how to implement it in R, especially when you have to introduce the name.
Can you show me the start idea?
Related
Is there any documentation, inside R, on the parameters and CDF/PDF of the most common distributions? I tried ?rexp but it doesn't provide the formula for the variance of X, only its mean.
I am really new to this and I have no idea how to use the ecdf function in R. Below I have mention everything step by step:
Frequency of losses is defined using a Poisson distribution
Generate an ecdf function that is going to be used for the severity of losses.
Linearly interpolate the ecdf function.
Take inverse transform of the linearly interpolated ecdf function.
For example,
I can use code freq <- rpois(10,5) to generate the random number of loss frequency but further I have to use this vector to do steps 2-4 and I have no idea how to do that. For step 2 I am facing the problem that how can I use that Poisson distribution as an input and then use to compute severity using the ecdf function. If anybody knows this please help me.
I wonder what would be the best and most correct way to estimate an Entropy from a probability density function in R? I have some real-values that are not probabilities, and I would like to get some measure of "uneaveness" of those values. Thus, I was thinking about entropy. Would something like this work:
entropy(density(dat$X), unit='log2'),
assuming that I am using entropy function from the entropy package.
Are there some other ways of estimating uncertainty from real-valued vector?
Many thanks! PM
I have a vector of data. I need build the density / distribution function and from that, extract a random sample, i.e. I need obtain the result that give us a function similar to rnorm(), rpois(), rbinom(), etc, but with a distribution built from a vector of data. All in R. Thank you so much.
It has nothing to do with generate stochastic random deviates.
I know the function sample() do something similar, but not exactly. If I use sample() I obtain only elements from my original data, as a discrete distribution and I need as a continuous distribution.
I'm, trying to apply this solution to find the p-value in an arbitrary distribution defined from data experiments. I have estimated this distribution using the density function in R. Now, I would like to integrate this function to apply the solution proposed by #mpiktas. However, the integrate function requires a function as input, not two vectors x and y with the values that define the function, which is what density provides.
Any idea on how to deal with this numerical integration based on x-y values in R?