Skip to content

Commit 6d87384

Browse files
authored
Merge pull request #28 from dom-muston/main
After CRAN submission
2 parents ed329f5 + 9ab72a3 commit 6d87384

File tree

9 files changed

+120
-27
lines changed

9 files changed

+120
-27
lines changed

CRAN-SUBMISSION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Version: 0.4.0
2-
Date: 2026-01-07 00:45:35 UTC
3-
SHA: 986f44179c3fb67d474c9a965f5643004c47e70c
1+
Version: 0.4.1
2+
Date: 2026-01-10 23:19:31 UTC
3+
SHA: ed329f5dac07bdbb36b0093216bc30c4d0a57514

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: dynamicpv
22
Title: Evaluates Present Values and Health Economic Models with Dynamic Pricing and Uptake
3-
Version: 0.4.1
3+
Version: 0.4.1.9000
44
Authors@R: c(
55
person("Dominic", "Muston", , "dominic.muston@msd.com", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0003-4876-7940")),

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# dynamicpv (development version)
2+
3+
* So far, only minor changes to the readme page
4+
15
# dynamicpv 0.4.1
26

37
* Revised vignettes

R/dynamic.R

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,34 @@
9898
dynpv <- function(
9999
uptakes = 1,
100100
payoffs,
101-
horizon = length(payoffs),
101+
horizon = NA,
102102
tzero = 0,
103-
prices = rep(1, length(payoffs)+tzero),
103+
prices = NA,
104104
discrate = 0
105105
){
106+
# If payoffs are discrete
107+
if (class(payoffs)=="numeric") {
108+
# Horizon defaults to length of payoffs
109+
if (class(horizon)=="logical") {horizon <- length(payoffs)}
110+
# Price index defaults to (1, ..., 1)
111+
if (class(prices)=="logical") {prices <- rep(1, length(payoffs)+tzero)}
112+
# Call calculation
113+
dpv <- dynpv_discrete(uptakes, payoffs, horizon, tzero, prices, discrate)
114+
}
115+
# If payoffs are not discrete and uptake is discrete
116+
if ((class(uptakes)=="numeric") & (class(payoffs)=="function")) {
117+
dpv <- dynpv_semicts(uptakes, payoffs, horizon, tzero, prices, discrate)
118+
}
119+
# If payoffs and uptake are not discrete
120+
if ((class(uptakes)=="function") & (class(payoffs)=="function")) {
121+
dpv <- dynpv_fullycts(uptakes, payoffs, horizon, tzero, prices, discrate)
122+
}
123+
# Return
124+
return(dpv)
125+
}
126+
127+
# Discrete function
128+
dynpv_discrete <- function(uptakes, payoffs, horizon, tzero, prices, discrate){
106129
# Avoid no visible binding note
107130
j <- k <- l <- uj <- pk <- R <- v <- NULL
108131
# Trim
@@ -137,3 +160,42 @@ trim_vec <- function(vec){
137160
# Return trimmed vector
138161
return(vec[1:trimto])
139162
}
163+
164+
# Function if payoffs, prices and discounting are functions; but uptakes is a vector
165+
dynpv_semicts <- function(uptakes, payoffs, horizon, tzero, prices, discrate){
166+
# Avoid no visible binding note
167+
j <- uj <- pRv <- pv <- NULL
168+
# Trim
169+
uptakes <- trim_vec(uptakes)
170+
# Integrand function
171+
integrand <- function(k, j) {
172+
payoffs(k) * prices(j+k+tzero) * discrate(j+k)
173+
}
174+
# Create a dataset for each combination of time
175+
df <- expand_grid(j=1:length(uptakes)) |>
176+
dplyr::mutate(
177+
uj = uptakes[j],
178+
pRv = stats::integrate(integrand, lower=0, upper=horizon-j, j=j)$value,
179+
pv = uj * pRv
180+
)
181+
class(df) <- c("dynpv", class(df))
182+
return(df)
183+
}
184+
185+
# Function if uptakes, payoffs, prices and discounting are functions
186+
dynpv_fullycts <- function(uptakes, payoffs, horizon, tzero, prices, discrate){
187+
# First integrand function - pRv, to be integrated between k=0 and k=T-j
188+
integrand1 <- function(k, j) {
189+
payoffs(k) * prices(j+k+tzero) * discrate(j+k)
190+
}
191+
# Second integrand function, uj I, to be integrated between j=0 and j=T
192+
integrand2 <- function(j) {
193+
pRv <- stats::integrate(integrand1, lower=0, upper=horizon-j, j=j)$value
194+
uptakes(j) * pRv
195+
}
196+
# Needs to be vectorized before integrating
197+
integrand2 <- Vectorize(integrand2, "j")
198+
# Calculate double integral
199+
df <- stats::integrate(integrand2, lower=0, upper=horizon)
200+
return(df$value)
201+
}

README.Rmd

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Through the [dynpv()](https://msdllcpapers.github.io/dynamicpv/reference/dynpv.h
2929

3030
## Installation
3131

32-
The package should shortly be available on [CRAN](https://cran.r-project.org/web/packages/index.html). Installing from here is simplest, once available.
32+
The package is now available on [CRAN](https://cran.r-project.org/web/packages/index.html). Installing from here is simplest, as follows.
3333

3434
```{r inst_cran}
3535
#| eval: false
@@ -48,14 +48,7 @@ install.packages("devtools")
4848
pak::pak("MSDLLCpapers/dynamicpv")
4949
```
5050

51-
Note that the above does not install vignettes. Vignettes may be viewed on the [package website](https://msdllcpapers.github.io/dynamicpv/) or by instead running the following.
52-
53-
```{r instal2}
54-
#| eval: false
55-
devtools::install_github("MSDLLCpapers/dynamicpv", build_vignettes=TRUE)
56-
```
57-
58-
You should then load the package, alongside some other packages used here.
51+
Installing the development version in this way does not include vignettes. Vignettes may be viewed on the [package website](https://msdllcpapers.github.io/dynamicpv/). You can then load the package, alongside other packages you may find helpful.
5952

6053
```{r instal3}
6154
#| eval: false

README.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ cost-effectiveness model, such as one computed using the
3636

3737
## Installation
3838

39-
The package should shortly be available on
39+
The package is now available on
4040
[CRAN](https://cran.r-project.org/web/packages/index.html). Installing
41-
from here is simplest, once available.
41+
from here is simplest, as follows.
4242

4343
``` r
4444
# CRAN installation - when available
@@ -56,16 +56,10 @@ install.packages("devtools")
5656
pak::pak("MSDLLCpapers/dynamicpv")
5757
```
5858

59-
Note that the above does not install vignettes. Vignettes may be viewed
60-
on the [package website](https://msdllcpapers.github.io/dynamicpv/) or
61-
by instead running the following.
62-
63-
``` r
64-
devtools::install_github("MSDLLCpapers/dynamicpv", build_vignettes=TRUE)
65-
```
66-
67-
You should then load the package, alongside some other packages used
68-
here.
59+
Installing the development version in this way does not include
60+
vignettes. Vignettes may be viewed on the [package
61+
website](https://msdllcpapers.github.io/dynamicpv/). You can then load
62+
the package, alongside other packages you may find helpful.
6963

7064
``` r
7165
# Load the dynamicpv package

cran-comments.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Resubmission
2+
This is a resubmission. In this version I have:
3+
4+
* Extended the description text in DESCRIPTION
5+
* Revised the vignettes
6+
17
## R CMD check results
28

39
0 errors | 0 warnings | 1 note

tests/testthat/test-fullycts.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Test new fullycts calculations
2+
3+
# Example
4+
payoffs <- function(t) {100+50*t}
5+
prices <- function(t) {1.03 ^ (floor(t))}
6+
discrate <- function(t) {0.97 ^ t}
7+
uptakes <- function(t) {exp(-t/2)}
8+
9+
# 1. Full function calls intermediate function ok
10+
test_that("Full function calls intermediate function ok", {
11+
int <- dynpv_fullycts(uptakes=uptakes, payoffs=payoffs, horizon=5, tzero=0, prices=prices, discrate=discrate)
12+
full <- dynpv(uptakes=uptakes, payoffs=payoffs, horizon=5, prices=prices, discrate=discrate)
13+
expect_equal(int, full)
14+
}
15+
)

tests/testthat/test-semicts.R

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Test new semicts calculations
2+
3+
# Example
4+
payoffs <- function(t) {100+50*t}
5+
prices <- function(t) {1.03 ^ (floor(t))}
6+
discrate <- function(t) {0.97 ^ t}
7+
8+
# 1. Full function calls intermediate function ok
9+
test_that("Full function calls intermediate function ok", {
10+
int <- dynpv_semicts(uptakes=1, payoffs=payoffs, horizon=5, tzero=0, prices=prices, discrate=discrate)
11+
full <- dynpv(payoffs=payoffs, horizon=5, prices=prices, discrate=discrate)
12+
expect_equal(int, full)
13+
}
14+
)
15+
16+
17+
18+
19+

0 commit comments

Comments
 (0)