library(Deriv) d1 <- Deriv(dnorm,"sd") source("d2.txt") # d2.txt is attached
d1(1,0,3,TRUE) # [1] -0.2962963 d2(1,0,3,TRUE) # [1] -0.8888889 cheers, Rolf P.S.: > sessionInfo() R version 4.1.1 (2021-08-10) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 20.04.3 LTS Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/atlas/libblas.so.3.10.3 LAPACK: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so.3.10.3 locale: [1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_NZ.UTF-8 LC_COLLATE=en_GB.UTF-8 [5] LC_MONETARY=en_NZ.UTF-8 LC_MESSAGES=en_GB.UTF-8 [7] LC_PAPER=en_NZ.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_NZ.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] Deriv_4.1.3 brev_0.0-7 loaded via a namespace (and not attached): [1] magrittr_1.5 usethis_2.0.1 devtools_2.4.2 pkgload_1.2.1 [5] colorspace_1.4-1 R6_2.4.1 rlang_0.4.11 fastmap_1.0.1 [9] tools_4.1.1 pkgbuild_1.2.0 sessioninfo_1.1.1 cli_2.5.0 [13] withr_2.4.2 ellipsis_0.3.2 remotes_2.4.0 rprojroot_1.3-2 [17] lifecycle_1.0.0 crayon_1.3.4 processx_3.5.2 purrr_0.3.4 [21] callr_3.7.0 fs_1.5.0 ps_1.6.0 testthat_3.0.3 [25] memoise_2.0.0 glue_1.4.0 cachem_1.0.5 compiler_4.1.1 [29] desc_1.3.0 backports_1.1.6 prettyunits_1.1.1 -- Honorary Research Fellow Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276
d2 <- function (x, mean = 0, sd = 1, log = FALSE) (((x - mean)/sd)^2 - 1) * if (log) 1 else dnorm(x, mean, sd)/sd
______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.