Skip to content

Commit

Permalink
split functions into separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
d-morrison committed Dec 7, 2023
1 parent 1502467 commit 1c6a345
Show file tree
Hide file tree
Showing 14 changed files with 513 additions and 417 deletions.
141 changes: 71 additions & 70 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,70 +1,71 @@
# Generated by roxygen2: do not edit by hand

S3method("[",seroincidence.by)
S3method(plot,seroincidence)
S3method(plot,seroincidence.by)
S3method(plot,summary.seroincidence.by)
S3method(print,seroincidence)
S3method(print,seroincidence.by)
S3method(print,summary.seroincidence.by)
S3method(strata,default)
S3method(summary,seroincidence)
S3method(summary,seroincidence.by)
export(est.incidence)
export(est.incidence.by)
export(fdev)
export(getAdditionalData)
export(graph.loglik)
export(sim.cs)
export(sim.cs.multi)
importFrom(Rcpp,sourceCpp)
importFrom(doParallel,registerDoParallel)
importFrom(dplyr,across)
importFrom(dplyr,all_of)
importFrom(dplyr,anti_join)
importFrom(dplyr,any_of)
importFrom(dplyr,bind_rows)
importFrom(dplyr,count)
importFrom(dplyr,distinct)
importFrom(dplyr,everything)
importFrom(dplyr,filter)
importFrom(dplyr,inner_join)
importFrom(dplyr,is.grouped_df)
importFrom(dplyr,mutate)
importFrom(dplyr,n)
importFrom(dplyr,n_distinct)
importFrom(dplyr,pull)
importFrom(dplyr,relocate)
importFrom(dplyr,rename)
importFrom(dplyr,row_number)
importFrom(dplyr,select)
importFrom(dplyr,semi_join)
importFrom(dplyr,tibble)
importFrom(dplyr,ungroup)
importFrom(foreach,"%:%")
importFrom(foreach,"%dopar%")
importFrom(foreach,foreach)
importFrom(ggplot2,aes)
importFrom(lifecycle,deprecated)
importFrom(magrittr,"%>%")
importFrom(rlang,.data)
importFrom(rlang,.env)
importFrom(rngtools,RNGseq)
importFrom(rngtools,setRNG)
importFrom(stats,dlnorm)
importFrom(stats,formula)
importFrom(stats,nlm)
importFrom(stats,optim)
importFrom(stats,pgamma)
importFrom(stats,plnorm)
importFrom(stats,qnorm)
importFrom(stats,runif)
importFrom(stats,xtabs)
importFrom(tibble,as_tibble)
importFrom(tibble,column_to_rownames)
importFrom(tibble,tibble)
importFrom(tidyr,drop_na)
importFrom(tidyr,pivot_longer)
importFrom(utils,download.file)
importFrom(utils,unzip)
useDynLib(serocalculator, .registration = TRUE)
# Generated by roxygen2: do not edit by hand

S3method("[",seroincidence.by)
S3method(plot,seroincidence)
S3method(plot,seroincidence.by)
S3method(plot,summary.seroincidence.by)
S3method(print,seroincidence)
S3method(print,seroincidence.by)
S3method(print,summary.seroincidence.by)
S3method(strata,seroincidence.by)
S3method(summary,seroincidence)
S3method(summary,seroincidence.by)
export(est.incidence)
export(est.incidence.by)
export(fdev)
export(getAdditionalData)
export(graph.loglik)
export(mkbaseline)
export(sim.cs)
export(sim.cs.multi)
importFrom(Rcpp,sourceCpp)
importFrom(doParallel,registerDoParallel)
importFrom(dplyr,across)
importFrom(dplyr,all_of)
importFrom(dplyr,anti_join)
importFrom(dplyr,any_of)
importFrom(dplyr,bind_rows)
importFrom(dplyr,count)
importFrom(dplyr,distinct)
importFrom(dplyr,everything)
importFrom(dplyr,filter)
importFrom(dplyr,inner_join)
importFrom(dplyr,is.grouped_df)
importFrom(dplyr,mutate)
importFrom(dplyr,n)
importFrom(dplyr,n_distinct)
importFrom(dplyr,pull)
importFrom(dplyr,relocate)
importFrom(dplyr,rename)
importFrom(dplyr,row_number)
importFrom(dplyr,select)
importFrom(dplyr,semi_join)
importFrom(dplyr,tibble)
importFrom(dplyr,ungroup)
importFrom(foreach,"%:%")
importFrom(foreach,"%dopar%")
importFrom(foreach,foreach)
importFrom(ggplot2,aes)
importFrom(lifecycle,deprecated)
importFrom(magrittr,"%>%")
importFrom(rlang,.data)
importFrom(rlang,.env)
importFrom(rngtools,RNGseq)
importFrom(rngtools,setRNG)
importFrom(stats,dlnorm)
importFrom(stats,formula)
importFrom(stats,nlm)
importFrom(stats,optim)
importFrom(stats,pgamma)
importFrom(stats,plnorm)
importFrom(stats,qnorm)
importFrom(stats,runif)
importFrom(stats,xtabs)
importFrom(tibble,as_tibble)
importFrom(tibble,column_to_rownames)
importFrom(tibble,tibble)
importFrom(tidyr,drop_na)
importFrom(tidyr,pivot_longer)
importFrom(utils,download.file)
importFrom(utils,unzip)
useDynLib(serocalculator, .registration = TRUE)
18 changes: 18 additions & 0 deletions R/ltpar.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# not used?
ltpar <- function(k.test, ...) {
y0.mc <- par.pred(1, k.test, ...)

y1.mc <- par.pred(2, k.test, ...)

t1.mc <- par.pred(3, k.test, ...)

alpha.mc <- par.pred(4,k.test, ...);
shape.mc <- par.pred(5,k.test, ...);
return(
data.frame(
"y1"=y1.mc,
"alpha"=alpha.mc,
"r"=shape.mc,
"y0"=y0.mc,
"t1"=t1.mc));
}
69 changes: 69 additions & 0 deletions R/par-extract.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

