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

Commit 33c9b0f

Browse files
authored
Merge pull request #55 from jeswheel/master
panelPomp v1.3.0
2 parents 2a4b147 + 32b6daf commit 33c9b0f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+4656
-280
lines changed

.Rbuildignore

+1
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@ hub_cov\.R
4545
covr.html
4646
covr.rds
4747
website
48+
^vignettes/articles$

.github/workflows/render-website.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ on:
77
paths:
88
- '.github/workflows/render-website.yml'
99
- 'DESCRIPTION'
10+
- 'inst/NEWS'
11+
- 'inst/NEWS.Rd'
1012
- 'R/**'
1113
- 'vignettes/**'
1214
- 'website/**' # Make sure to include the path to your website files
@@ -87,7 +89,10 @@ jobs:
8789
8890
- name: Copy Vignettes and Other Files
8991
run: |
90-
cp -r vignettes website/
92+
mkdir -p website/vignettes
93+
cp vignettes/getting-started.Rmd website/vignettes/.
94+
cp vignettes/articles/package_tutorial/tutorial.pdf website/vignettes/.
95+
# cp -r vignettes website/
9196
Rscript --vanilla website/rmd2qmd.R website/vignettes/getting-started
9297
rm website/vignettes/getting-started.Rmd
9398
tree website

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,10 @@ website/html
3535
website/help
3636
inst/doc
3737
website/vignettes/*
38+
vignettes/articles/package_tutorial/tutorial.aux
39+
vignettes/articles/package_tutorial/tutorial.bbl
40+
vignettes/articles/package_tutorial/tutorial-concordance.tex
41+
vignettes/articles/package_tutorial/tutorial.log
42+
vignettes/articles/package_tutorial/tutorial.tex
43+
vignettes/articles/package_tutorial/tutorial.synctex.gz
44+
!vignettes/articles/package_tutorial/tutorial.pdf

DESCRIPTION

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: panelPomp
22
Type: Package
33
Title: Inference for Panel Partially Observed Markov Processes
4-
Version: 1.2.0
4+
Version: 1.3.0
55
Date: 2023-05-22
66
Authors@R: c(person(given="Carles",family="Breto",role=c("aut","cre"),email="carles.breto@uv.es",comment=c(ORCID="0000-0003-4695-4902")),
77
person(given=c("Edward","L."),family="Ionides",role="aut",comment=c(ORCID="0000-0002-4190-0174")),
@@ -15,7 +15,7 @@ Depends:
1515
Imports:
1616
lifecycle,
1717
methods
18-
RoxygenNote: 7.3.1
18+
RoxygenNote: 7.3.2
1919
Encoding: UTF-8
2020
Collate:
2121
'panelPomp-package.R'
@@ -42,5 +42,5 @@ Roxygen: list(markdown = TRUE)
4242
Suggests:
4343
knitr,
4444
rmarkdown,
45-
bookdown
45+
bookdown
4646
VignetteBuilder: knitr

NAMESPACE

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@
33
export("shared<-")
44
export("specific<-")
55
export(contacts)
6-
export(fromVectorPparams)
76
export(get_col)
87
export(get_row)
9-
export(pParams)
108
export(panelGompertz)
119
export(panelGompertzLikelihood)
1210
export(panelPomp)
1311
export(panelRandomWalk)
1412
export(panel_logmeanexp)
15-
export(pparams)
1613
export(runif_panel_design)
1714
export(shared)
1815
export(specific)
1916
export(toMatrixPparams)
20-
export(toVectorPparams)
17+
export(toParamList)
18+
export(toParamVec)
2119
export(unitLogLik)
2220
export(unit_objects)
2321
export(unitlogLik)
@@ -37,7 +35,6 @@ exportMethods(mif2)
3735
exportMethods(names)
3836
exportMethods(pfilter)
3937
exportMethods(plot)
40-
exportMethods(pparams)
4138
exportMethods(print)
4239
exportMethods(shared)
4340
exportMethods(show)

R/generics.R

-23
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,5 @@
11
## generic functions
22

3-
#' @title Extract parameters (coefficients) of a panel model
4-
#' @description \code{pparams()} is a generic function that extracts parameter
5-
#' (coefficient) values from objects returned by panel modeling functions. While
6-
#' the named \code{numeric} vector format is useful and possible via S4 methods
7-
#' for \code{coef()}, alternative formats capturing the panel structure can be
8-
#' implemented via \code{pparams()}.
9-
#' @param object an object for which extraction of panel model parameter
10-
#' (coefficient) values is meaningful.
11-
#' @param ... additional arguments.
12-
#' @details This is a generic function: methods can be defined for it.
13-
#' @return Parameter (coefficient) values extracted from the panel model
14-
#' \code{object}.
15-
#'
16-
#' \pparamsReturn
17-
#' @example examples/prw.R
18-
#' @example examples/pparams.R
19-
#' @keywords internal
20-
#' @seealso \link{panelPomp_methods}
21-
#' @author Carles \Breto
22-
#' @export
23-
setGeneric(name = "pparams",
24-
def = function(object, ...) standardGeneric("pparams"))
25-
263
#' @title Extract units of a panel model
274
#' @description \code{unit_objects()} is a generic function that extracts a list
285
#' of objects corresponding to units of panel objects returned by panel modeling

R/mif2.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ mif2.internal <- function (object, Nmif, start, Np, rw.sd, cooling.type,
206206
# Extract loglikelihoods
207207
unit.logliks <- sapply(X = output, FUN = logLik)
208208
ploglik <- sum(unit.logliks)
209-
# create pParams slot from last mif iteration values in pconv.rec
209+
# create parameter list from last mif iteration values in pconv.rec
210210
pParams <- list()
211211
pParams$shared <- pconv.rec[nrow(pconv.rec), -1L]
212212
# Here, we want to drop the iteration dimension but, if there was only one
@@ -262,7 +262,7 @@ setMethod(
262262
"mif2",
263263
signature=signature(data="panelPomp"),
264264
definition = function (data, Nmif = 1, shared.start, specific.start, start,
265-
Np, rw.sd, cooling.type = c("hyperbolic", "geometric"),
265+
Np, rw.sd, cooling.type = c("geometric", "hyperbolic"),
266266
cooling.fraction.50, block = FALSE,
267267
verbose = getOption("verbose"), ...) {
268268
object <- data
@@ -275,7 +275,7 @@ setMethod(
275275
if (missing(start)) {
276276
start <- list(shared=object@shared,specific=object@specific)
277277
} else {
278-
if (is.numeric(start)) start <- pParams(start)
278+
if (is.numeric(start)) start <- toParamList(start)
279279
}
280280
if (missing(shared.start)) shared.start <- start$shared
281281
if (missing(specific.start)) specific.start <- start$specific
@@ -332,7 +332,7 @@ setMethod(
332332
if (missing(start)) {
333333
start <- list(shared=object@shared,specific=object@specific)
334334
} else {
335-
if (is.numeric(start)) start <- pParams(start)
335+
if (is.numeric(start)) start <- toParamList(start)
336336
}
337337
if (missing(shared.start)) shared.start <- start$shared
338338
if (missing(specific.start)) specific.start <- start$specific

R/panelPomp.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ panelPomp <- function (object, shared, specific, params) {
179179
call.=FALSE)
180180
} else {
181181
if (is.numeric(params) && !is.null(names(params))) {
182-
params <- pParams(params)
182+
params <- toParamList(params)
183183
} else {
184184
stop(wQuotes(ep,"''params'' must be a named numeric vector"),call.=FALSE)
185185
}

R/panelPomp_methods.R

+20-26
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ NULL
2020
#' \item{coef<-}{Assign coefficients to \code{panelPomp} objects.}
2121
#' \item{length}{Count the number of units in \code{panelPomp} objects.}
2222
#' \item{names}{Get the unit names of \code{panelPomp} objects.}
23-
#' \item{pparams}{Extracts coefficients from \code{panelPomp} objects in list form.}
24-
#' \item{pParams}{Converts panel coefficients from vector form to list form.}
23+
#' \item{toParamList}{Converts panel coefficients from vector form to list form.}
2524
#' \item{window}{Subset \code{panelPomp} objects by changing start time and
2625
#' end time.}
2726
#' \item{\code{[]}}{Take a subset of units.}
@@ -42,15 +41,21 @@ NULL
4241
setMethod(
4342
"coef",
4443
signature=signature(object="panelPomp"),
45-
definition = function (object) {
44+
definition = function (object, format = c("vector", 'list')) {
45+
out_type <- match.arg(format)
4646
pmat <- object@specific
47-
c(
48-
object@shared,
49-
setNames(
50-
as.numeric(pmat),
51-
outer(rownames(pmat),colnames(pmat),sprintf,fmt="%s[%s]")
47+
48+
if (out_type == 'vector') {
49+
c(
50+
object@shared,
51+
setNames(
52+
as.numeric(pmat),
53+
outer(rownames(pmat),colnames(pmat),sprintf,fmt="%s[%s]")
54+
)
5255
)
53-
)
56+
} else if (out_type == 'list') {
57+
list(shared=object@shared,specific=object@specific)
58+
}
5459
}
5560
)
5661

@@ -114,28 +119,17 @@ setMethod(
114119
definition = function (x) names(x@unit_objects)
115120
)
116121

117-
#' @rdname panelPomp_methods
118-
#' @return \pparamsReturn
119-
# \pparamsReturn is resused in documentation of generic function introduced by the panelPomp package
120-
#' @example examples/pparams.R
121-
#' @export
122-
setMethod(
123-
"pparams",
124-
signature=signature(object="panelPomp"),
125-
definition = function (object)
126-
list(shared=object@shared,specific=object@specific)
127-
)
128-
129122
#' @rdname panelPomp_methods
130123
#' @return
131-
#' \code{pParams()} returns a \code{list} with the model parameters in list form.
124+
#' \code{toParamList()} returns a \code{list} with the model parameters in list form.
132125
#' @examples
133126
#' # convert vector-form parameters to list-form parameters
134-
#' pParams(coef(prw))
127+
#' toParamList(coef(prw))
135128
#' @export
136-
pParams <- function (value) {
129+
toParamList <- function (value) {
137130

138-
ep <- wQuotes("in ''pParams'': ")
131+
ep <- wQuotes("in ''toParamList'': ")
132+
if (is.list(value)) stop(ep, 'input is already a list.', call. = FALSE)
139133
if (!is.vector(value)) stop(ep, "input must be a vector.", call. = FALSE)
140134

141135
nn <- grep("^.+\\[.+?\\]$", names(value), perl = TRUE, value = TRUE)
@@ -183,7 +177,7 @@ setMethod(
183177
cat("panel of",length(object),ifelse(length(object)>1,"units","unit"),"\n")
184178
if (length(coef(object))>0) {
185179
cat("parameter(s):\n")
186-
print(pParams(coef(object)))
180+
print(coef(object, format = 'list'))
187181
} else {
188182
cat("parameter(s) unspecified\n");
189183
}

R/params.R

+21-73
Original file line numberDiff line numberDiff line change
@@ -3,89 +3,37 @@
33
#' @include panelPomp_methods.R
44
NULL
55

6-
#' @title Convert to and from a \code{panelPomp} object \code{pParams} slot format and a one-row \code{data.frame}
6+
#' @title Manipulating \code{panelPomp} object parameter formats
77
#' @description These facilitate keeping a record of evaluated log likelihoods.
8-
#' @param vec_pars A one-row \code{data.frame} with format matching that of the
9-
#' output of \link{toVectorPparams}.
10-
#' @param pParams A list with the format of the \code{pParams} slot of \code{panelPomp} objects.
8+
#' @param pParams A list with both shared (vector) and unit-specific (matrix) parameters.
119
#' @name params
1210
NULL
1311

1412
#' @rdname params
1513
#' @author Carles \Breto
1614
#' @return
17-
#' \code{toVectorPparams()} returns an object of class \code{data.frame}.
15+
#' \code{toParamVec()} returns model parameters in vector form. This function
16+
#' is the inverse of \link{toParamList}
1817
#' @examples
1918
#' prw <- panelRandomWalk()
20-
#' toVectorPparams(pparams(prw))
19+
#' toParamVec(coef(prw, format = 'list'))
2120
#' @export
22-
toVectorPparams <- function(pParams) {
23-
# rbind replicated shared parameters with matrix of specific parameters
24-
mat_pars <- rbind(
25-
matrix(
26-
rep(pParams$shared,
27-
times=ncol(pParams$specific)),
28-
ncol = ncol(pParams$specific),
29-
dimnames = list(names(pParams$shared), NULL)
30-
),
31-
pParams$specific
32-
)
33-
# vectorize the matrix
34-
vec_pars <- setNames(
35-
as.vector(mat_pars),
36-
nm=paste0(rep(colnames(mat_pars), each = nrow(mat_pars)),
37-
rownames(mat_pars)))
38-
# Append info about ...
39-
#... nature of parameters (shared and specific), and ...
40-
par_typ <- setNames(
41-
c(rep("shared",times=length(pParams$shared)),
42-
rep("specific",times=nrow(pParams$specific))),
43-
nm=c(names(pParams$shared),rownames(pParams$specific)))
44-
# ... unit names
45-
u_nms <- setNames(
46-
rep("unit_name",ncol(mat_pars)),
47-
nm=colnames(pParams$specific)
48-
)
49-
# return
50-
merge(data.frame(t(par_typ),stringsAsFactors=FALSE),
51-
y=merge(data.frame(t(u_nms),stringsAsFactors=FALSE),
52-
y=data.frame(t(vec_pars))))
53-
}
21+
toParamVec <- function(pParams) {
5422

55-
#' @rdname params
56-
# @author Carles \Breto
57-
#' @return
58-
#' \code{fromVectorPparams()} returns an object of class \code{list} with the
59-
#' model parameters in list form.
60-
#' @examples
61-
#' fromVectorPparams(toVectorPparams(pparams(prw)))
62-
#' @export
63-
fromVectorPparams <- function(vec_pars) {
64-
# Extract unit, shared, and specific names
65-
sh_nms <- names(vec_pars[,!is.na(vec_pars=="shared")&vec_pars=="shared",drop=FALSE])
66-
sp_nms <- names(vec_pars[,!is.na(vec_pars=="specific")&vec_pars=="specific",drop=FALSE])
67-
u_nms <- names(vec_pars)[vec_pars=="unit_name"]
68-
# shared
69-
sh_pars <- if(length(sh_nms)>0) {
70-
sh_pars <- setNames(as.numeric(vec_pars[,paste0(u_nms[1],sh_nms)]),nm=sh_nms)
71-
} else {
72-
numeric(0)
73-
}
74-
# specific
75-
if(length(sp_nms)>0) {
76-
mat_sps <- NULL
77-
for (i.u in seq_len(length(u_nms))) {
78-
mat_sps <- cbind(
79-
mat_sps,
80-
as.numeric(vec_pars[, paste0(u_nms[i.u],sp_nms)])
81-
)
82-
}
83-
dimnames(mat_sps) <- list(sp_nms,u_nms)
84-
} else {
85-
mat_sps <- array(numeric(),dim=c(0,length(u_nms)),dimnames=list(NULL,u_nms))
86-
}
87-
# return
88-
list(shared=sh_pars,specific=mat_sps)
23+
ep <- wQuotes("in ''toParamVec'': ")
24+
if (!is.list(pParams)) stop(ep, 'input must be a list.', call. = FALSE)
25+
if (is.null(pParams$shared) && is.null(pParams$specific)) stop(ep, 'input must have shared or specific components.', call. = FALSE)
26+
27+
# Create a new list, removing unused components.
28+
value <- list(shared=pParams$shared, specific = pParams$specific)
29+
30+
c(
31+
value$shared,
32+
setNames(
33+
as.numeric(value$specific),
34+
outer(rownames(value$specific),colnames(value$specific),sprintf,fmt="%s[%s]")
35+
)
36+
)
8937
}
9038

9139
## Go to list-form pparams from matrix specification
@@ -125,7 +73,7 @@ toListPparams <- function(
12573
#' \code{toMatrixPparams()} returns an object of class \code{matrix} with the
12674
#' model parameters in matrix form.
12775
#' @examples
128-
#' toMatrixPparams(pparams(prw))
76+
#' toMatrixPparams(coef(prw, format = 'list'))
12977
#' @export
13078
toMatrixPparams <- function(listPparams) {
13179
common.params <- listPparams[[which(sapply(listPparams, is.vector))]]

R/pfilter.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ setMethod(
9292
object <- data # the argument name 'data' is fixed by pomp's generic
9393
ep <- wQuotes("in ''pfilter'': ")
9494
## check for params format
95-
if (!missing(params) && is.numeric(params)) params <- pParams(params)
95+
if (!missing(params) && is.numeric(params)) params <- toParamList(params)
9696

9797
if (!missing(shared) && !missing(specific) && !missing(params))
9898
stop(ep,wQuotes("specify either ''params'' only, ''params'' and ''shared'' ,",

0 commit comments

Comments
 (0)