Skip to content

Commit

Permalink
add roxygen stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
WillyRay committed Oct 22, 2024
1 parent 1497ac4 commit 6285803
Show file tree
Hide file tree
Showing 10 changed files with 503 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.Rhistory
.Rproj.user
Empty file added DESCRIPTION
Empty file.
Empty file added NAMESPACE
Empty file.
7 changes: 6 additions & 1 deletion R/getFinalSize.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
library(deSolve)

#' @export
getFinalSizeAnalytic <- function(Rinit, Iinit, Vinit, N, R0, a, eps, q) {

Check warning on line 4 in R/getFinalSize.R

View workflow job for this annotation

GitHub Actions / Pre-commit

file=/home/runner/work/vaccine-equity-model/vaccine-equity-model/R/getFinalSize.R,line=4,col=1,[object_name_linter] Variable and function name style should match snake_case or symbols.

Check warning on line 4 in R/getFinalSize.R

View workflow job for this annotation

GitHub Actions / Pre-commit

file=/home/runner/work/vaccine-equity-model/vaccine-equity-model/R/getFinalSize.R,line=4,col=34,[object_name_linter] Variable and function name style should match snake_case or symbols.

Check warning on line 4 in R/getFinalSize.R

View workflow job for this annotation

GitHub Actions / Pre-commit

file=/home/runner/work/vaccine-equity-model/vaccine-equity-model/R/getFinalSize.R,line=4,col=41,[object_name_linter] Variable and function name style should match snake_case or symbols.

Check warning on line 4 in R/getFinalSize.R

View workflow job for this annotation

GitHub Actions / Pre-commit

file=/home/runner/work/vaccine-equity-model/vaccine-equity-model/R/getFinalSize.R,line=4,col=48,[object_name_linter] Variable and function name style should match snake_case or symbols.

Check warning on line 4 in R/getFinalSize.R

View workflow job for this annotation

GitHub Actions / Pre-commit

file=/home/runner/work/vaccine-equity-model/vaccine-equity-model/R/getFinalSize.R,line=4,col=55,[object_name_linter] Variable and function name style should match snake_case or symbols.

Check warning on line 4 in R/getFinalSize.R

View workflow job for this annotation

GitHub Actions / Pre-commit

file=/home/runner/work/vaccine-equity-model/vaccine-equity-model/R/getFinalSize.R,line=4,col=58,[object_name_linter] Variable and function name style should match snake_case or symbols.

if (sum(Iinit) == 0) Iinit <- N / sum(N)

Check warning on line 6 in R/getFinalSize.R

View workflow job for this annotation

GitHub Actions / Pre-commit

file=/home/runner/work/vaccine-equity-model/vaccine-equity-model/R/getFinalSize.R,line=6,col=24,[object_name_linter] Variable and function name style should match snake_case or symbols.
Expand All @@ -24,6 +25,7 @@ getFinalSizeAnalytic <- function(Rinit, Iinit, Vinit, N, R0, a, eps, q) {
opt$par + Iinit + Rinit
}

#' @export
exposure.SIR <- function(Time, state, Pars) {
with(as.list(c(Time, state, Pars)), {

Expand All @@ -48,6 +50,7 @@ exposure.SIR <- function(Time, state, Pars) {
})
}

#' @export
rescale.R0 <- function(beta, gam, pop.p, N, R0.value) {
NGM.unscaled <- N * pop.p * beta * 1 / gam
dom.eigen <- as.numeric(eigen(NGM.unscaled)$values[1])
Expand All @@ -57,6 +60,7 @@ rescale.R0 <- function(beta, gam, pop.p, N, R0.value) {
return(scaling.factor)
}

#' @export
sim.exposure.SIR <- function(Rinit, Iinit, Vinit, tm, N, R0, gam, a, eps, q) {

Ntot <- sum(N)
Expand Down Expand Up @@ -96,7 +100,7 @@ sim.exposure.SIR <- function(Rinit, Iinit, Vinit, tm, N, R0, gam, a, eps, q) {
simulation
}


#' @export
getFinalSize <- function(vacTime, vacPortion, popSize, R0, recoveryRate,
contactRatio, contactWithinGroup, suscRatio) {
# vacTime: time after first case at which all vaccinations are delivered
Expand Down Expand Up @@ -125,6 +129,7 @@ getFinalSize <- function(vacTime, vacPortion, popSize, R0, recoveryRate,

}

#' @export
finalSizeExample <- getFinalSize(vacTime = 100, vacPortion = c(0.1, 0.1),
popSize = c(800000, 200000), R0 = 1.5, recoveryRate = 1 / 7,
contactRatio = 1.7, contactWithinGroup = c(0.4, 0.4), suscRatio = 1)
82 changes: 82 additions & 0 deletions man/exposure.SIR.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
\name{exposure.SIR}
\alias{exposure.SIR}
%- Also NEED an '\alias' for EACH other topic documented here.
\title{
A Capitalized Title (ideally limited to 65 characters)
}
\description{
%% ~~ A concise (1-5 lines) description of what the function does. ~~
}
\usage{
exposure.SIR(Time, state, Pars)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
\item{Time}{
%% ~~Describe \code{Time} here~~
}
\item{state}{
%% ~~Describe \code{state} here~~
}
\item{Pars}{
%% ~~Describe \code{Pars} here~~
}
}
\details{
%% ~~ If necessary, more details than the description above ~~
}
\value{
%% ~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{
%% ~~who you are~~
}
\note{
%% ~~further notes~~
}

%% ~Make other sections like Warning with \section{Warning }{....} ~

\seealso{
%% ~~objects to See Also as \code{\link{help}}, ~~~
}
\examples{
##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or standard data sets, see data().

## The function is currently defined as
function (Time, state, Pars)
{
with(as.list(c(Time, state, Pars)), {
S <- c(S1, S2)
I <- c(I1, I2)
R <- c(R1, R2)
N <- c(N1, N2)
beta <- (1 - epsilon) * outer(activities, activities)/sum(c(N1,
N2) * activities) + epsilon * activities/c(N1, N2) *
diag(2)
beta <- beta/scaling.factor
dS <- -(beta \%*\% I) * S
dI <- (beta \%*\% I) * S - gam * I
dR <- gam * I
return(list(c(dS, dI, dR)))
})
}
}
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory (show via RShowDoc("KEYWORDS")):
% \keyword{ ~kwd1 }
% \keyword{ ~kwd2 }
% Use only one keyword per line.
% For non-standard keywords, use \concept instead of \keyword:
% \concept{ ~cpt1 }
% \concept{ ~cpt2 }
% Use only one concept per line.
28 changes: 28 additions & 0 deletions man/finalSizeExample.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
\name{finalSizeExample}
\alias{finalSizeExample}
\docType{data}
\title{
A Capitalized Title for the Data Set
}
\description{
%% ~~ A concise (1-5 lines) description of the dataset. ~~
}
\usage{data("finalSizeExample")}
\format{
The format is:
num [1:2] 233224 102557
}
\details{
%% ~~ If necessary, more details than the __description__ above ~~
}
\source{
%% ~~ reference to a publication or URL from which the data were obtained ~~
}
\references{
%% ~~ possibly secondary sources and usages ~~
}
\examples{
data(finalSizeExample)
## maybe str(finalSizeExample) ; plot(finalSizeExample) ...
}
\keyword{datasets}
97 changes: 97 additions & 0 deletions man/getFinalSize.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
\name{getFinalSize}
\alias{getFinalSize}
%- Also NEED an '\alias' for EACH other topic documented here.
\title{
A Capitalized Title (ideally limited to 65 characters)
}
\description{
%% ~~ A concise (1-5 lines) description of what the function does. ~~
}
\usage{
getFinalSize(vacTime, vacPortion, popSize, R0, recoveryRate, contactRatio, contactWithinGroup, suscRatio)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
\item{vacTime}{
%% ~~Describe \code{vacTime} here~~
}
\item{vacPortion}{
%% ~~Describe \code{vacPortion} here~~
}
\item{popSize}{
%% ~~Describe \code{popSize} here~~
}
\item{R0}{
%% ~~Describe \code{R0} here~~
}
\item{recoveryRate}{
%% ~~Describe \code{recoveryRate} here~~
}
\item{contactRatio}{
%% ~~Describe \code{contactRatio} here~~
}
\item{contactWithinGroup}{
%% ~~Describe \code{contactWithinGroup} here~~
}
\item{suscRatio}{
%% ~~Describe \code{suscRatio} here~~
}
}
\details{
%% ~~ If necessary, more details than the description above ~~
}
\value{
%% ~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{
%% ~~who you are~~
}
\note{
%% ~~further notes~~
}

%% ~Make other sections like Warning with \section{Warning }{....} ~

\seealso{
%% ~~objects to See Also as \code{\link{help}}, ~~~
}
\examples{
##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or standard data sets, see data().

## The function is currently defined as
function (vacTime, vacPortion, popSize, R0, recoveryRate, contactRatio,
contactWithinGroup, suscRatio)
{
Isim1 <- c(0, 0)
Rsim1 <- c(0, 0)
if (vacTime > 0) {
sim1 <- sim.exposure.SIR(Rinit = c(0, 0), Iinit = c(0,
0), Vinit = c(0, 0), tm = vacTime, N = popSize, R0 = R0,
gam = recoveryRate, a = c(1, contactRatio), eps = contactWithinGroup,
q = c(1, suscRatio))
Isim1 <- as.numeric(sim1[nrow(sim1), c("I1", "I2")])
Rsim1 <- as.numeric(sim1[nrow(sim1), c("R1", "R2")])
}
getFinalSizeAnalytic(Rinit = Rsim1, Iinit = Isim1, Vinit = popSize *
vacPortion, N = popSize, R0 = R0, a = c(1, contactRatio),
eps = contactWithinGroup, q = c(1, suscRatio))
}
}
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory (show via RShowDoc("KEYWORDS")):
% \keyword{ ~kwd1 }
% \keyword{ ~kwd2 }
% Use only one keyword per line.
% For non-standard keywords, use \concept instead of \keyword:
% \concept{ ~cpt1 }
% \concept{ ~cpt2 }
% Use only one concept per line.
100 changes: 100 additions & 0 deletions man/getFinalSizeAnalytic.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
\name{getFinalSizeAnalytic}
\alias{getFinalSizeAnalytic}
%- Also NEED an '\alias' for EACH other topic documented here.
\title{
A Capitalized Title (ideally limited to 65 characters)
}
\description{
%% ~~ A concise (1-5 lines) description of what the function does. ~~
}
\usage{
getFinalSizeAnalytic(Rinit, Iinit, Vinit, N, R0, a, eps, q)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
\item{Rinit}{
%% ~~Describe \code{Rinit} here~~
}
\item{Iinit}{
%% ~~Describe \code{Iinit} here~~
}
\item{Vinit}{
%% ~~Describe \code{Vinit} here~~
}
\item{N}{
%% ~~Describe \code{N} here~~
}
\item{R0}{
%% ~~Describe \code{R0} here~~
}
\item{a}{
%% ~~Describe \code{a} here~~
}
\item{eps}{
%% ~~Describe \code{eps} here~~
}
\item{q}{
%% ~~Describe \code{q} here~~
}
}
\details{
%% ~~ If necessary, more details than the description above ~~
}
\value{
%% ~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{
%% ~~who you are~~
}
\note{
%% ~~further notes~~
}

%% ~Make other sections like Warning with \section{Warning }{....} ~

\seealso{
%% ~~objects to See Also as \code{\link{help}}, ~~~
}
\examples{
##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or standard data sets, see data().

## The function is currently defined as
function (Rinit, Iinit, Vinit, N, R0, a, eps, q)
{
if (sum(Iinit) == 0)
Iinit <- N/sum(N)
Sinit <- N - Rinit - Iinit - Vinit
fn <- (1 - eps) * a * N
f <- fn/sum(fn)
cij <- diag(eps) + outer((1 - eps), f)
R0i <- R0/eigen(a * q * cij)$values[1] * a * q
Zrhs <- function(Z) c(Sinit * (1 - exp(-R0i * cij \%*\% ((Z +
Iinit)/N))))
optfn <- function(x) ifelse(all(x > 0), max(abs(x - Zrhs(x))),
Inf)
optVal <- Inf
while (optVal > 1) {
opt <- optim((0.01 + 0.98 * runif(length(N))) * N, optfn)
optVal <- opt$value
}
opt$par + Iinit + Rinit
}
}
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory (show via RShowDoc("KEYWORDS")):
% \keyword{ ~kwd1 }
% \keyword{ ~kwd2 }
% Use only one keyword per line.
% For non-standard keywords, use \concept instead of \keyword:
% \concept{ ~cpt1 }
% \concept{ ~cpt2 }
% Use only one concept per line.
Loading

0 comments on commit 6285803

Please sign in to comment.