### Load C code

useDynLib(surveillance)


###############
### IMPORTS ###
###############

### Import all packages listed as Depends
### (for utils and xtable: only selected methods are imported)

import(methods, grDevices, graphics, stats)
import(Rcpp)
## although Rcpp is only used on C-level we need to "ensure that Rcpp is loaded
## so any dynamic linking to its code can be resolved.  (There may be none, but
## there could be, now or in future.)" (B. Ripley, 2013-09-08)

## sp classes & utilities (bbox, coordinates, dimensions, overlay, plot, ...)
## (we "Depend" on package sp since it defines essential data classes & methods)
import(sp)


### required generics for own methods (that's why we "Depend" on these packages)

## importFrom(stats, coef, vcov, logLik, nobs, residuals, confint, AIC, extractAIC,
##                   profile, simulate, update, terms, add1, drop1, predict)
importFrom(utils, head, tail, toLatex)
importFrom(xtable, xtable) # if we wouldn't "Depend" on xtable, our
                           # xtable-methods would not be useable except if the
                           # user attaches the xtable package himself


### required functions from utils and stats

## importFrom(stats, pnorm, cov2cor, ks.test, formula, rnorm, runif, step, dist,
##                   update.formula, terms.formula, rpois, rnbinom, setNames,
##                   na.omit, as.formula, pnbinom, qnbinom, qnorm, sd, glm, optim,
##                   poisson, ppois, qpois, predict.glm, summary.glm, quasipoisson,
##                   glm.fit) ## and many more...
importFrom(utils, packageVersion, modifyList, capture.output, read.table,
                  setTxtProgressBar, txtProgressBar, sessionInfo, head.matrix,
                  str, flush.console, write.table)


### sampling from mv.Gausian for OSAIC weights (twinSIR) and iafplot (twinstim)

importFrom(MASS, mvrnorm)


### disProg-specific

importFrom(MASS, glm.nb)   # for algo.glrnb
##importFrom(msm, msm, hmmPois, viterbi.msm)   # for algo.hmm()
##importFrom(spc, xcusum.arl, xcusum.crit)     # for find.kh()
## (packages msm and spc are now "suggested", not imported)


### hhh4-specific

importFrom(MASS, ginv)
importFrom(Matrix, Matrix)
importClassesFrom(Matrix, ddiMatrix)
importMethodsFrom(Matrix, coerce, diag, forceSymmetric, solve)
## sparse matrix methods provide a significant speed-up in marFisher


### twinSIR-specific

# for use in computing OSAIC weights by simulation
#importFrom(quadprog, solve.QP)   # moved to "Suggests"


### twinstim-specific

importFrom(spatstat, area.owin, as.im.function, coords.ppp, diameter,
                     diameter.owin, disc, distppl, inside.owin, intersect.owin,
                     is.polygonal, marks, runifpoint, shift.owin)

importFrom(polyCub, polyCub, polyCub.SV, polyCub.midpoint, xylist)
importMethodsFrom(polyCub, coerce)

importFrom(MASS, kde2d)



###############
### EXPORTS ###
###############


### general exports

export(surveillance.options, reset.surveillance.options)
export(animate)          # new S3-generic
export(R0)               # new S3-generic
export(intensityplot)    # new S3-generic
export(formatPval)       # yapf -- yet another p-value formatter
export(anscombe.residuals)
export(magic.dim, primeFactors, bestCombination)   # similar to n2mfrow
export(isoWeekYear)
export(refvalIdxByDate)
export(ks.plot.unif)
export(checkResidualProcess)            # for twinstim and twinSIR

# spatial utilities
export(discpoly)
#export(runifdisc)           # CAVE: spatstat has similar function of same name
export(unionSpatialPolygons)
export(inside.gpc.poly)
S3method(scale, gpc.poly)   # redefined method for gpc.poly in spatial_stuff.R
S3method(diameter, gpc.poly)
export(nbOrder)
export(poly2adjmat)
export(polyAtBorder)

# randomly break tied event times or coordinates
export(untie)                           # new S3-generic
#export(untie.default, untie.matrix, untie.epidataCS)
S3method(untie, default)
S3method(untie, matrix)
S3method(untie, epidataCS)

