R Under development (unstable) (2024-02-22 r85974 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(OneStep) Loading required package: OneStep Loading required package: fitdistrplus Loading required package: MASS Loading required package: survival Loading required package: numDeriv Loading required package: parallel Loading required package: extraDistr > require(actuar) Loading required package: actuar Attaching package: 'actuar' The following objects are masked from 'package:extraDistr': dgumbel, dinvgamma, dpareto, pgumbel, pinvgamma, ppareto, qgumbel, qinvgamma, qpareto, rgumbel, rinvgamma, rpareto The following objects are masked from 'package:stats': sd, var The following object is masked from 'package:grDevices': cm > > n <- 1e3 > > #### G1 <- c("norm", "exp", "lnorm", "invgauss", "pois", "geom") # Distributions for which the explicit MLE is returned #### > > x <- rexp(n) > os <- onestep(x, "exp") > summary(os) Parameters : estimate rate 0.9903148 Loglikelihood: -1009.732 AIC: 2021.465 BIC: 2026.373 > print(os) Parameters: estimate rate 0.9903148 > class(os) [1] "onestep" "fitdist" > plot(os) > > x <- rlnorm(n, 0, 1) > os <- onestep(x, "lnorm", method="closed") > summary(os) Parameters : estimate meanlog 0.03711185 sdlog 1.01841389 Loglikelihood: -1474.297 AIC: 2952.594 BIC: 2962.409 > plot(os) > > #### G2 <- c("unif", "logis") # Special distributions #### > > x <- runif(n) > os <- onestep(x, "unif") > summary(os) Parameters : estimate 1 0.00766132 2 1.01300181 Loglikelihood: -Inf AIC: Inf BIC: Inf > le <- fitdist(x, "unif") > summary(le) Fitting of the distribution ' unif ' by maximum likelihood Parameters : estimate Std. Error min 0.0003739302 NA max 0.9997526563 NA Loglikelihood: 0.621467 AIC: 2.757066 BIC: 12.57258 Correlation matrix: [1] NA > > > x <- rlogis(n) > os <- onestep(x, "logis") > summary(os) Parameters : estimate location -0.01493669 scale 0.99667357 Loglikelihood: -1998.785 AIC: 4001.57 BIC: 4011.386 > le <- fitdist(x, "logis") > summary(le) Fitting of the distribution ' logis ' by maximum likelihood Parameters : estimate Std. Error location -0.02803861 0.05467147 scale 0.99839733 0.02641282 Loglikelihood: -1998.754 AIC: 4001.508 BIC: 4011.324 Correlation matrix: location scale location 1.00000000 0.00251881 scale 0.00251881 1.00000000 > > > #### G3 <- c("gamma", "beta", "nbinom") # Distributions with a default MME initial guess estimator #### > > x <- rbeta(n, 3, 2) > os <- onestep(x, "beta") > summary(os) Parameters : estimate shape1 3.075415 shape2 2.131712 Loglikelihood: 242.6108 AIC: -481.2215 BIC: -471.406 > os <- onestep(x, "beta", init=list(shape1=1, shape2=1)) > > x <- rgamma(n, 3, 2) > os <- onestep(x, "gamma", init=list(shape=1, scale=1)) > summary(os) Parameters : estimate shape 1.486931 rate 1.001207 Loglikelihood: -1256.179 AIC: 2516.359 BIC: 2526.175 > os <- onestep(x, "gamma", init=list(shape=10, rate=1)) Warning message: In dgamma(c(0.518931507001945, 2.3666249700763, 3.48363317180729, : NaNs produced > summary(os) Parameters : estimate shape -217.97183 rate -20.94575 Loglikelihood: NaN AIC: NaN BIC: NaN > > x <- rnbinom(n, 3, 1/3) #mu=size*(1-prob)/prob=6 > os <- onestep(x, "nbinom") > summary(os) Parameters : estimate size 3.001653 mu 5.962000 Loglikelihood: -2725.924 AIC: 5455.849 BIC: 5465.664 > os <- onestep(x, "nbinom", init=list(size=10, mu=2)) > summary(os) Parameters : estimate size 13.055957 mu 3.257501 Loglikelihood: -3557.176 AIC: 7118.352 BIC: 7128.168 > os <- onestep(x, "nbinom", init=list(size=10, prob=1/2)) > summary(os) Parameters : estimate size 2.604170 mu 3.546077 Loglikelihood: -2987.539 AIC: 5979.077 BIC: 5988.893 > > > > > #### G4 <- c("cauchy", "weibull", "pareto") # Distributions with a special initial guess estimator #### > > x <- rweibull(n, 3, 2) > os <- onestep(x, "weibull") > summary(os) Parameters : estimate shape 3.029529 scale 2.045224 Loglikelihood: -996.3449 AIC: 1996.69 BIC: 2006.505 > os <- onestep(x, "weibull", init=list(shape=1, scale=1)) > summary(os) Parameters : estimate shape 1.392106 scale 152.855260 Loglikelihood: -6467.9 AIC: 12939.8 BIC: 12949.62 > > > x <- rcauchy(n, 1, 2) > os <- onestep(x, "cauchy", control=list(param_t=1/4)) > summary(os) Parameters : estimate location 0.827723 scale 1.994658 Loglikelihood: -3294.543 AIC: 6593.085 BIC: 6602.901 > os <- onestep(x, "cauchy", init=list(location=0, scale=1)) > summary(os) Parameters : estimate location 0.3676292 scale 1.7596202 Loglikelihood: -3313.997 AIC: 6631.993 BIC: 6641.809 > > > x <- rpareto(n, 1, 2) > os <- onestep(x, "pareto") > summary(os) Parameters : estimate shape 0.9246754 scale 1.8253853 Loglikelihood: -2764.145 AIC: 5532.29 BIC: 5542.105 > os <- onestep(x, "pareto", init=list(shape=1, scale=1)) > summary(os) Parameters : estimate shape 0.7178122 scale 1.2870607 Loglikelihood: -2773.679 AIC: 5551.359 BIC: 5561.174 > > proc.time() user system elapsed 1.14 0.17 1.29