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("HyperbolicDist-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('HyperbolicDist') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "SandP500" > > ### * SandP500 > > flush(stderr()); flush(stdout()) > > ### Name: SandP500 > ### Title: Standard and Poor New York Stock Exchange market price index > ### Aliases: SandP500 > ### Keywords: datasets > > ### ** Examples > > data(SandP500) > ## Consider proportional changes in the index > change<-SandP500[-length(SandP500)]/SandP500[-1] > hist(change) > ## Fit hyperbolic distribution to changes > fit.hyperb(change) Hit to see next plot: $pars Pi Zeta Delta Mu BFGS Fitted Normal 0.5191078 2.457194 0.1734520 0.8351562 BFGS Skew Laplace 0.5191204 2.457513 0.1734660 0.8351484 BFGS Barndorff-Nielsen 1977 0.5191640 2.457826 0.1734777 0.8351331 LogLikelihood Convergence Iterations BFGS Fitted Normal 85.05974 Optim 0 18 BFGS Skew Laplace 85.05974 Optim 0 24 BFGS Barndorff-Nielsen 1977 85.05974 Optim 0 28 $breaks [1] 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 $starting.values Pi.start Zeta.start Delta.start Mu.start Barndorff-Nielsen 1977 0.2401149 0.10000000 0.01597477 0.9149878 Fitted Normal -0.1976740 1.03907499 0.17312767 0.9842228 Skew Laplace -0.1728737 0.01212583 0.10000000 0.9423029 > > > > cleanEx(); ..nameEx <- "calculate.range" > > ### * calculate.range > > flush(stderr()); flush(stdout()) > > ### Name: calculate.range > ### Title: Range of a Hyperbolic Distribution > ### Aliases: calculate.range > ### Keywords: distribution > > ### ** Examples > > hyperb.range <- calculate.range(c(3,5,1,0),tol=10^(-2)) > curve(dhyperb(x,c(3,5,1,0)),hyperb.range[1],hyperb.range[2]) > > > > cleanEx(); ..nameEx <- "dhyperb" > > ### * dhyperb > > flush(stderr()); flush(stdout()) > > ### Name: dhyperb > ### Title: Hyperbolic Distribution > ### Aliases: dhyperb phyperb qhyperb rhyperb > ### Keywords: distribution > > ### ** Examples > > theta <- c(0,1,1,0) > data.vector <- rhyperb(500,theta) > par(mfrow=c(1,2)) > hist(data.vector,freq=FALSE) > curve(dhyperb(x,theta),add=TRUE, + range(data.vector)[1],range(data.vector)[2]) > log.hist(data.vector) > curve(log(dhyperb(x,theta)),add=TRUE, + range(data.vector)[1],range(data.vector)[2]) > hyperb.range <- calculate.range(c(0,1,1,0),tol=10^(-2)) > curve(dhyperb(x,theta), + hyperb.range[1],hyperb.range[2],log="") > title("Density of the\n Hyperbolic Distribution") > curve(phyperb(x,theta), + hyperb.range[1],hyperb.range[2],log="") > title("Distribution Function of the\n Hyperbolic Distribution") > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "dskewlap" > > ### * dskewlap > > flush(stderr()); flush(stdout()) > > ### Name: dskewlap > ### Title: Skew-Laplace Density > ### Aliases: dskewlap > ### Keywords: distribution > > ### ** Examples > > theta <- c(1,2,1) > curve(dskewlap(x,theta),from=-3,to=6,n=1000) > > > > cleanEx(); ..nameEx <- "fit.hyperb" > > ### * fit.hyperb > > flush(stderr()); flush(stdout()) > > ### Name: fit.hyperb > ### Title: Fit the Hyperbolic Distribution to Data > ### Aliases: fit.hyperb > ### Keywords: distribution > > ### ** Examples > > theta <- c(2,2,2,2) > data.vector <- rhyperb(500,theta) > ## See how well fit.hyperb works > fit.hyperb(data.vector) Hit to see next plot: $pars Pi Zeta Delta Mu LogLikelihood BFGS Barndorff-Nielsen 1977 6.276476 3.088407 0.9503354 0.2985787 -1426.168 BFGS Fitted Normal 6.211244 3.086036 0.9593930 0.3040853 -1426.169 BFGS Skew Laplace 5.155649 3.023692 1.1340908 0.4098277 -1426.193 Convergence Iterations BFGS Barndorff-Nielsen 1977 Optim 0 74 BFGS Fitted Normal Optim 0 74 BFGS Skew Laplace Optim 0 68 $breaks [1] 0 5 10 15 20 25 30 35 $starting.values Pi.start Zeta.start Delta.start Mu.start Barndorff-Nielsen 1977 0.0470815 0.04953286 0.2389997 7.728012 Fitted Normal -0.3711016 1.13771643 4.9595548 9.340499 Skew Laplace -0.6498689 0.27455543 0.1000000 5.772297 > ## Use nlm instead of default > fit.hyperb(data.vector,method="nlm") Warning: NA/Inf replaced by maximum positive value Warning: NA/Inf replaced by maximum positive value Warning: NA/Inf replaced by maximum positive value Warning: NA/Inf replaced by maximum positive value Warning: NA/Inf replaced by maximum positive value Warning: NA/Inf replaced by maximum positive value Warning: NA/Inf replaced by maximum positive value Warning: NA/Inf replaced by maximum positive value Warning: NA/Inf replaced by maximum positive value Warning: NA/Inf replaced by maximum positive value Warning: NA/Inf replaced by maximum positive value Warning: NA/Inf replaced by maximum positive value Warning: NA/Inf replaced by maximum positive value Warning: NA/Inf replaced by maximum positive value Warning: NA/Inf replaced by maximum positive value Hit to see next plot: $pars Pi Zeta Delta Mu NLM Skew Laplace 65.81723 3.189613 0.09371906 0.09561108 NLM Fitted Normal 63.46043 3.189348 0.09719342 0.09592395 NLM Barndorff-Nielsen 1977 63.10577 3.189493 0.09774237 0.09582076 LogLikelihood Convergence Iterations NLM Skew Laplace -1426.121 Nlm 1 353 NLM Fitted Normal -1426.121 Nlm 1 299 NLM Barndorff-Nielsen 1977 -1426.121 Nlm 1 337 $breaks [1] 0 5 10 15 20 25 30 35 $starting.values Pi.start Zeta.start Delta.start Mu.start Barndorff-Nielsen 1977 0.0470815 0.04953286 0.2389997 7.728012 Fitted Normal -0.3711016 1.13771643 4.9595548 9.340499 Skew Laplace -0.6498689 0.27455543 0.1000000 5.772297 > > > > cleanEx(); ..nameEx <- "hyperb.change.pars" > > ### * hyperb.change.pars > > flush(stderr()); flush(stdout()) > > ### Name: hyperb.change.pars > ### Title: Change Parameterisations of the Hyperbolic Distribution > ### Aliases: hyperb.change.pars > ### Keywords: distribution > > ### ** Examples > > theta1 <- c(-2,1,3,0) # Parameter vector in parameterisation 1 > theta2 <- hyperb.change.pars(1,2,theta1) # Convert to parameterisation 2 > theta2 # Parameter vector in parameterisation 2 alpha beta delta mu 0.7453560 -0.6666667 3.0000000 0.0000000 > hyperb.change.pars(2,1,as.numeric(theta2)) # Convert back to parameterisation 1 hyperb.pi zeta delta mu -2 1 3 0 > > > > cleanEx(); ..nameEx <- "hyperb.mean" > > ### * hyperb.mean > > flush(stderr()); flush(stdout()) > > ### Name: hyperb.mean > ### Title: Mean, Variance and Mode of the Hyperbolic Distribution > ### Aliases: hyperb.mean hyperb.var hyperb.mode R.lambda S.lambda > ### Keywords: distribution > > ### ** Examples > > theta <- c(2,2,2,2) > hyperb.mean(theta) [1] 9.257231 > hyperb.var(theta) [1] 25.01906 > hyperb.mode(theta) [1] 6 > > > > cleanEx(); ..nameEx <- "log.hist" > > ### * log.hist > > flush(stderr()); flush(stdout()) > > ### Name: log.hist > ### Title: Plot Log-Histogram > ### Aliases: log.hist > ### Keywords: hplot distribution > > ### ** Examples > > data(SandP500) > ## Consider proportional changes in the index > change<-SandP500[-length(SandP500)]/SandP500[-1] > hist(change) > log.hist(change) > ## Fit the hyperbolic distribution to the changes > fit.hyperb(change) Hit to see next plot: $pars Pi Zeta Delta Mu BFGS Fitted Normal 0.5191078 2.457194 0.1734520 0.8351562 BFGS Skew Laplace 0.5191204 2.457513 0.1734660 0.8351484 BFGS Barndorff-Nielsen 1977 0.5191640 2.457826 0.1734777 0.8351331 LogLikelihood Convergence Iterations BFGS Fitted Normal 85.05974 Optim 0 18 BFGS Skew Laplace 85.05974 Optim 0 24 BFGS Barndorff-Nielsen 1977 85.05974 Optim 0 28 $breaks [1] 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 $starting.values Pi.start Zeta.start Delta.start Mu.start Barndorff-Nielsen 1977 0.2401149 0.10000000 0.01597477 0.9149878 Fitted Normal -0.1976740 1.03907499 0.17312767 0.9842228 Skew Laplace -0.1728737 0.01212583 0.10000000 0.9423029 > > > cleanEx(); ..nameEx <- "mamquam" > > ### * mamquam > > flush(stderr()); flush(stdout()) > > ### Name: mamquam > ### Title: Size of gravel from Mamquam River > ### Aliases: mamquam > ### Keywords: datasets > > ### ** Examples > > data(mamquam) > str(mamquam) `data.frame': 16 obs. of 2 variables: $ midpoints: num 0.75 1.25 1.75 2.25 2.75 3.25 3.75 4.25 4.75 5.25 ... $ counts : num 1 6 34 58 94 161 262 340 497 628 ... > attach(mamquam) > ## construct data from frequency summary, taking all observations > ## at midpoints of intervals > psi <- rep(midpoints,counts) > summary(psi) Min. 1st Qu. Median Mean 3rd Qu. Max. 0.750 4.250 5.250 5.121 5.750 8.250 > ## fit the hyperbolic distribution > fit.hyperb(psi) Hit to see next plot: $pars Pi Zeta Delta Mu BFGS Barndorff-Nielsen 1977 -0.9686424 9.450605e+00 2.339965e+00 7.755709 BFGS Fitted Normal -0.9687698 9.444454e+00 2.338917e+00 7.755056 BFGS Skew Laplace -0.3820510 2.875635e-05 2.368049e-05 5.750054 LogLikelihood Convergence Iterations BFGS Barndorff-Nielsen 1977 -5542.066 Optim 0 33 BFGS Fitted Normal -5542.066 Optim 0 37 BFGS Skew Laplace -5600.763 Optim 0 28 $breaks [1] 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 $starting.values Pi.start Zeta.start Delta.start Mu.start Barndorff-Nielsen 1977 -0.3386220 0.84341380 0.5229699 5.688712 Fitted Normal 0.5354212 1.28667588 1.1752746 5.120733 Skew Laplace 0.3821163 0.08235192 0.1000000 5.750000 > ## actually fit.hyperb can deal with frequency data > fit.hyperb(midpoints, freq=counts) Hit to see next plot: $pars Pi Zeta Delta Mu BFGS Barndorff-Nielsen 1977 -0.9686424 9.450605e+00 2.339965e+00 7.755709 BFGS Fitted Normal -0.9687698 9.444454e+00 2.338917e+00 7.755056 BFGS Skew Laplace -0.3820510 2.875635e-05 2.368049e-05 5.750054 LogLikelihood Convergence Iterations BFGS Barndorff-Nielsen 1977 -5542.066 Optim 0 33 BFGS Fitted Normal -5542.066 Optim 0 37 BFGS Skew Laplace -5600.763 Optim 0 28 $breaks [1] 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 $starting.values Pi.start Zeta.start Delta.start Mu.start Barndorff-Nielsen 1977 -0.3386220 0.84341380 0.5229699 5.688712 Fitted Normal 0.5354212 1.28667588 1.1752746 5.120733 Skew Laplace 0.3821163 0.08235192 0.1000000 5.750000 > > > > cleanEx(); ..nameEx <- "resistors" > > ### * resistors > > flush(stderr()); flush(stdout()) > > ### Name: resistors > ### Title: Resistance of One-half-ohm Resistors > ### Aliases: resistors > ### Keywords: datasets > > ### ** Examples > > data(resistors) > str(resistors) `data.frame': 28 obs. of 2 variables: $ midpoints: num 0.337 0.362 0.387 0.412 0.437 0.462 0.487 0.512 0.537 0.562 ... $ counts : num 1 1 2 9 24 34 44 43 56 41 ... > attach(resistors) > ## construct data from frequency summary, taking all observations > ## at midpoints of intervals > resistances <- rep(midpoints,counts) > hist(resistances) > log.hist(resistances) > ## fit the hyperbolic distribution > fit.hyperb(resistances) Hit to see next plot: $pars Pi Zeta Delta Mu LogLikelihood BFGS Skew Laplace 1.254695 5.732243 0.1368702 0.3673533 426.7935 BFGS Barndorff-Nielsen 1977 1.256869 5.743005 0.1368793 0.3670495 426.7934 BFGS Fitted Normal 1.262138 5.773497 0.1369630 0.3662529 426.7934 Convergence Iterations BFGS Skew Laplace Optim 0 37 BFGS Barndorff-Nielsen 1977 Optim 0 27 BFGS Fitted Normal Optim 0 33 $breaks [1] 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.70 0.75 0.80 0.85 0.90 0.95 1.00 [16] 1.05 $starting.values Pi.start Zeta.start Delta.start Mu.start Barndorff-Nielsen 1977 0.5118681 0.471629475 0.0309775 0.5196857 Fitted Normal -0.5530789 1.305896277 0.1097493 0.5857000 Skew Laplace -0.5085512 0.007246037 0.1000000 0.5120000 > ## actually fit.hyperb can deal with frequency data > fit.hyperb(midpoints, freq=counts) Hit to see next plot: $pars Pi Zeta Delta Mu LogLikelihood BFGS Skew Laplace 1.254695 5.732243 0.1368702 0.3673533 426.7935 BFGS Barndorff-Nielsen 1977 1.256869 5.743005 0.1368793 0.3670495 426.7934 BFGS Fitted Normal 1.262138 5.773497 0.1369630 0.3662529 426.7934 Convergence Iterations BFGS Skew Laplace Optim 0 37 BFGS Barndorff-Nielsen 1977 Optim 0 27 BFGS Fitted Normal Optim 0 33 $breaks [1] 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.70 0.75 0.80 0.85 0.90 0.95 1.00 [16] 1.05 $starting.values Pi.start Zeta.start Delta.start Mu.start Barndorff-Nielsen 1977 0.5118681 0.471629475 0.0309775 0.5196857 Fitted Normal -0.5530789 1.305896277 0.1097493 0.5857000 Skew Laplace -0.5085512 0.007246037 0.1000000 0.5120000 > > > > ### *