mixturedist.Rdpdf, cdf, inverse cdf, and random deviates of a user defined mixture distribution with equal weights.
.checkFunctions(functionList) qMixtureDistribution(p, functionList, xMin, xMax, nPoints = 1000, logScale = FALSE) rMixtureDistribution(n, functionList) pMixtureDistribution(x, functionList) dMixtureDistribution(x, functionList)
| functionList | A list of functions forming the mixture distribution. The functions must be a continuous CDF dependent on 'x'. |
|---|---|
| p | A vector of probabilities. |
| xMin | The minimum value for which probabilities and quantiles are calculated. |
| xMax | The maximum value for which probabilities and quantiles are calculated. |
| nPoints | The number of points at which the mixed CDF is calculated. Default=1000. |
| logScale | Are the CDF estimates to be performed on a logarithmic scale? Default=FALSE |
| n | The number of random deviates to compute |
| x | The value at which the cdf or pdf are computed |
A vector of densities, probabilities, quantiles, or random deviates from the mixture distribution.
#> [1] 2#> [1] 0.5pMixtureDistribution(c(0.5,1,2,4,5,6), list("pnorm(x, 1, 0.1)","pnorm(x, 2, 0.1)", "pnorm(x, 3, 0.1)"))#> [1] 9.555052e-08 1.666667e-01 5.000000e-01 1.000000e+00 1.000000e+00 #> [6] 1.000000e+00x1 <- rMixtureDistribution(10000, list("pnorm(x, 1, 0.1)", "pnorm(x, 2, 0.1)", "pnorm(x, 3, 0.1)")) mean(x1)#> [1] 1.999914#> Warning: There are not enough requested samples to sample once from each function#> rnorm(n, 1, 0.1) #> 0.796579#> rnorm(n, 1, 0.1) rnorm(n, 2, 0.1) rnorm(n, 3, 0.1) #> 1.172192 2.138209 2.924062#> [1] 1.056129 1.088525 1.968245 2.038495integrate(dMixtureDistribution, 0, 4, functionList = list("pnorm(x, 1, 0.1)","pnorm(x, 2, 0.1)", "pnorm(x, 3, 0.1)"))#> 1 with absolute error < 8.2e-05integrate(dMixtureDistribution, 0, Inf, functionList = list("pnorm(x, 1, 0.1)","plnorm(x, .2, 0.1)", "pnorm(x, 3, 0.1)"))#> 1 with absolute error < 7e-05