R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 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 a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("plugdensity-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('plugdensity') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "plugin.density" > > ### * plugin.density > > flush(stderr()); flush(stdout()) > > ### Name: plugin.density > ### Title: Kernel Density Estimation by Plug-In Bandwidth Selection > ### Aliases: plugin.density print.densityEHpi > ### Keywords: distribution smooth > > ### ** Examples > > data(co2) > plot(dco2 <- density(co2), ylim = c(0, 0.03)) > (pdco2 <- plugin.density(co2, xout = dco2$x)) EvaHerrmann plugin density estimate call : plugin.density(x = co2, xout = dco2$x) n = 468 ; estimated (Gaussian) bandwidth h = 2.764658 List of 2 $ x: num [1:512] 301.3652 301.5164 301.6677 301.8189 301.9702 ... $ y: num [1:512] 8.410951e-08 1.084367e-07 1.403643e-07 1.779440e-07 2.262085e-07 ... > lines(pdco2, col = "red") > > plot(pdco2)# calls 'plot.density' method > > str(pdco2 <- plugin.density(co2)) List of 6 $ x : num [1:201] 308 308 308 309 309 ... $ y : num [1:201] 0.000281 0.000373 0.000489 0.000634 0.000813 ... $ bw : num 2.76 $ n : int 468 $ call : language plugin.density(x = co2) $ data.name: chr "co2" - attr(*, "class")= chr [1:2] "densityEHpi" "density" > xo <- pdco2 $x > str(d.co2 <- density(co2, n = length(xo), from=xo[1],to=max(xo), + width= 4 * pdco2$bw)) List of 7 $ x : num [1:201] 308 308 308 309 309 ... $ y : num [1:201] 0.000284 0.000376 0.000492 0.000637 0.000818 ... $ bw : num 2.76 $ n : int 468 $ call : language density(x = co2, width = 4 * pdco2$bw, n = length(xo), from = xo[1], to = max(xo)) $ data.name: chr "co2" $ has.na : logi FALSE - attr(*, "class")= chr "density" > nms <- c("x","y", "bw", "n") > all.equal(d.co2[nms], pdco2[nms]) [1] "Component 2: Mean relative difference: 0.0009737517" > ## are close: "Component 2 (= 'y'): Mean relative difference: 0.0009..." > > > > ### *