Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #52 from jeswheel/master
Browse files Browse the repository at this point in the history
panelPomp V1.2.0
  • Loading branch information
jeswheel authored Jun 24, 2024
2 parents 74c7825 + e44330a commit 2a4b147
Show file tree
Hide file tree
Showing 94 changed files with 2,977 additions and 314 deletions.
1 change: 0 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ man/roxygen
LICENSE\.md$
README\.md$
CRAN\.md$
TODO\.md$
^\.gitignore$
\.github
^\.travis\.yml$
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/r-cmd-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ jobs:
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-20.04, r: '4.1.0'}
- {os: macOS-11, r: 'release'}
- {os: macOS-latest, r: 'release'}
- {os: windows-latest, r: 'release'}

Expand Down Expand Up @@ -56,7 +55,7 @@ jobs:
_R_CHECK_CODETOOLS_PROFILE_: "suppressLocalUnused=FALSE,suppressPartialMatchArgs=FALSE,suppressParamUnused=TRUE,suppressUndefined=FALSE"

steps:
- uses: actions/checkout@v3.1.0
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
Expand All @@ -75,10 +74,10 @@ jobs:
any::subplex
any::nloptr
kingaa/pomp
- uses: r-lib/actions/check-r-package@v2

- uses: actions/upload-artifact@v3.1.1
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.config.os }}-${{ matrix.config.r }}-results
path: check
8 changes: 8 additions & 0 deletions .github/workflows/render-website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ jobs:
any::devtools
any::bib2df
any::tidyverse
any::bookdown
- name: Install package from source
run: |
Expand All @@ -84,6 +85,13 @@ jobs:
R CMD Rdconv -t html inst/NEWS.Rd -o website/NEWS.html
ed -s website/html/00Index.html < website/changes.ed
- name: Copy Vignettes and Other Files
run: |
cp -r vignettes website/
Rscript --vanilla website/rmd2qmd.R website/vignettes/getting-started
rm website/vignettes/getting-started.Rmd
tree website
- name: Render and Publish
uses: quarto-dev/quarto-actions/publish@v2
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ covr.rds
website/docs
website/html
website/help
inst/doc
website/vignettes/*
14 changes: 11 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: panelPomp
Type: Package
Title: Inference for Panel Partially Observed Markov Processes
Version: 1.1.0.2
Version: 1.2.0
Date: 2023-05-22
Authors@R: c(person(given="Carles",family="Breto",role=c("aut","cre"),email="carles.breto@uv.es",comment=c(ORCID="0000-0003-4695-4902")),
person(given=c("Edward","L."),family="Ionides",role="aut",comment=c(ORCID="0000-0002-4190-0174")),
Expand All @@ -13,11 +13,12 @@ Depends:
R(>= 4.1.0),
pomp(>= 4.5.2)
Imports:
lifecycle,
methods
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Encoding: UTF-8
Collate:
'package.R'
'panelPomp-package.R'
'aaa.R'
'contacts.R'
'generics.R'
Expand All @@ -34,5 +35,12 @@ Collate:
'panelGompertz.R'
'panelGompertzLikelihood.R'
'panelRandomWalk.R'
'panel_designs.R'
'plot.R'
'simulate.R'
Roxygen: list(markdown = TRUE)
Suggests:
knitr,
rmarkdown,
bookdown
VignetteBuilder: knitr
15 changes: 13 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Generated by roxygen2: do not edit by hand

export("shared<-")
export("specific<-")
export(contacts)
export(fromVectorPparams)
export(get_col)
Expand All @@ -11,17 +13,23 @@ export(panelPomp)
export(panelRandomWalk)
export(panel_logmeanexp)
export(pparams)
export(runif_panel_design)
export(shared)
export(specific)
export(toMatrixPparams)
export(toVectorPparams)
export(unitLogLik)
export(unit_objects)
export(unitlogLik)
export(unitobjects)
export(wQuotes)
exportClasses(mif2d.ppomp)
exportClasses(panelPomp)
exportClasses(pfilterd.ppomp)
exportMethods("[")
exportMethods("[[")
exportMethods("coef<-")
exportMethods("shared<-")
exportMethods("specific<-")
exportMethods(coef)
exportMethods(length)
exportMethods(logLik)
Expand All @@ -31,11 +39,14 @@ exportMethods(pfilter)
exportMethods(plot)
exportMethods(pparams)
exportMethods(print)
exportMethods(shared)
exportMethods(show)
exportMethods(simulate)
exportMethods(specific)
exportMethods(traces)
exportMethods(unitLogLik)
exportMethods(unit_objects)
exportMethods(unitlogLik)
exportMethods(unitobjects)
exportMethods(window)
import(methods)
import(pomp)
Expand Down
2 changes: 1 addition & 1 deletion R/aaa.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @include package.R
#' @include panelPomp-package.R
NULL

#' @title Interpret shortcuts for \code{sQuote()}s and \code{dQuote()}s in
Expand Down
130 changes: 123 additions & 7 deletions R/generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ setGeneric(name = "pparams",
def = function(object, ...) standardGeneric("pparams"))

#' @title Extract units of a panel model
#' @description \code{unitobjects()} is a generic function that extracts a list
#' @description \code{unit_objects()} is a generic function that extracts a list
#' of objects corresponding to units of panel objects returned by panel modeling
#' functions.
#' @param object an object for which extraction of panel units is meaningful.
Expand All @@ -39,26 +39,142 @@ setGeneric(name = "pparams",
#' @seealso \link{panelPomp_methods}
#' @author Carles \Breto
#' @export
setGeneric(name = "unitobjects",
def = function(object, ...) standardGeneric("unitobjects"))
setGeneric(name = "unit_objects",
def = function(object, ...) standardGeneric("unit_objects"))

#' @name unitLogLik
#' @title Extract log likelihood of units of panel models
#' @description \code{unitlogLik()} is a generic function that extracts the log
#' @description \code{unitLogLik()} is a generic function that extracts the log
#' likelihood for each unit of panel objects returned by panel modeling functions.
#' While the \code{numeric} value with the log likelihood for the entire panel
#' is useful and possible via S4 methods \code{logLik()}, the contributions to it
#' by panel units can be implemented via \code{unitlogLik()}.
#' by panel units can be implemented via \code{unitLogLik()}.
#' @param object an object for which log likelihood values for units can be extracted.
#' @param ... additional arguments.
#' @details This is a generic function: methods can be defined for it.
#' @return Log likelihood extracted for each unit of the panel model \code{object}.
#'
#' \unitlogLikReturn
#' \unitLogLikReturn
#' @example examples/pfrw.R
#' @example examples/unitlogLik.R
#' @example examples/unitLogLik.R
#' @keywords internal
#' @seealso \link{pfilter}
#' @author Carles \Breto
#' @export
setGeneric(name = "unitLogLik",
def = function(object, ...) standardGeneric("unitLogLik"))


#' @rdname unitlogLik-deprecated
#' @name unitlogLik-deprecated
#' @title (Deprecated) Extract log likelihood of units of panel models
#' @description
#' `r lifecycle::badge("deprecated")`
#'
#' In future versions, this generic is being replaced with [unitLogLik()].
#'
#' \code{unitlogLik()} is a generic function that extracts the log
#' likelihood for each unit of panel objects returned by panel modeling functions.
#' While the \code{numeric} value with the log likelihood for the entire panel
#' is useful and possible via S4 methods \code{logLik()}, the contributions to it
#' by panel units can be implemented via \code{unitlogLik()}.
#' @param object an object for which log likelihood values for units can be extracted.
#' @param ... additional arguments.
#' @details This is a generic function: methods can be defined for it.
#' @return Log likelihood extracted for each unit of the panel model \code{object}.
#'
#' When given objects of class \code{pfilterd.ppomp}, \code{unitloglik()} returns a \code{numeric} vector.
#' @examples
#' # filter, which generates log likelihoods
#' pfrw <- pfilter(panelRandomWalk(),Np=10)
#'
#' # extract log likelihood for each panel unit
#' unitlogLik(pfrw)
#'
#' @keywords internal
#' @seealso \link{pfilter}
#' @author Carles \Breto
#' @aliases unitlogLik
#' @export
setGeneric(name = "unitlogLik",
def = function(object, ...) standardGeneric("unitlogLik"))

#' Extract unit-specific parameters from a panelPomp object
#'
#' This function is used to extract the unit-specific parameters from a
#' panel pomp object.
#'
#' @param object an object that contains unit-specific parameters
#' @param format character representing how the parameters should be returned
#' @param ... additional arguments.
#'
#' @return a matrix or vector containing the unit-specific parameters
#'
#' @example examples/prw.R
#' @example examples/get_specific.R
#' @keywords internal
#' @seealso \link{panelPomp_methods}
#' @author Jesse Wheeler
#' @export
setGeneric(name = "specific",
def = function(object, ..., format = c('matrix', 'vector')) standardGeneric('specific')
)

#' Set unit-specific parameters of a panelPomp object
#'
#' This function is used to set the unit-specific parameters of a
#' panel pomp object.
#'
#' @param object an object that contains unit-specific parameters.
#' @param value a numeric matrix with column names matching the names of the
#' `unit_objects` slot, and row names matching the names of the unit-specific
#' parameters. Alternatively, this can be a named vector following the naming
#' convention `<parameter>[<unit_name>]`.
#'
#' @example examples/set_specific.R
#' @keywords internal
#' @seealso \link{panelPomp_methods}
#' @author Jesse Wheeler
#' @export
setGeneric(name = "specific<-",
def = function(object, value) standardGeneric('specific<-')
)

#' Extract shared parameters from a panelPomp object
#'
#' This function is used to extract the shared parameters from a panelPomp
#' object.
#'
#' @param object an object that contains shared parameters.
#' @param ... additional arguments.
#'
#' @return vector containing the shared parameters
#'
#' @example examples/prw.R
#' @example examples/get_shared.R
#' @keywords internal
#' @seealso \link{panelPomp_methods}
#' @author Jesse Wheeler
#' @export
setGeneric(name = "shared",
def = function(object, ...) standardGeneric('shared')
)

#' Set shared parameters of a panelPomp object
#'
#' This function is used to set the shared parameters of a panel pomp object.
#'
#' @param object an object that contains shared parameters.
#' @param value a named numeric vector containing the desired values of the
#' shared parameter vector.
#'
#' @example examples/prw.R
#' @example examples/set_shared.R
#' @keywords internal
#' @seealso \link{panelPomp_methods}
#' @author Jesse Wheeler
#' @export
setGeneric(name = "shared<-",
def = function(object, value) standardGeneric('shared<-')
)

14 changes: 7 additions & 7 deletions R/mif2.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ NULL
#' @param specific.start matrix with row parameter names and column unit names;
#' the starting guess of the specific parameters.
#' @param start A named numeric vector of parameters at which to start the IF2 procedure.
#' @param block A logical variable determining whther to carry out block
#' @param block A logical variable determining whether to carry out block
#' resampling of unit-specific parameters.
#' @param rw.sd An unevaluated expression of the form \code{quote(rw.sd())} to
#' be used for all panel units. If a \code{list} of such expressions of the
Expand Down Expand Up @@ -85,10 +85,10 @@ mif2.internal <- function (object, Nmif, start, Np, rw.sd, cooling.type,
shnames <- names(start$shared)
spnames <- rownames(start$specific)

if (!setequal(names(object@unit.objects),colnames(start$specific)))
if (!setequal(names(object@unit_objects),colnames(start$specific)))
stop(ep,wQuotes("specific parameter column-names must match the names of the units"),
call.=FALSE)
start$specific <- start$specific[,names(object@unit.objects),drop=FALSE]
start$specific <- start$specific[,names(object@unit_objects),drop=FALSE]

########################################################
# Initialize objects
Expand All @@ -110,7 +110,7 @@ mif2.internal <- function (object, Nmif, start, Np, rw.sd, cooling.type,
dimnames = list(
variable = spnames,
rep = NULL,
unit = names(unitobjects(object))
unit = names(unit_objects(object))
)
)
# Initialize pconv.rec and pconv.rec.array
Expand All @@ -131,14 +131,14 @@ mif2.internal <- function (object, Nmif, start, Np, rw.sd, cooling.type,
iteration = seq.int(.ndone, .ndone + Nmif),
variable = c('unitLoglik',
dimnames(start$specific)[[1]]),
unit = names(unitobjects(object))
unit = names(unit_objects(object))
)
)
pconv.rec.array[1L, -1L, ] <- pparamArray[, 1L,]
# Initialize output
output <- vector(mode="list",length=U)
# nameoutput
names(output) <- names(unitobjects(object))
names(output) <- names(unit_objects(object))

###########################################################
# LOOP OVER MIF ITERATIONS AND PANEL UNITS
Expand Down Expand Up @@ -227,7 +227,7 @@ mif2.internal <- function (object, Nmif, start, Np, rw.sd, cooling.type,
new(
Class = "mif2d.ppomp",
# panelPomp
unit.objects = output,
unit_objects = output,
shared = pParams$shared,
specific = pParams$specific,
# pfilterd.ppomp
Expand Down
Loading

0 comments on commit 2a4b147

Please sign in to comment.