Skip to content

Commit

Permalink
full test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ionides committed May 14, 2024
1 parent bd81c81 commit cbafb64
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 15 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: spatPomp
Type: Package
Title: Inference for Spatiotemporal Partially Observed Markov Processes
Version: 0.34.6
Date: 2024-05-12
Version: 0.34.7
Date: 2024-05-13
Authors@R: c(
person("Kidus", "Asfaw", email = "[email protected]", role = c("aut")),
person("Edward", "Ionides", email = "[email protected]",role = c("cre","aut")),
Expand Down
7 changes: 4 additions & 3 deletions R/as_data_frame.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ setAs(
# convert to long format with column for stateobscovars
no_time_colnames <- colnames(dat)[-1]
shared_covnames_ix <- which(no_time_colnames %in% from@shared_covarnames)
if(length(shared_covnames_ix) > 0)
if(length(shared_covnames_ix) > 0) {
to_gather <- no_time_colnames[-shared_covnames_ix]
else
to_gather <- no_time_colnames
stop(paste('in', sQuote('as.data.frame'),
": shared covariates are not yet fully implemented in spatPomp"))
} else to_gather <- no_time_colnames
to_arrange <- rlang::syms(c(timename, unitname, "stateobscovars"))
to_final_select <- c(timename, unitname, unit_stateobscovars)
gathered <- dat %>%
Expand Down
2 changes: 1 addition & 1 deletion tests/bm.R
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ try(spatPomp(data=b_data,times="time",units="unit",t0=0,
b_shared_covar <- data.frame(time=0:2,Z=3:5)
model_shared_covar <- spatPomp(data=b_data,times="time",units="unit",
t0=0,covar=b_shared_covar, shared_covarnames="Z")
as.data.frame(b_shared_covar)
try(as.data.frame(model_shared_covar))

b_unit_covar <- data.frame(time=c(0:2,0:2),unit=rep(c("U1","U2"),each=3),
Z=rep(3:5,times=2))
Expand Down
10 changes: 4 additions & 6 deletions tests/bm.Rout.save
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

R version 4.4.0 (2024-04-24) -- "Puppy Cup"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin20
Platform: x86_64-apple-darwin20

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Expand Down Expand Up @@ -1132,11 +1132,9 @@ Error : in ‘spatPomp’: for unit-specific covariates, there should be a colum
> b_shared_covar <- data.frame(time=0:2,Z=3:5)
> model_shared_covar <- spatPomp(data=b_data,times="time",units="unit",
+ t0=0,covar=b_shared_covar, shared_covarnames="Z")
> as.data.frame(b_shared_covar)
time Z
1 0 3
2 1 4
3 2 5
> try(as.data.frame(model_shared_covar))
Error in asMethod(object) :
in ‘as.data.frame’ : shared covariates are not yet fully implemented in spatPomp
>
> b_unit_covar <- data.frame(time=c(0:2,0:2),unit=rep(c("U1","U2"),each=3),
+ Z=rep(3:5,times=2))
Expand Down
9 changes: 8 additions & 1 deletion tests/measles.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ logLik(m2_pf)
## i.e., cohort=0.
##

## A call to igirf using the moment-based guide function can test compiled code for eunit_measure, munit_measure, vunit_measure, dunit_measure, runit_measure, rprocess, skeleton, rinit and partrans.
## A call to igirf using the moment-based guide function can test
## compiled code for eunit_measure, munit_measure, vunit_measure,
## dunit_measure, runit_measure, rprocess, skeleton, rinit and partrans.
## It also tests igirf (method=moment) with covariates

m3_params <- m_params
m3_params["cohort"] <- 0
Expand All @@ -64,6 +67,10 @@ m3_igirf_out <- igirf(m_model, Ngirf = m3_igirf_ngirf,
)
logLik(m3_igirf_out)

## another call to igirf tests igirf (method=bootstrap) with covariates
m3_igirf_bootstrap_out <- igirf(m3_igirf_out,kind='bootstrap')
logLik(m3_igirf_bootstrap_out)

## test error message
try(measles(U=1000))

Expand Down
17 changes: 15 additions & 2 deletions tests/measles.Rout.save
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

R version 4.4.0 (2024-04-24) -- "Puppy Cup"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin20
Platform: x86_64-apple-darwin20

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Expand Down Expand Up @@ -63,7 +63,10 @@ Loading required package: pomp
> ## i.e., cohort=0.
> ##
>
> ## A call to igirf using the moment-based guide function can test compiled code for eunit_measure, munit_measure, vunit_measure, dunit_measure, runit_measure, rprocess, skeleton, rinit and partrans.
> ## A call to igirf using the moment-based guide function can test
> ## compiled code for eunit_measure, munit_measure, vunit_measure,
> ## dunit_measure, runit_measure, rprocess, skeleton, rinit and partrans.
> ## It also tests igirf (method=moment) with covariates
>
> m3_params <- m_params
> m3_params["cohort"] <- 0
Expand Down Expand Up @@ -91,6 +94,16 @@ Warning messages:
> logLik(m3_igirf_out)
[1] -86380.55
>
> ## another call to igirf tests igirf (method=bootstrap) with covariates
> m3_igirf_bootstrap_out <- igirf(m3_igirf_out,kind='bootstrap')
Warning messages:
1: in 'table_lookup': extrapolating at 1.965003e+03.
2: in 'table_lookup': extrapolating at 1.965002e+03.
3: in 'table_lookup': extrapolating at 1.965002e+03.
4: in 'table_lookup': extrapolating at 1.965002e+03.
> logLik(m3_igirf_bootstrap_out)
[1] -86123.26
>
> ## test error message
> try(measles(U=1000))
Error in measles(U = 1000) :
Expand Down

0 comments on commit cbafb64

Please sign in to comment.