R Under development (unstable) (2023-12-02 r85657 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 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. > #### Tests for psi(), rho() etc > > library(robust) Loading required package: fit.models > > ### Test internal consistency > ## (1) rho'(x) = psi(x) > ## (2) psi'(x) = psp(x) > > ## (3) chi(x) = pmin(R, rho(x)) ( *not* the definition for S-estimates !! ) > ## but really chi() = 1/2 psi()^2 Huber; for the others chi() == rho() > > ## > x <- seq(-4,4, length = 801)# large n > x. <- seq(-4,4, length = 2001)# larger n > > verbose <- TRUE > for(ipsi in 1:3) { # later 1:4 -- ipsi = 4 nowhere documented + cat("ipsi = ", ipsi, "\n") + f.x <- cbind(psi = psi.weight(x, ips=ipsi), psp = psp.weight(x, ips=ipsi), + chi = chi.weight(x, ips=ipsi), rho = rho.weight(x, ips=ipsi)) + rhoF <- splinefun(x,f.x[,"rho"]) + psiF <- splinefun(x,f.x[,"psi"]) + pspF <- splinefun(x,f.x[,"psp"]) + ## chiF <- splinefun(x,f.x[,"chi"]) + p1 <- psiF(x., deriv=1); p. <- pspF(x.) + r1 <- rhoF(x., deriv=1); ps <- psiF(x.) + if(verbose) { + cat("psi'(.) = psp(.):", all.equal(p1, p., tol = 1e-6),"\n") + cat("rho'(.) = psi(.):", all.equal(r1, ps, tol = 1e-6),"\n") + ## TODO: chi ? + } + stopifnot(all.equal(p1, p., tol = if(ipsi == 3) .05 else 1e-3), + all.equal(r1, ps, tol = 1e-4)) + if(verbose) cat("\n---------------------\n\n") + } ipsi = 1 psi'(.) = psp(.): Mean relative difference: 0.0002375808 rho'(.) = psi(.): TRUE --------------------- ipsi = 2 psi'(.) = psp(.): Mean relative difference: 0.0002333463 rho'(.) = psi(.): Mean relative difference: 1.896192e-06 --------------------- ipsi = 3 psi'(.) = psp(.): Mean relative difference: 0.03071846 rho'(.) = psi(.): Mean relative difference: 5.115593e-06 --------------------- > > > ### Plots --> ../man/weight.funs.Rd > > proc.time() user system elapsed 0.46 0.03 0.48