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. > library(fitdistrplus) Loading required package: MASS Loading required package: survival > > > manageparam <- fitdistrplus:::manageparam > > obs1 <- rnorm(10) > s1 <- NULL > s2 <- list("mean"=2, "sd"=3) > s3 <- function(x) + list("mean"=1.01*mean(x)) > s4 <- list("mean"=1) > > f1 <- NULL > f2 <- list("sd"=3) > f3 <- function(x) + list("sd"=1.01*sd(x)) > f4 <- list("toto"=2) > > #no error > > manageparam(s1, f1, obs1, "norm") $start.arg $start.arg$mean [1] 0.195255 $start.arg$sd [1] 0.9248833 $fix.arg NULL > manageparam(s2, f1, obs1, "norm") $start.arg $start.arg$mean [1] 2 $start.arg$sd [1] 3 $fix.arg NULL > manageparam(s3, f1, obs1, "norm") $start.arg $start.arg$mean [1] 0.1972076 $fix.arg NULL > > manageparam(s1, f2, obs1, "norm") $start.arg $start.arg$mean [1] 0.195255 $fix.arg $fix.arg$sd [1] 3 > manageparam(s1, f3, obs1, "norm") $start.arg $start.arg$mean [1] 0.195255 $fix.arg $fix.arg$sd [1] 0.9846617 > > #raise error > > try(manageparam(matrix(3), f1, obs1, "norm")) Error in manageparam(matrix(3), f1, obs1, "norm") : Wrong type of argument for start > try(manageparam(function(x) c("a"=33), f1, obs1, "norm")) Error in manageparam(function(x) c(a = 33), f1, obs1, "norm") : Starting values must be a named list, your function does not return that. > try(manageparam(function(x) list(33), f1, obs1, "norm")) Error in manageparam(function(x) list(33), f1, obs1, "norm") : Starting values must be a named list, your function does not return that. > try(manageparam(NULL, list(mean=1, sd=1), obs1, "norm")) Error in manageparam(NULL, list(mean = 1, sd = 1), obs1, "norm") : Don't need to use fitdist() if all parameters have fixed values > > > #no error > > checkparamlist <- fitdistrplus:::checkparamlist > > myformal <- names(formals("dnorm")) > > res <- manageparam(s1, f1, obs1, "norm") > checkparamlist(res$start.arg, res$fix.arg, myformal) $start.arg $start.arg$mean [1] 0.195255 $start.arg$sd [1] 0.9248833 $fix.arg NULL > > res <- manageparam(s1, f2, obs1, "norm") > checkparamlist(res$start.arg, res$fix.arg, myformal) $start.arg $start.arg$mean [1] 0.195255 $fix.arg $fix.arg$sd [1] 3 > > res <- manageparam(s1, f3, obs1, "norm") > checkparamlist(res$start.arg, res$fix.arg, myformal) $start.arg $start.arg$mean [1] 0.195255 $fix.arg $fix.arg$sd [1] 0.9846617 > > res <- manageparam(s2, f1, obs1, "norm") > checkparamlist(res$start.arg, res$fix.arg, myformal) $start.arg $start.arg$mean [1] 2 $start.arg$sd [1] 3 $fix.arg NULL > > #raise errors > > res <- manageparam(s1, f4, obs1, "norm") > try(checkparamlist(res$start.arg, res$fix.arg, myformal)) Error in checkparamlist(res$start.arg, res$fix.arg, myformal) : 'fix.arg' must specify names which are arguments to 'distr'. > > res <- manageparam(s2, f2, obs1, "norm") > try(checkparamlist(res$start.arg, res$fix.arg, myformal)) Error in checkparamlist(res$start.arg, res$fix.arg, myformal) : A distribution parameter cannot be specified both in 'start' and 'fix.arg'. > > res <- manageparam(s2, f3, obs1, "norm") > try(checkparamlist(res$start.arg, res$fix.arg, myformal)) Error in checkparamlist(res$start.arg, res$fix.arg, myformal) : A distribution parameter cannot be specified both in 'start' and 'fix.arg'. > > > > #no error > fitdist(obs1, "norm", start=NULL, fix.arg=NULL) Fitting of the distribution ' norm ' by maximum likelihood Parameters: estimate Std. Error mean 0.1952550 0.2924738 sd 0.9248833 0.2068091 > fitdist(obs1, "norm", start=NULL, fix.arg=f3) Fitting of the distribution ' norm ' by maximum likelihood Parameters: estimate Std. Error mean 0.195255 0.3113774 Fixed parameters (computed by a user-supplied function): value sd 0.9846617 > > > #raise error > try(fitdist(obs1, "norm", start=NULL, fix.arg=f4)) Error in checkparamlist(arg_startfix$start.arg, arg_startfix$fix.arg, : 'fix.arg' must specify names which are arguments to 'distr'. > try(fitdist(obs1, "norm", start=s2, fix.arg=f2)) Error in checkparamlist(arg_startfix$start.arg, arg_startfix$fix.arg, : A distribution parameter cannot be specified both in 'start' and 'fix.arg'. > try(fitdist(obs1, "norm", start=s2, fix.arg=f3)) Error in checkparamlist(arg_startfix$start.arg, arg_startfix$fix.arg, : A distribution parameter cannot be specified both in 'start' and 'fix.arg'. > > proc.time() user system elapsed 1.64 0.14 1.75