Skip to content

Commit

Permalink
improve 'melt' method; update tests for R version 3.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kingaa committed May 19, 2019
1 parent 1e6e3ec commit 1da69b2
Show file tree
Hide file tree
Showing 239 changed files with 349 additions and 278 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: pomp2
Type: Package
Title: Statistical Inference for Partially Observed Markov Processes
Version: 2.0.13.2
Date: 2019-04-18
Version: 2.0.14.1
Date: 2019-05-19
Authors@R: c(person(given=c("Aaron","A."),family="King",
role=c("aut","cre"),email="[email protected]"),
person(given=c("Edward","L."),family="Ionides",role=c("aut")),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ exportMethods(filter.traj)
exportMethods(flow)
exportMethods(forecast)
exportMethods(logLik)
exportMethods(melt)
exportMethods(mif2)
exportMethods(nlf_objfun)
exportMethods(obs)
Expand Down
45 changes: 31 additions & 14 deletions R/as_data_frame.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ setAs(
##' @method as.data.frame pomp
##' @rdname as_data_frame
##'
##' @param x the object to be coerced
##' @param \dots ignored
##' @inheritParams base::as.data.frame
##' @export
##'
as.data.frame.pomp <- function (x, ...) as(x,"data.frame")
Expand All @@ -70,12 +69,21 @@ setAs(
ess=eff.sample.size(from),
cond.loglik=cond.logLik(from)
)
if (length(pm)>0)
out <- cbind(out,pred.mean=t(pm))
if (length(pv)>0)
out <- cbind(out,pred.var=t(pv))
if (length(fm)>0)
out <- cbind(out,filter.mean=t(fm))
if (length(pm)>0) {
pm <- as.data.frame(t(pm))
names(pm) <- paste0("pred.mean.",names(pm))
out <- cbind(out,pm)
}
if (length(pv)>0) {
pv <- as.data.frame(t(pv))
names(pv) <- paste0("pred.var.",names(pv))
out <- cbind(out,pv)
}
if (length(fm)>0) {
fm <- as.data.frame(t(fm))
names(fm) <- paste0("filter.mean.",names(fm))
out <- cbind(out,fm)
}
out
}
)
Expand Down Expand Up @@ -127,12 +135,21 @@ setAs(
as(as(from,"pomp"),"data.frame"),
cond.loglik=cond.logLik(from)
)
if (length(pm)>0)
out <- cbind(out,pred.mean=t(pm))
if (length(fm)>0)
out <- cbind(out,filter.mean=t(fm))
if (length(fc)>0)
out <- cbind(out,forecast=t(fc))
if (length(pm)>0) {
pm <- as.data.frame(t(pm))
names(pm) <- paste0("pred.mean.",names(pm))
out <- cbind(out,pm)
}
if (length(fm)>0) {
fm <- as.data.frame(t(fm))
names(fm) <- paste0("filter.mean.",names(fm))
out <- cbind(out,fm)
}
if (length(fc)>0) {
fc <- as.data.frame(t(fc))
names(fc) <- paste0("forecast.",names(fc))
out <- cbind(out,fc)
}
out
}
)
Expand Down
14 changes: 14 additions & 0 deletions R/melt.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,17 @@
##' @docType import
##' @export
reshape2::melt