### these below are copied from Pater's par-extract.r script
par.pred <- function(parnum, k.test, predpar)
{
if (parnum == 2)
{
par1 <- exp(predpar[k.test, 1, ])

par2 <- exp(predpar[k.test, parnum, ])

return(par1 + par2)

} else
{

par <- exp(predpar[k.test, parnum, ])

if (parnum == 5)
{
return(par + 1)
} else
{
return(par)
}

}
}



# Generate longitudinal parameter sample for the simulation model
# parnum: use y0=par[1]; b0=par[2]; mu0=par[3]; mu1=par[4]; c1=par[5];
# alpha=par[6]; shape=par[7] (dmu = mu1 - mu0; b0 = 1)
mu1fn <- function(y0,y1,t1) log(y1/y0)/t1;
mu0fn <- function(beta,y0,y1,t1) mu1fn(y0,y1,t1)*exp(beta)/(1+exp(beta));
dmufn <- function(beta,y0,y1,t1) mu1fn(y0,y1,t1)/(1+exp(beta));
t1fn <- function(beta,y0,y1,t1,c1)
log(1+dmufn(beta,y0,y1,t1)/(c1*y0))/dmufn(beta,y0,y1,t1);
y1fn <- function(beta,y0,y1,t1,c1)
y0*(1+dmufn(beta,y0,y1,t1)/(c1*y0))^(1+exp(beta))
objfnt1 <- function(par,y0,y1,t1) (t1-t1fn(par[1],y0,y1,t1,exp(par[2])))^2;
# the longitudinal model estimates observables: y0, y1, t1, alpha, shape
# for the simulation model we need mu0, mu1 and c1 (=c/b0)
# mu1 can be calculated (see above) but mu0 and c1 are not so easy
# the equation for t1 (above) can be used to calculate dmu (= mu1 - mu0)
# and c1. We need a pair (dmu, c1) that minimizes the difference
# (t1 - t1fn(dmu, c1, y0))^2. This is done in the following function
estpart1 <- function(y0,y1,t1){
# est <- nlm(objfn,c(-1,-12),y0=y0,t1=t1); # print(est$estimate);
# if(sqrt(est$minimum/t1)>1e0) print(sqrt(est$minimum));# return(NA);
# return(exp(est$estimate));
est <- optim(c(-1,-12),objfnt1,y0=y0,y1=y1,t1=t1,method="Nelder-Mead");
if(sqrt(est$value/t1)>1e-1) print(sqrt(est$value));
return(c(exp(est$par[1])/(1+exp(est$par[1])),exp(est$par[2])));
}

par.pred.n <- function(parnum,k.test,nmc, predpar, ...){
if(parnum==2){
par1 <- exp(predpar[k.test,1,nmc]);
par2 <- exp(predpar[k.test,parnum,nmc]);
return(par1+par2);
}
par <- exp(predpar[k.test,parnum,nmc]);
if(parnum==5) return(par+1); # this step converts d to r
return(par);
}



Loading

0 comments on commit 1c6a345

Please sign in to comment.