# (1) basic fit of a normal distribution with moment matching estimation
#
set.seed(1234)
x1 <- rnorm(n=100)
mmedist(x1,"norm")
# (2) fit a discrete distribution (Poisson)
#
set.seed(1234)
x2 <- rpois(n=30,lambda = 2)
mmedist(x2,"pois")
# (3) fit a finite-support distribution (beta)
#
set.seed(1234)
x3 <- rbeta(n=100,shape1=5, shape2=10)
mmedist(x3,"beta")
# (4) fit a Pareto distribution
#
require(actuar)
#simulate a sample
x4 <- rpareto(1000, 6, 2)
#empirical raw moment
memp <- function(x, order)
ifelse(order == 1, mean(x), sum(x^order)/length(x))
#fit
mmedist(x4, "pareto", order=c(1, 2), memp="memp",
start=c(shape=10, scale=10), lower=1, upper=Inf)Run the code above in your browser using DataLab