##' @name melt,pomp-method
##' @include melt.R
##' @rdname as_data_frame
##' @details A \sQuote{pomp} object can be melted into a data frame.
##' @inheritParams reshape2::melt
##' @export
setMethod(
"melt",
signature=signature(data="pomp"),
definition=function (data, ...) {
melt(as(data,"data.frame"),...)
}
)
19 changes: 16 additions & 3 deletions man/as_data_frame.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/euler.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ SEXP euler_model_simulator (SEXP func, SEXP xstart, SEXP tstart, SEXP times, SEX

break;

default:
default: // # nocov

errorcall(R_NilValue,"unrecognized 'mode' %d",mode); // # nocov

Expand Down Expand Up @@ -263,7 +263,7 @@ SEXP euler_model_simulator (SEXP func, SEXP xstart, SEXP tstart, SEXP times, SEX

break;

default:
default: // # nocov

errorcall(R_NilValue,"unrecognized 'mode' %d",mode); // # nocov

Expand Down
2 changes: 1 addition & 1 deletion src/partrans.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ SEXP do_partrans (SEXP object, SEXP params, SEXP dir, SEXP gnsi)

break;

default:
default: // #nocov

break; // #nocov

Expand Down
2 changes: 1 addition & 1 deletion src/pomp_fun.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ SEXP pomp_fun_handler (SEXP pfun, SEXP gnsi, pompfunmode *mode,
}
break;

default:
default: // #nocov
break; // #nocov
}

Expand Down
4 changes: 2 additions & 2 deletions src/ssa.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ SEXP SSA_simulator (SEXP func, SEXP xstart, SEXP tstart, SEXP times, SEXP params

switch (mode) {

case undef: default:
case undef: default: // #nocov

errorcall(R_NilValue,"unrecognized 'mode' %d",mode); // # nocov
errorcall(R_NilValue,"unrecognized 'mode' %d",mode); // #nocov

case native: case regNative:

Expand Down
8 changes: 4 additions & 4 deletions src/trajectory.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ SEXP iterate_map (SEXP object, SEXP times, SEXP t0, SEXP x0, SEXP params, SEXP g

break;

default:
default: // #nocov

break; // #nocov

Expand Down Expand Up @@ -238,7 +238,7 @@ SEXP pomp_desolve_setup (SEXP object, SEXP x0, SEXP params, SEXP gnsi) {

break;

default:
default: // #nocov

errorcall(R_NilValue,"in 'pomp_desolve_setup': unrecognized 'mode'"); // # nocov

Expand Down Expand Up @@ -272,7 +272,7 @@ void pomp_vf_eval (int *neq, double *t, double *y, double *ydot, double *yout, i

break;

default:
default: // #nocov

errorcall(R_NilValue,"in 'pomp_vf_eval': unrecognized 'mode'"); // # nocov

Expand Down Expand Up @@ -324,7 +324,7 @@ void pomp_desolve_takedown (void) {

break;

default:
default: // #nocov

errorcall(R_NilValue,"in 'pomp_desolve_takedown': unrecognized 'mode'"); // # nocov

Expand Down
Binary file modified tests/R_v_C-01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/R_v_C-02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 11 additions & 6 deletions tests/R_v_C.Rout
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

R version 3.5.2 (2018-12-20) -- "Eggshell Igloo"
Copyright (C) 2018 The R Foundation for Statistical Computing
R version 3.6.0 (2019-04-26) -- "Planting of a Tree"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
Expand All @@ -26,6 +26,11 @@ Welcome to pomp version 2!
For information on upgrading your pomp version < 2 code, see the
'pomp version 2 upgrade guide' at https://kingaa.github.io/pomp/.
> library(ggplot2)
Registered S3 methods overwritten by 'ggplot2':
method from
[.quosures rlang
c.quosures rlang
print.quosures rlang
>
> ## ----seed,echo=FALSE-----------------------------------------------------
> set.seed(56300069)
Expand Down Expand Up @@ -111,16 +116,16 @@ For information on upgrading your pomp version < 2 code, see the
> ## ----comparison----------------------------------------------------------
> system.time(simulate(gompertz,nsim=10000,format="arrays"))
user system elapsed
8.032 0.088 8.120
6.936 0.008 6.944
> system.time(simulate(Gompertz,nsim=10000,format="arrays"))
user system elapsed
0.380 0.008 0.387
0.279 0.008 0.287
> system.time(pfilter(gompertz,Np=1000))
user system elapsed
0.696 0.004 0.703
0.615 0.000 0.616
> system.time(pfilter(Gompertz,Np=1000))
user system elapsed
0.056 0.000 0.058
0.045 0.000 0.045
>
> dev.off()
null device
Expand Down
Binary file modified tests/abc-01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/abc-02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/abc-03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/abc-04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/abc-05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/abc-06.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/abc-07.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/abc.Rout.save
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

R version 3.5.2 (2018-12-20) -- "Eggshell Igloo"
Copyright (C) 2018 The R Foundation for Statistical Computing
R version 3.6.0 (2019-04-26) -- "Planting of a Tree"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
Expand Down
4 changes: 2 additions & 2 deletions tests/bake.Rout.save
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

R version 3.5.2 (2018-12-20) -- "Eggshell Igloo"
Copyright (C) 2018 The R Foundation for Statistical Computing
R version 3.6.0 (2019-04-26) -- "Planting of a Tree"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
Expand Down
8 changes: 5 additions & 3 deletions tests/basic_probes.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
options(digits=3)

library(pomp2)
library(dplyr)
library(tidyr)
library(ggplot2)
suppressPackageStartupMessages({
library(dplyr)
library(tidyr)
library(ggplot2)
})

set.seed(255066335)

Expand Down
23 changes: 7 additions & 16 deletions tests/basic_probes.Rout.save
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

R version 3.5.2 (2018-12-20) -- "Eggshell Igloo"
Copyright (C) 2018 The R Foundation for Statistical Computing
R version 3.6.0 (2019-04-26) -- "Planting of a Tree"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
Expand All @@ -23,20 +23,11 @@ Type 'q()' to quit R.
Welcome to pomp version 2!
For information on upgrading your pomp version < 2 code, see the
'pomp version 2 upgrade guide' at https://kingaa.github.io/pomp/.
> library(dplyr)

Attaching package: 'dplyr'

The following objects are masked from 'package:stats':

filter, lag

The following objects are masked from 'package:base':

intersect, setdiff, setequal, union

> library(tidyr)
> library(ggplot2)
> suppressPackageStartupMessages({
+ library(dplyr)
+ library(tidyr)
+ library(ggplot2)
+ })
>
> set.seed(255066335)
>
Expand Down
Binary file modified tests/blowflies-01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/blowflies-02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/blowflies-03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/blowflies-04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/blowflies-05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/blowflies-06.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/blowflies.Rout.save
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

R version 3.5.2 (2018-12-20) -- "Eggshell Igloo"
Copyright (C) 2018 The R Foundation for Statistical Computing
R version 3.6.0 (2019-04-26) -- "Planting of a Tree"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
Expand Down
Binary file modified tests/bsmc2-01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/bsmc2-02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/bsmc2-03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/bsmc2-04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions tests/bsmc2.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ png(filename="bsmc2-%02d.png",res=100)
options(digits=2)

library(pomp2)
library(tidyr)
library(dplyr)
library(ggplot2)
suppressPackageStartupMessages({
library(dplyr)
library(tidyr)
library(ggplot2)
})

gompertz() -> gompertz
set.seed(398585L)
Expand Down
Loading

0 comments on commit 1da69b2

Please sign in to comment.