From 22c1108887942f92464b0bdd3c02d3dccd21bbbe Mon Sep 17 00:00:00 2001 From: Tyler Hunt Date: Thu, 25 Apr 2013 11:19:48 -0600 Subject: [PATCH 1/3] Changed to polar norm --- R/.gitignore | 1 + R/polar.norm.R | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 R/.gitignore create mode 100644 R/polar.norm.R diff --git a/R/.gitignore b/R/.gitignore new file mode 100644 index 0000000..62b29a2 --- /dev/null +++ b/R/.gitignore @@ -0,0 +1 @@ +rand.norm.R diff --git a/R/polar.norm.R b/R/polar.norm.R new file mode 100644 index 0000000..fcfdf48 --- /dev/null +++ b/R/polar.norm.R @@ -0,0 +1,27 @@ +#' Generate A Random Normal Variable +#' +#' @description A method for generating a random normal variable based upon the polar method. +#' @param mu mean of a normal distribution +#' @param sigma variance of a normal distribution +#' +#' @author Damon McCafferty \email{damon.mccafferty@@economics.utah.edu} +#' +#' @export + +polar.norm<-function(mu, sig) +{ + + u<-(2*wich.hill()-1) + v<-(2*wich.hill()-1) + + s<-u^2+v^2 + + while(s==0||s>=1) + { + u<-(2*wich.hill()-1) + v<-(2*wich.hill()-1) + + s<-u^2+v^2 + } + sig*sqrt(-2*log(s)/s)*u + mu +} From 81bb40ddadfcb6ade63388f0abb753b05e5d046f Mon Sep 17 00:00:00 2001 From: Tyler Hunt Date: Thu, 25 Apr 2013 11:48:10 -0600 Subject: [PATCH 2/3] Added polar norm and tweaks --- DESCRIPTION | 1 + NAMESPACE | 1 + R/polar.norm.R | 2 +- R/rand.norm.R | 2 +- man/maxbound.Rd | 4 ++-- man/pois.proc.Rd | 2 +- man/polar.norm.Rd | 20 ++++++++++++++++++++ man/rand.unif.Rd | 6 +++--- 8 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 man/polar.norm.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 494f53c..5ac1886 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,3 +29,4 @@ Collate: 'around.R' 'nearest.loc.R' 'Bootstrap.R' + 'polar.norm.R' diff --git a/NAMESPACE b/NAMESPACE index da11b0a..a8225af 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -10,6 +10,7 @@ export(nearest.loc) export(newton.raph) export(plot.mc) export(pois.proc) +export(polar.norm) export(rand.exp) export(rand.mvnorm) export(rand.norm) diff --git a/R/polar.norm.R b/R/polar.norm.R index fcfdf48..6150983 100644 --- a/R/polar.norm.R +++ b/R/polar.norm.R @@ -2,7 +2,7 @@ #' #' @description A method for generating a random normal variable based upon the polar method. #' @param mu mean of a normal distribution -#' @param sigma variance of a normal distribution +#' @param sig variance of a normal distribution #' #' @author Damon McCafferty \email{damon.mccafferty@@economics.utah.edu} #' diff --git a/R/rand.norm.R b/R/rand.norm.R index 4437a53..46920c1 100644 --- a/R/rand.norm.R +++ b/R/rand.norm.R @@ -10,4 +10,4 @@ rand.norm<-function(n, mean, sd){ qnorm( replicate( n, wich.hill() ) )*sd + mean -} \ No newline at end of file +} diff --git a/man/maxbound.Rd b/man/maxbound.Rd index fc0b8cf..3de3870 100644 --- a/man/maxbound.Rd +++ b/man/maxbound.Rd @@ -7,9 +7,9 @@ \arguments{ \item{f}{the function to be optimized} - \item{lo}{the lower bound} + \item{lo}{the lower bound.} - \item{hi}{the upper bound} + \item{hi}{the upper bound.} } \description{ Maxbound Optimization diff --git a/man/pois.proc.Rd b/man/pois.proc.Rd index 8399e2b..2abf9db 100644 --- a/man/pois.proc.Rd +++ b/man/pois.proc.Rd @@ -5,7 +5,7 @@ pois.proc(end = 200, rate = 1) } \arguments{ - \item{end}{the end time.} + \item{end}{the end time desired.} \item{rate}{the rate of occurrence.} } diff --git a/man/polar.norm.Rd b/man/polar.norm.Rd new file mode 100644 index 0000000..994bb73 --- /dev/null +++ b/man/polar.norm.Rd @@ -0,0 +1,20 @@ +\name{polar.norm} +\alias{polar.norm} +\title{Generate A Random Normal Variable} +\usage{ + polar.norm(mu, sig) +} +\arguments{ + \item{mu}{mean of a normal distribution} + + \item{sig}{variance of a normal distribution} +} +\description{ + A method for generating a random normal variable based + upon the polar method. +} +\author{ + Damon McCafferty + \email{damon.mccafferty@economics.utah.edu} +} + diff --git a/man/rand.unif.Rd b/man/rand.unif.Rd index 9f10463..0ce8d3d 100644 --- a/man/rand.unif.Rd +++ b/man/rand.unif.Rd @@ -5,11 +5,11 @@ rand.unif(n, min = 0, max = 1) } \arguments{ - \item{n}{Number of observations} + \item{n}{Number of observations.} - \item{min}{lower limit of the distribution} + \item{min}{lower limit of the distribution.} - \item{max}{upper limit of the distribution} + \item{max}{upper limit of the distribution.} } \description{ Generate Random Uniform Variables From 174c6c62aec2bd8b68005ff92faf4a5fa65c91a4 Mon Sep 17 00:00:00 2001 From: Tyler Hunt Date: Thu, 25 Apr 2013 11:56:45 -0600 Subject: [PATCH 3/3] Changed jackknife example to examples --- DESCRIPTION | 1 + NAMESPACE | 1 + R/jackknife.R | 2 +- man/jackknife.Rd | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 man/jackknife.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 5ac1886..33a67a5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -30,3 +30,4 @@ Collate: 'nearest.loc.R' 'Bootstrap.R' 'polar.norm.R' + 'jackknife.R' diff --git a/NAMESPACE b/NAMESPACE index a8225af..7fc3467 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,6 +2,7 @@ export(Bootstrap) export(around) export(em.mixnorm) export(grid.sect) +export(jackknife) export(maxbound) export(mc) export(mixnorm) diff --git a/R/jackknife.R b/R/jackknife.R index 9c2a209..c38bd98 100644 --- a/R/jackknife.R +++ b/R/jackknife.R @@ -14,7 +14,7 @@ #' #' @author Damon McCafferty \email{damon.mccafferty@@economics.utah.edu} #' -#' @example x = runif(10, 0, 1) +#' @examples x = runif(10, 0, 1) #' mean(x) #' jackknife(x,mean) #' diff --git a/man/jackknife.Rd b/man/jackknife.Rd new file mode 100644 index 0000000..6ffcac4 --- /dev/null +++ b/man/jackknife.Rd @@ -0,0 +1,36 @@ +\name{jackknife} +\alias{jackknife} +\title{Resamples Data using the Jackknife Method} +\usage{ + jackknife(x, t) +} +\arguments{ + \item{x}{a vector} + + \item{t}{estimation of parameter} +} +\value{ + est orignial estimation of parameter + + jkest jackknife estimation of parameter + + jkvar jackknife estimation of variance + + jkbias jackknife estimate of biasness of parameter + + jkbiascorr bias corrected parameter estimate +} +\description{ + This function is used for estimating standard errors when + the distribution is not know. +} +\examples{ +x = runif(10, 0, 1) +mean(x) +jackknife(x,mean) +} +\author{ + Damon McCafferty + \email{damon.mccafferty@economics.utah.edu} +} +