From 05ba19cf802e86621d5e8e57294334aadcb48592 Mon Sep 17 00:00:00 2001 From: Felipe Figueiredo Date: Tue, 20 Mar 2018 14:53:09 -0300 Subject: [PATCH 1/8] predint(): new function to compute the prediction interval of data --- R/predint.R | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 R/predint.R diff --git a/R/predint.R b/R/predint.R new file mode 100644 index 0000000..4e3f96f --- /dev/null +++ b/R/predint.R @@ -0,0 +1,10 @@ +predint <- function(datavector, level = 0.95) { + datavector <- datavector[!is.na(datavector)] # discard NA values + N <- length(datavector) + xbar <- mean(datavector, na.rm = na.rm) # X bar + ts <- qt(1-alpha/2, N-1) # student's t with N - 1 degrees of freedom + sdl <- sd(datavector, na.rm = na.rm) # SD of log titers + sq <- sqrt( 1 + 1/N ) # square root term + range <- c(xbar - ts*sdl*sq, xbar + ts*sdl*sq) # formula + range +} From 5a88e82d8e04e64bbee0e00838a2a94b2cc5e8ee Mon Sep 17 00:00:00 2001 From: Felipe Figueiredo Date: Tue, 20 Mar 2018 15:30:37 -0300 Subject: [PATCH 2/8] revert to using alpha, instead of level This way, we don't need to change the formula --- R/predint.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/predint.R b/R/predint.R index 4e3f96f..7a5d2de 100644 --- a/R/predint.R +++ b/R/predint.R @@ -1,4 +1,4 @@ -predint <- function(datavector, level = 0.95) { +predint <- function(datavector, alpha = 0.05) { datavector <- datavector[!is.na(datavector)] # discard NA values N <- length(datavector) xbar <- mean(datavector, na.rm = na.rm) # X bar From bcaf695428a019f907334acab835b2433e69df47 Mon Sep 17 00:00:00 2001 From: Felipe Figueiredo Date: Tue, 20 Mar 2018 15:31:10 -0300 Subject: [PATCH 3/8] we don't need na.rm anymore The NA values are removed in the fist line --- R/predint.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/predint.R b/R/predint.R index 7a5d2de..4179128 100644 --- a/R/predint.R +++ b/R/predint.R @@ -1,9 +1,9 @@ predint <- function(datavector, alpha = 0.05) { datavector <- datavector[!is.na(datavector)] # discard NA values N <- length(datavector) - xbar <- mean(datavector, na.rm = na.rm) # X bar + xbar <- mean(datavector) # X bar ts <- qt(1-alpha/2, N-1) # student's t with N - 1 degrees of freedom - sdl <- sd(datavector, na.rm = na.rm) # SD of log titers + sdl <- sd(datavector) # SD of log titers sq <- sqrt( 1 + 1/N ) # square root term range <- c(xbar - ts*sdl*sq, xbar + ts*sdl*sq) # formula range From 16484dd6b0ba2f283f6c42e0f63345e6096973cb Mon Sep 17 00:00:00 2001 From: Felipe Figueiredo Date: Tue, 20 Mar 2018 15:57:22 -0300 Subject: [PATCH 4/8] doc for predint() --- man/predint.Rd | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 man/predint.Rd diff --git a/man/predint.Rd b/man/predint.Rd new file mode 100644 index 0000000..f0e6f55 --- /dev/null +++ b/man/predint.Rd @@ -0,0 +1,54 @@ +\name{predint} +\alias{predint} +%- Also NEED an '\alias' for EACH other topic documented here. +\title{Prediction Intervals for given data +%% ~~function to do ... ~~ +} +\description{Compute a prediction of a vector, which is assumed normally distributed with unknown mean and variance. +%% ~~ A concise (1-5 lines) description of what the function does. ~~ +} +\usage{ +predint(datavector, alpha = 0.05) +} +%- maybe also 'usage' for other objects documented here. +\arguments{ + \item{datavector}{the data vector} + \item{alpha}{the significance level required (default = 0.05) +%% ~~Describe \code{x} here~~ +} +} +\details{ +%% ~~ If necessary, more details than the description above ~~ +} +\value{a vector of two values +A vector with values giving lower and upper prediction limits for each parameter. +%% ~Describe the value returned +%% If it is a LIST, use +%% \item{comp1 }{Description of 'comp1'} +%% \item{comp2 }{Description of 'comp2'} +%% ... +} +\references{ +%% ~put references to the literature/web site here ~ +} +\author{Felipe Figueiredo +%% ~~who you are~~ +} +\note{ +%% ~~further notes~~ +} + +%% ~Make other sections like Warning with \section{Warning }{....} ~ + +\seealso{ +%% ~~objects to See Also as \code{\link{help}}, ~~~ +} +\examples{ +x <- rnorm(30) +predint(x) +predint(x, alpha = 0.01) +} +% Add one or more standard keywords, see file 'KEYWORDS' in the +% R documentation directory. +\keyword{ ~kwd1 }% use one of RShowDoc("KEYWORDS") +\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line From 972756ea2e98ac00f2adbece96e9e4aae6bb748f Mon Sep 17 00:00:00 2001 From: Felipe Figueiredo Date: Tue, 20 Mar 2018 16:01:10 -0300 Subject: [PATCH 5/8] argument explanation extracted from sd() --- man/predint.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/predint.Rd b/man/predint.Rd index f0e6f55..e72ffad 100644 --- a/man/predint.Rd +++ b/man/predint.Rd @@ -12,7 +12,7 @@ predint(datavector, alpha = 0.05) } %- maybe also 'usage' for other objects documented here. \arguments{ - \item{datavector}{the data vector} + \item{datavector}{a numeric vector or an R object which is coercible to one by as.double(x)} \item{alpha}{the significance level required (default = 0.05) %% ~~Describe \code{x} here~~ } From f81fbbf2b7cc6eb62f198e84d942786bfab5d6c1 Mon Sep 17 00:00:00 2001 From: Felipe Figueiredo Date: Tue, 20 Mar 2018 16:02:05 -0300 Subject: [PATCH 6/8] version bump, and fix LICENSE encoding --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f653cfc..a75bf90 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,10 +1,10 @@ Package: philsfmisc Type: Package Title: philsf's miscellaneous R functions -Version: 0.4.0 +Version: 0.5.0 Authors@R: person("Felipe", "Figueiredo", email = "philsf79@gmail.com", role = c("aut", "cre")) Description: Miscellaneous R functions for convenient data analyses. -License: GPL2 +License: GPL-2 Encoding: UTF-8 LazyData: true URL: https://github.com/philsf/philsfmisc From 94f2c6c080651bf324828ccb9b7038541d96f59a Mon Sep 17 00:00:00 2001 From: Felipe Figueiredo Date: Tue, 20 Mar 2018 16:12:17 -0300 Subject: [PATCH 7/8] build warnings: include global functions in NAMESPACE --- NAMESPACE | 1 + 1 file changed, 1 insertion(+) diff --git a/NAMESPACE b/NAMESPACE index d75f824..ecbb4dd 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1 +1,2 @@ +importFrom("stats", "qt", "sd") exportPattern("^[[:alpha:]]+") From 38fc0bcfa0f7d85a2e1463b742227c5959171006 Mon Sep 17 00:00:00 2001 From: Felipe Figueiredo Date: Tue, 20 Mar 2018 16:48:50 -0300 Subject: [PATCH 8/8] predint documented in the README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1559cf6..c4ba16c 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ To install the *development* version, use the following command: - `geosd` - `geocv` - `logsd2cv` +- `predint` ## Report template