Skip to content

Commit

Permalink
splinef
Browse files Browse the repository at this point in the history
+ make_function.splinef and makepar_F_splinef added
  • Loading branch information
smitdave committed Jan 29, 2025
1 parent f6e7c0e commit f8ce01a
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ S3method(make_function,product)
S3method(make_function,sharkfin)
S3method(make_function,sigmoid)
S3method(make_function,sin)
S3method(make_function,splinef)
S3method(make_function,sum)
S3method(make_runtime,dts)
S3method(make_runtime,xde)
Expand Down Expand Up @@ -545,6 +546,7 @@ export(makepar_F_product)
export(makepar_F_sharkfin)
export(makepar_F_sigmoid)
export(makepar_F_sin)
export(makepar_F_splinef)
export(makepar_F_sum)
export(metric_calD)
export(metric_calR)
Expand Down
29 changes: 29 additions & 0 deletions R/functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,32 @@ makepar_F_sharkfin = function(D=100, L=180, uk = 1/7, dk=1/40, pw=1, mx=1, N=1){
pars$N = N
return(pars)
}


#' @title Make a spline function
#' @description A spline function passes time points `tt` and
#' associated values `yy` and returns a spline function
#' @inheritParams make_function
#' @return a function
#' @export
make_function.splinef = function(opts){
ff <- function(t){
stats::spline(opts$tt, opts$yy, xout = t)$y
}
return(ff)
}


#' @title Make Parameters for a Spline
#' @description Return an object for [make_function.splinef]
#' @param tt the nodes
#' @param yy the y values
#' @return parameters to configure the `splinef` case of `make_function`
#' @export
makepar_F_splinef = function(tt, yy){
pars <- list()
class(pars) = "splinef"
pars$tt = tt
pars$yy = yy
return(pars)
}
2 changes: 2 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,8 @@ reference:
- makepar_F_sigmoid
- make_function.sharkfin
- makepar_F_sharkfin
- make_function.splinef
- makepar_F_splinef
- subtitle: New
desc: |
Basic visualization of the transmission terms
Expand Down
2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ articles:
TraceFunctions: TraceFunctions.html
Understanding_ramp.xds: Understanding_ramp.xds.html
Working: Working.html
last_built: 2024-12-16T22:33Z
last_built: 2025-01-28T23:38Z
urls:
reference: https://dd-harp.github.io/ramp.xds/reference
article: https://dd-harp.github.io/ramp.xds/articles
Expand Down
10 changes: 10 additions & 0 deletions docs/reference/index.html

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

6 changes: 5 additions & 1 deletion docs/reference/xds_solve_cohort.html

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

3 changes: 3 additions & 0 deletions man/make_function.sin.Rd

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

18 changes: 18 additions & 0 deletions man/make_function.splinef.Rd

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

19 changes: 19 additions & 0 deletions man/makepar_F_splinef.Rd

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

4 changes: 3 additions & 1 deletion man/xds_solve_cohort.Rd

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

20 changes: 20 additions & 0 deletions vignettes/TraceFunctions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,23 @@ C2t <- C2(tt)
plot(tt, C2t[1,], type ="l", xlab = "Time (in Days)", ylab = expression(Fs1(t)))
lines(tt, C2t[2,])
```

### Spline


```{r}
tv = c(-1:6)*365/4
yv = c(1/2, 1, 2, 1, 1/3, 1, 3, 1)
sp0 <- makepar_F_splinef(tv, yv)
```


```{r}
ff <- make_function(sp0)
```


```{r}
plot(tt, ff(tt), type = "l")
```

0 comments on commit f8ce01a

Please sign in to comment.