# intersection of a polygonal and a circular domain
export(intersectPolyCircle)
S3method(intersectPolyCircle, owin)
S3method(intersectPolyCircle, SpatialPolygons)
S3method(intersectPolyCircle, gpc.poly)

# little helper: multiplicity of points
export(multiplicity)                    # new S3-generic
S3method(multiplicity, default)
S3method(multiplicity, Spatial)

# Spatio-temporal cluster detection
export(stcd)


### sts(BP)-specific

exportClasses(sts, stsBP)

# generics for sts class defined in sts.R
exportMethods("[", plot)
exportMethods(nrow, ncol, dim, colnames, epochInYear, year)
exportMethods(aggregate)
exportMethods(as.data.frame)

# methods for accessing/replacing slots of an sts object (as defined in AllGeneric.R)
exportMethods(epoch,observed,alarms,upperbound,population,control,multinomialTS,neighbourhood)
exportMethods("epoch<-","observed<-","alarms<-","upperbound<-","population<-","control<-","multinomialTS<-","neighbourhood<-")

export(linelist2sts)

export(wrap.algo, farrington, bayes, rki, cusum, glrpois, glrnb, outbreakP) # rogerson, hmm
export(earsC)
export(farringtonFlexible)
export(categoricalCUSUM, pairedbinCUSUM, pairedbinCUSUM.runlength)
export(nowcast, backprojNP)
## auxiliary functions for farringtonFlexible:
## export(algo.farrington.data.glm, algo.farrington.fitGLM.flexible,
##        algo.farrington.glm, algo.farrington.referencetimepoints,
##        algo.farrington.threshold.farrington, algo.farrington.threshold.noufaily)


### disProg-specific

export(create.disProg, readData, toFileDisProg)
S3method(print, disProg)
S3method(plot, disProg)
S3method(plot, disProg.one)
S3method(aggregate, disProg)

export(sim.pointSource, sim.seasonalNoise)
export(LRCUSUM.runlength, arlCusum, find.kh, findH, hValues, findK)
export(compMatrix.writeTable, correct53to52, enlargeData)
export(makePlot)
export(estimateGLRNbHook)
export(algo.compare, algo.quality, algo.summary)

## outbreak detection algorithms (old disProg implementations)
export(algo.bayes, algo.bayes1, algo.bayes2, algo.bayes3, algo.bayesLatestTimepoint,
       algo.call,
       algo.cdc, algo.cdcLatestTimepoint,
       algo.cusum,
       algo.farrington,
       algo.glrnb, algo.glrpois,
       algo.hhh, algo.hhh.grid,
       algo.hmm,
       algo.outbreakP,
       algo.rki, algo.rki1, algo.rki2, algo.rki3, algo.rkiLatestTimepoint,
       algo.rogerson,
       algo.twins)

## auxiliary functions for algo.farrington (FIXME: why do we export these internals?)
export(algo.farrington.assign.weights,
       algo.farrington.fitGLM, algo.farrington.fitGLM.fast,
       algo.farrington.fitGLM.populationOffset, algo.farrington.threshold)


S3method(plot, atwins)
S3method(plot, survRes)
S3method(plot, survRes.one)
S3method(print, algoQV)
S3method(xtable, algoQV)

export(test, testSim)   # FIXME: do we really want that?
# if not, then we have to prefix all test() and testSim() calls in the
# corresponding examples in the Rd files by "surveillance:::"


### conversion between old disProg and new sts classes

export(disProg2sts)
export(sts2disProg)


### twinSIR-specific

export(cox)
export(as.epidata)
S3method(as.epidata, default)
export(as.epidata.default)              # for convenience
export(intersperse)
export(twinSIR)
export(stateplot)
export(simEpidata)

S3method("[", epidata)
S3method(print, epidata)
S3method(summary, epidata)
S3method(print, summary.epidata)
S3method(plot, epidata)
S3method(animate, epidata)
S3method(plot, summary.epidata)
S3method(animate, summary.epidata)

S3method(print, twinSIR)
S3method(summary, twinSIR)
S3method(print, summary.twinSIR)
S3method(plot, twinSIR)
S3method(intensityplot, twinSIR)
export(intensityplot.twinSIR)           # for convenience
S3method(profile, twinSIR)
S3method(vcov, twinSIR)
S3method(logLik, twinSIR)
S3method(AIC, twinSIR)
S3method(extractAIC, twinSIR)
S3method(simulate, twinSIR)
export(simulate.twinSIR)                # for convenience
S3method(residuals, twinSIR)

