R Under development (unstable) (2025-01-06 r87534 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 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 2.8635913 0.45492283 rate 0.4549228 0.08064197 > 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) + } > > if(FALSE) + { + mmedist(rgamma(1e2, truetheta["alpha"], truetheta["beta"]), "gamma", order=1:2, calcvcov = TRUE)$vcov + mmedist(rgamma(1e3, truetheta["alpha"], truetheta["beta"]), "gamma", order=1:2, calcvcov = TRUE)$vcov + mmedist(rgamma(1e4, truetheta["alpha"], truetheta["beta"]), "gamma", order=1:2, calcvcov = TRUE)$vcov + } > > > # (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 1.40 0.29 1.68