@@ -188,11 +188,12 @@ Xs.deSolve <- function(odemodel,
188188# ' and proper `dimnames` for variables and parameters.
189189# '
190190# ' @examples
191- # ' # Example column names: "A.k1", "A.k2", "B.k1", "B.k2"
192- # ' mysens <- matrix(runif(40), nrow = 10)
193- # ' colnames(mysens) <- c("A.k1", "A.k2", "B.k1", "B.k2")
194- # ' reshapeSens(mysens, variables = c("A", "B"), parameters = c("k1", "k2"))
195- # '
191+ # ' \dontrun{
192+ # ' # Example column names: "A.k1", "A.k2", "B.k1", "B.k2"
193+ # ' mysens <- matrix(runif(40), nrow = 10)
194+ # ' colnames(mysens) <- c("A.k1", "A.k2", "B.k1", "B.k2")
195+ # ' reshapeSens(mysens, variables = c("A", "B"), parameters = c("k1", "k2"))
196+ # ' }
196197# ' @keywords internal
197198reshapeSens <- function (sensMatrix , variables , parameters ) {
198199 n_times <- nrow(sensMatrix )
@@ -521,6 +522,7 @@ Xf <- function(odemodel, forcings = NULL, events = NULL, condition = NULL, optio
521522# ' the data frame), and possibly "pouter", a named numeric vector which is generated
522523# ' from `data$value`.
523524# ' @examples
525+ # ' \dontrun{
524526# ' # Generate a data.frame and corresponding prediction function
525527# ' timesD <- seq(0, 2*pi, 0.5)
526528# ' mydata <- data.frame(name = "A", time = timesD, value = sin(timesD),
@@ -533,6 +535,7 @@ Xf <- function(odemodel, forcings = NULL, events = NULL, condition = NULL, optio
533535# ' prediction <- x(times, pouter)
534536# ' plot(prediction)
535537# '
538+ # ' }
536539# ' @export
537540Xd <- function (data , condition = NULL ) {
538541
@@ -1030,51 +1033,53 @@ Y <- function(g, f = NULL, states = NULL, parameters = NULL, condition = NULL,
10301033}
10311034
10321035
1033- # #' Generate a prediction function that returns times
1034- # #'
1035- # #' Function to deal with non-ODE models within the framework of dMod. See example.
1036- # #'
1037- # #' @param condition either NULL (generic prediction for any condition) or a character, denoting
1038- # #' the condition for which the function makes a prediction.
1039- # #' @return Object of class [prdfn].
1040- # #' @examples
1041- # #' x <- Xt()
1042- # #' g <- Y(c(y = "a*time^2+b"), f = NULL, parameters = c("a", "b"))
1043- # #'
1044- # #' times <- seq(-1, 1, by = .05)
1045- # #' pars <- c(a = .1, b = 1)
1046- # #'
1047- # #' plot((g*x)(times, pars))
1048- # #' @export
1049- # Xt <- function(condition = NULL) {
1050- #
1051- #
1052- #
1053- # # Controls to be modified from outside
1054- # controls <- list()
1055- #
1056- # P2X <- function(times, pars, deriv=TRUE){
1057- #
1058- # out <- matrix(times, ncol = 1, dimnames = list(NULL, "time"))
1059- # sens <- deriv <- out
1060- #
1061- # prdframe(out, deriv = deriv, sensitivities = sens, parameters = pars)
1062- #
1063- # }
1064- #
1065- # attr(P2X, "parameters") <- NULL
1066- # attr(P2X, "equations") <- NULL
1067- # attr(P2X, "forcings") <- NULL
1068- # attr(P2X, "events") <- NULL
1069- #
1070- #
1071- # prdfn(P2X, NULL, condition)
1072- #
1073- #
1074- #
1075- #
1076- # }
1077-
1036+ # ' Generate a prediction function that returns times
1037+ # '
1038+ # ' Function to deal with non-ODE models within the framework of dMod. See example.
1039+ # '
1040+ # ' @param condition either NULL (generic prediction for any condition) or a character, denoting
1041+ # ' the condition for which the function makes a prediction.
1042+ # ' @return Object of class [prdfn].
1043+ # ' @examples
1044+ # ' x <- Xt()
1045+ # ' g <- Y(c(y = "a*time^2+b"), f = NULL, parameters = c("a", "b"))
1046+ # '
1047+ # ' times <- seq(-1, 1, by = .05)
1048+ # ' pars <- c(a = .1, b = 1)
1049+ # '
1050+ # ' plot((g*x)(times, pars))
1051+ # ' @export
1052+ Xt <- function (condition = NULL ) {
1053+ # Controls to be modified from outside
1054+ controls <- list ()
1055+ P2X <- function (times , pars , deriv = TRUE , deriv2 = FALSE , ... ) {
1056+ n_times <- length(times )
1057+ n_pars <- length(pars )
1058+ par_names <- names(pars )
1059+
1060+ # Output: matrix with time column
1061+ out <- matrix (times , ncol = 1 , dimnames = list (NULL , " time" ))
1062+
1063+ # Sensitivities (deriv): 3D array [n_times, n_states, n_pars]
1064+ # time has no dependence on parameters, so all zeros
1065+ sens <- array (0 ,
1066+ dim = c(n_times , 1 , n_pars ),
1067+ dimnames = list (NULL , " time" , par_names ))
1068+
1069+ # Second derivatives (deriv2): 4D array [n_times, n_states, n_pars, n_pars]
1070+ # All zeros since time is independent of parameters
1071+ deriv2_arr <- array (0 ,
1072+ dim = c(n_times , 1 , n_pars , n_pars ),
1073+ dimnames = list (NULL , " time" , par_names , par_names ))
1074+
1075+ prdframe(out , deriv = sens , deriv2 = deriv2_arr , parameters = pars )
1076+ }
1077+ attr(P2X , " parameters" ) <- NULL
1078+ attr(P2X , " equations" ) <- NULL
1079+ attr(P2X , " forcings" ) <- NULL
1080+ attr(P2X , " events" ) <- NULL
1081+ prdfn(P2X , NULL , condition )
1082+ }
10781083
10791084
10801085# ' An identity function which vanishes upon concatenation of fns
0 commit comments