R Under development (unstable) (2024-07-10 r86888 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > require(fitdistrplus) Loading required package: fitdistrplus Loading required package: MASS Loading required package: survival > nsample <- 1e6 > nsample <- 10 > > #### (1) Gamma example #### > > truetheta <- c("alpha"=3, "beta"=1/2) > x <- rgamma(nsample, truetheta["alpha"], truetheta["beta"]) > f1 <- mmedist(x, "gamma", order=1:2, calcvcov = TRUE) > f1$vcov shape rate shape 115.15595 20.842139 rate 20.84214 4.004956 > if(FALSE) + { + memp <- function(x, order) mean(x^order) + require(actuar) + fitdistrplus:::mme.vcov(as.numeric(truetheta), fix.arg=NULL, order=1:2, obs=x, mdistnam=mgamma, memp, weights=NULL) + } > > > # (2) fit a Pareto distribution > # > > if(any(installed.packages()[, "Package"] == "actuar")) + { + require(actuar) + #simulate a sample + x4 <- rpareto(nsample, 6, 2) + + #empirical raw moment + memp <- function(x, order) + mean(x^order) + + #fit + res <- mmedist(x4, "pareto", order=c(1, 2), memp=memp, start=c(shape=10, scale=10), + lower=1, upper=Inf, calcvcov = TRUE) + } Loading required package: actuar Attaching package: 'actuar' The following objects are masked from 'package:stats': sd, var The following object is masked from 'package:grDevices': cm > > proc.time() user system elapsed 2.28 0.50 2.76