S3method(intensityplot, simEpidata)
export(intensityplot.simEpidata)        # for convenience


### twinstim-specific

export(as.epidataCS)
export(twinstim)
export(simEpidataCS)
export(siaf.constant, siaf.gaussian, siaf.lomax, qlomax, siaf.powerlaw, siaf.powerlawL)
export(tiaf.constant, tiaf.exponential)
export(epidataCS2sts)

S3method(nobs, epidataCS)
S3method("[", epidataCS)
S3method(update, epidataCS)
export(update.epidataCS)                # for convenience
S3method(head, epidataCS)
S3method(tail, epidataCS)
S3method(print, epidataCS)
S3method(subset, epidataCS)
S3method(summary, epidataCS)
S3method(print, summary.epidataCS)
S3method(animate, epidataCS)
export(animate.epidataCS)               # for convenience
export(marks)                           # as imported from spatstat
S3method(marks, epidataCS)
export(marks.epidataCS)            # for convenience since its a foreign generic
S3method(plot, epidataCS)
S3method(as.epidata, epidataCS)
export(as.epidata.epidataCS)            # for convenience

S3method(print, twinstim)
S3method(summary, twinstim)
export(summary.twinstim)                # for convenience
S3method(print, summary.twinstim)
S3method(toLatex, summary.twinstim)
S3method(xtable, summary.twinstim)
export(xtable.summary.twinstim)         # for xtable.twinstim
S3method(xtable, twinstim)
S3method(plot, twinstim)
export(iafplot)
export(intensity.twinstim)
S3method(intensityplot, twinstim)
export(intensityplot.twinstim)          # for convenience
S3method(profile, twinstim)
S3method(coef, summary.twinstim)
S3method(vcov, twinstim)
S3method(vcov, summary.twinstim)
S3method(logLik, twinstim)
S3method(extractAIC, twinstim)
S3method(nobs, twinstim)
S3method(simulate, twinstim)
export(simulate.twinstim)               # for convenience
S3method(R0, twinstim)
S3method(residuals, twinstim)
S3method(update, twinstim)
export(update.twinstim)                 # for convenience
S3method(terms, twinstim)

export(stepComponent)
S3method(terms, twinstim_stependemic)
S3method(terms, twinstim_stepepidemic)
S3method(update, twinstim_stependemic)
S3method(update, twinstim_stepepidemic)
S3method(add1, twinstim)
S3method(add1, twinstim_stependemic)
S3method(add1, twinstim_stepepidemic)
S3method(drop1, twinstim)
S3method(drop1, twinstim_stependemic)
S3method(drop1, twinstim_stepepidemic)

S3method(R0, simEpidataCS)
S3method(intensityplot, simEpidataCS)
export(intensityplot.simEpidataCS)      # for convenience
S3method(print, simEpidataCSlist)
S3method("[[", simEpidataCSlist)
S3method(plot, simEpidataCSlist)


### hhh-specific

export(algo.hhh)
export(algo.hhh.grid)
export(create.grid)

S3method(print, ah)
S3method(coef, ah)
S3method(predict, ah)
S3method(residuals, ah)
S3method(logLik, ah)

S3method(print, ahg)
S3method(coef, ahg)
S3method(predict, ahg)
S3method(residuals, ahg)
S3method(logLik, ahg)

export(hhh4) 
export(addSeason2formula)
export(zetaweights, powerlaw)
export(ranef)  # S3-generic
export(fixef)  # S3-generic

S3method(print, ah4)
S3method(print, summary.ah4)
S3method(summary, ah4)
S3method(coef, ah4)
S3method(logLik, ah4)
S3method(AIC, ah4)
S3method(fixef, ah4)
S3method(ranef, ah4)
S3method(confint, ah4)
S3method(predict, ah4)
S3method(plot, ah4)
S3method(update, ah4)

export(simHHH, simHHH.default)
S3method(simHHH, default)
S3method(simHHH, ah)
S3method(simulate, ah4)

export(oneStepAhead)
export(scores)

# functions not yet documented, but used in (dontrun) part of example(hhh4)
export(permutationTest)
export(pit)
