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 > > n <- 1e3 > > theta <- c(shape=0.8, scale=3) > o.sample <- rweibull(n, shape=theta["shape"], scale=theta["scale"]) > > #### numerical one-step with sub-sample init #### > #i <- 0 > > dweibull2 <- function(x, shape, scale, log=FALSE) + { + #cat("\t\tx", i, "\ttheta", shape, "/-/", scale, "\n") + if(is.function(x)) + { + stop("x is a function") + } + #i <<- i+1 + dweibull(x = x, shape = shape, scale = scale, log = log) + } > args(dweibull) function (x, shape, scale = 1, log = FALSE) NULL > > onestep(o.sample, "weibull2", method="numeric", start=list(shape=1, scale=1), control=list(trace=1)) * one step numeric * one step result before processing output $estimate shape scale 0.7964254 3.1247548 $convergence [1] 0 $value NULL $hessian NULL $optim.function NULL $opt.meth NULL $fix.arg NULL $fix.arg.fun NULL $weights NULL $counts NULL $optim.message NULL $method [1] "numeric" $order NULL $memp NULL $nbstep [1] 1 Parameters: estimate shape 0.7964254 scale 3.1247548 > > mledist(o.sample, "weibull2", start=list(shape=1, scale=1)) $estimate shape scale 0.7964455 3.1242148 $convergence [1] 0 $value [1] 2220.26 $hessian shape scale shape 2877.5129 -136.41941 scale -136.4194 65.01314 $optim.function [1] "optim" $optim.method [1] "Nelder-Mead" $fix.arg NULL $fix.arg.fun NULL $weights NULL $counts function gradient 105 NA $optim.message NULL $loglik [1] -2220.26 > > #### numerical one-step with user-supplied #### > > onestep(o.sample, "weibull", method="numeric", start=list(shape=1, scale=1), control=list(trace=1)) * one step numeric * one step result before processing output $estimate shape scale 0.7964764 3.1231100 $convergence [1] 0 $value NULL $hessian NULL $optim.function NULL $opt.meth NULL $fix.arg NULL $fix.arg.fun NULL $weights NULL $counts NULL $optim.message NULL $method [1] "numeric" $order NULL $memp NULL $nbstep [1] 1 Parameters: estimate shape 0.7964764 scale 3.1231100 Warning message: In onestep(o.sample, "weibull", method = "numeric", start = list(shape = 1, : argument 'method' could be set to 'closed formula' > > proc.time() user system elapsed 1.10 0.09 1.20