Skip to content

Commit b16a069

Browse files
committed
Added timeStartEnd as an alternative to frameStartEnd to select frames based on times
1 parent ec94b99 commit b16a069

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+471
-153
lines changed

R/kinfitr_1tcm.R

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
#' be fitted. Recommended to perform once on a large ROI for each measurement,
2626
#' and to specify this value for the remainder of the regions.
2727
#' @param frameStartEnd Optional: This allows one to specify the beginning and
28-
#' final frame to use for modelling, e.g. c(1,20). This is to assess time
29-
#' stability.
28+
#' final frame to use for modelling, e.g. c(1,20). This can be used to assess time stability for example.
29+
#' @param timeStartEnd Optional. This allows one to specify the beginning and end time point instead of defining the frame numbers using frameStartEnd. This function will restrict the model to all time frames whose t_tac is between the values, i.e. c(0,5) will select all frames with midtimes during the first 5 minutes.
3030
#' @param K1.start Optional. Starting parameter for fitting of K1. Default is
3131
#' 0.1.
3232
#' @param K1.lower Optional. Lower bound for the fitting of K1. Default is
@@ -92,14 +92,20 @@
9292
#' @export
9393

9494
onetcm <- function(t_tac, tac, input, weights = NULL, inpshift = NULL, vB = NULL,
95-
frameStartEnd = NULL,
95+
frameStartEnd = NULL, timeStartEnd = NULL,
9696
K1.start = 0.1, K1.lower = 0.0001, K1.upper = 1,
9797
k2.start = 0.1, k2.lower = 0.0001, k2.upper = 0.5,
9898
inpshift.start = 0, inpshift.lower = -0.5, inpshift.upper = 0.5,
9999
vB.start = 0.05, vB.lower = 0.01, vB.upper = 0.1,
100100
multstart_iter = 1, multstart_lower = NULL, multstart_upper = NULL,
101101
printvals = F) {
102102

103+
# Convert timeStartEnd to frameStartEnd if needed
104+
if (is.null(frameStartEnd) && !is.null(timeStartEnd)) {
105+
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
106+
tail(which(t_tac <= timeStartEnd[2]), 1))
107+
}
108+
103109
# Tidying
104110

105111
modeldata <- tidyinput_art(t_tac, tac, weights, frameStartEnd)

R/kinfitr_2tcm.R

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
#' be fitted. Recommended to perform once on a large ROI for each measurement,
2525
#' and to specify this value for the remainder of the regions.
2626
#' @param frameStartEnd Optional: This allows one to specify the beginning and
27-
#' final frame to use for modelling, e.g. c(1,20). This is to assess time
28-
#' stability.
27+
#' final frame to use for modelling, e.g. c(1,20). This can be used to assess time stability for example.
28+
#' @param timeStartEnd Optional. This allows one to specify the beginning and end time point instead of defining the frame numbers using frameStartEnd. This function will restrict the model to all time frames whose t_tac is between the values, i.e. c(0,5) will select all frames with midtimes during the first 5 minutes.
2929
#' @param K1.start Optional. Starting parameter for fitting of K1. Default is
3030
#' 0.1.
3131
#' @param K1.lower Optional. Lower bound for the fitting of K1. Default is
@@ -99,7 +99,7 @@
9999
#' @export
100100

101101
twotcm <- function(t_tac, tac, input, weights = NULL, inpshift = NULL, vB = NULL,
102-
frameStartEnd = NULL,
102+
frameStartEnd = NULL, timeStartEnd = NULL,
103103
K1.start = 0.1, K1.lower = 0.0001, K1.upper = 1,
104104
k2.start = 0.1, k2.lower = 0.0001, k2.upper = 0.5,
105105
k3.start = 0.1, k3.lower = 0.0001, k3.upper = 0.5,
@@ -109,6 +109,12 @@ twotcm <- function(t_tac, tac, input, weights = NULL, inpshift = NULL, vB = NULL
109109
multstart_iter = 1, multstart_lower = NULL, multstart_upper = NULL,
110110
printvals = F) {
111111

112+
# Convert timeStartEnd to frameStartEnd if needed
113+
if (is.null(frameStartEnd) && !is.null(timeStartEnd)) {
114+
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
115+
tail(which(t_tac <= timeStartEnd[2]), 1))
116+
}
117+
112118
# Tidying
113119

114120
tidyinput <- tidyinput_art(t_tac, tac, weights, frameStartEnd)

R/kinfitr_2tcm1k.R

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
#' be fitted. Recommended to perform once on a large ROI for each measurement,
2727
#' and to specify this value for the remainder of the regions.
2828
#' @param frameStartEnd Optional: This allows one to specify the beginning and
29-
#' final frame to use for modelling, e.g. c(1,20). This is to assess time
30-
#' stability.
29+
#' final frame to use for modelling, e.g. c(1,20). This can be used to assess time stability for example.
30+
#' @param timeStartEnd Optional. This allows one to specify the beginning and end time point instead of defining the frame numbers using frameStartEnd. This function will restrict the model to all time frames whose t_tac is between the values, i.e. c(0,5) will select all frames with midtimes during the first 5 minutes.
3131
#' @param K1.start Optional. Starting parameter for fitting of K1. Default is
3232
#' 0.1.
3333
#' @param K1.lower Optional. Lower bound for the fitting of K1. Default is
@@ -113,7 +113,7 @@
113113
#' @export
114114

115115
twotcm1k <- function(t_tac, tac, input, weights = NULL, inpshift = NULL, vB = NULL,
116-
frameStartEnd = NULL,
116+
frameStartEnd = NULL, timeStartEnd = NULL,
117117
K1.start = 0.1, K1.lower = 0.0001, K1.upper = 1,
118118
k2.start = 0.1, k2.lower = 0.0001, k2.upper = 0.5,
119119
k3.start = 0.1, k3.lower = 0.0001, k3.upper = 0.5,
@@ -124,6 +124,12 @@ twotcm1k <- function(t_tac, tac, input, weights = NULL, inpshift = NULL, vB = NU
124124
multstart_iter = 1, multstart_lower = NULL, multstart_upper = NULL,
125125
printvals = F) {
126126

127+
# Convert timeStartEnd to frameStartEnd if needed
128+
if (is.null(frameStartEnd) && !is.null(timeStartEnd)) {
129+
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
130+
tail(which(t_tac <= timeStartEnd[2]), 1))
131+
}
132+
127133
# Tidying
128134

129135
tidyinput <- tidyinput_art(t_tac, tac, weights, frameStartEnd)

R/kinfitr_2tcm_irr.R

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
#' be fitted. Recommended to perform once on a large ROI for each measurement,
2525
#' and to specify this value for the remainder of the regions.
2626
#' @param frameStartEnd Optional: This allows one to specify the beginning and
27-
#' final frame to use for modelling, e.g. c(1,20). This is to assess time
28-
#' stability.
27+
#' final frame to use for modelling, e.g. c(1,20). This can be used to assess time stability for example.
28+
#' @param timeStartEnd Optional. This allows one to specify the beginning and end time point instead of defining the frame numbers using frameStartEnd. This function will restrict the model to all time frames whose t_tac is between the values, i.e. c(0,5) will select all frames with midtimes during the first 5 minutes.
2929
#' @param K1.start Optional. Starting parameter for fitting of K1. Default is
3030
#' 0.1.
3131
#' @param K1.lower Optional. Lower bound for the fitting of K1. Default is
@@ -94,7 +94,7 @@
9494
#' @export
9595

9696
twotcm_irr <- function(t_tac, tac, input, weights = NULL, inpshift = NULL, vB = NULL,
97-
frameStartEnd = NULL,
97+
frameStartEnd = NULL, timeStartEnd = NULL,
9898
K1.start = 0.1, K1.lower = 0.0001, K1.upper = 1,
9999
k2.start = 0.1, k2.lower = 0.0001, k2.upper = 0.5,
100100
k3.start = 0.1, k3.lower = 0.0001, k3.upper = 0.5,
@@ -103,6 +103,12 @@ twotcm_irr <- function(t_tac, tac, input, weights = NULL, inpshift = NULL, vB =
103103
multstart_iter = 1, multstart_lower = NULL, multstart_upper = NULL,
104104
printvals = F) {
105105

106+
# Convert timeStartEnd to frameStartEnd if needed
107+
if (is.null(frameStartEnd) && !is.null(timeStartEnd)) {
108+
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
109+
tail(which(t_tac <= timeStartEnd[2]), 1))
110+
}
111+
106112
# Tidying
107113

108114
tidyinput <- tidyinput_art(t_tac, tac, weights, frameStartEnd)

R/kinfitr_2tcm_macro.R

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
#' @param k4 Optional. This parameter can be used to fix k4 to a specific value.
3535
#' If not specified, this will be fitted.
3636
#' @param frameStartEnd Optional: This allows one to specify the beginning and
37-
#' final frame to use for modelling, e.g. c(1,20). This is to assess time
38-
#' stability.
37+
#' final frame to use for modelling, e.g. c(1,20). This can be used to assess time stability for example.
38+
#' @param timeStartEnd Optional. This allows one to specify the beginning and end time point instead of defining the frame numbers using frameStartEnd. This function will restrict the model to all time frames whose t_tac is between the values, i.e. c(0,5) will select all frames with midtimes during the first 5 minutes.
3939
#' @param K1.start Optional. Starting parameter for fitting of K1. Default is
4040
#' 0.1.
4141
#' @param K1.lower Optional. Lower bound for the fitting of K1. Default is
@@ -110,7 +110,7 @@
110110

111111
twotcm_macro <- function(t_tac, tac, input, weights = NULL, inpshift = NULL,
112112
vB = NULL, Vnd = NULL, BPp = NULL, k4 = NULL,
113-
frameStartEnd = NULL,
113+
frameStartEnd = NULL, timeStartEnd = NULL,
114114
K1.start = 0.1, K1.lower = 0.0001, K1.upper = 1,
115115
Vnd.start = 1, Vnd.lower = 0.0001, Vnd.upper = 10,
116116
BPp.start = 1, BPp.lower = 0.0001, BPp.upper = 50,
@@ -120,6 +120,12 @@ twotcm_macro <- function(t_tac, tac, input, weights = NULL, inpshift = NULL,
120120
multstart_iter = 1, multstart_lower = NULL, multstart_upper = NULL,
121121
printvals = F) {
122122

123+
# Convert timeStartEnd to frameStartEnd if needed
124+
if (is.null(frameStartEnd) && !is.null(timeStartEnd)) {
125+
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
126+
tail(which(t_tac <= timeStartEnd[2]), 1))
127+
}
128+
123129
# Tidying
124130

125131
tidyinput <- tidyinput_art(t_tac, tac, weights, frameStartEnd)

R/kinfitr_SIME.R

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
#' specify which column of \code{tacdf} to use for fitting this: best to use
3131
#' the largest ROI.
3232
#' @param frameStartEnd Optional: This allows one to specify the beginning and
33-
#' final frame to use for modelling, e.g. c(1,20). This is to assess time
34-
#' stability.
33+
#' final frame to use for modelling, e.g. c(1,20). This can be used to assess time stability for example.
34+
#' @param timeStartEnd Optional. This allows one to specify the beginning and end time point instead of defining the frame numbers using frameStartEnd. This function will restrict the model to all time frames whose t_tac is between the values, i.e. c(0,5) will select all frames with midtimes during the first 5 minutes.
3535
#' @param k2.start Optional. Starting parameter for fitting of k2. Default is
3636
#' 0.1.
3737
#' @param k2.lower Optional. Lower bound for the fitting of k2. Default is 0.
@@ -89,12 +89,18 @@
8989
#' @importFrom dplyr "%>%"
9090

9191
SIME <- function(t_tac, tacdf, input, Vndgrid, weights = NULL, roiweights = NULL,
92-
inpshift = 0, vB = NULL, twotcmstart = NULL, frameStartEnd = NULL,
92+
inpshift = 0, vB = NULL, twotcmstart = NULL, frameStartEnd = NULL, timeStartEnd = NULL,
9393
k2.start = 0.1, k2.lower = 0, k2.upper = 0.5,
9494
k3.start = 0.1, k3.lower = 0, k3.upper = 0.5,
9595
k4.start = 0.1, k4.lower = 0, k4.upper = 0.5,
9696
success_cutoff = 0.5) {
9797

98+
# Convert timeStartEnd to frameStartEnd if needed
99+
if (is.null(frameStartEnd) && !is.null(timeStartEnd)) {
100+
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
101+
tail(which(t_tac <= timeStartEnd[2]), 1))
102+
}
103+
98104
# Tidying
99105

100106
if (is.null(weights)) {

R/kinfitr_SUV.R

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
#' @param injRad The injected radioactivity. If not included, this will be set to 1 in case one is using SUV ratios.
1111
#' @param bodymass The body mass of the participant. If not included, this will be set to 1 in case one is using SUV ratios.
1212
#' @param frameStartEnd Optional: This allows one to specify the beginning and final frame to use for modelling, e.g. c(1,20).
13-
#' This is to assess time stability.
13+
#' This can be used to assess time stability for example.
14+
#' @param timeStartEnd Optional. This allows one to specify the beginning and end time point instead of defining the frame numbers using frameStartEnd. This function will restrict the model to all time frames whose t_tac is between the values, i.e. c(0,5) will select all frames with midtimes during the first 5 minutes. Note that this requires t_tac.
1415
#'
1516
#' @return A list with a data frame of the calculated parameters \code{out$par} and a dataframe containing the TACs both of the
1617
#' original data and the transformed values \code{out$tacs}
@@ -25,26 +26,59 @@
2526
#'
2627
#' fit1 <- SUV(tac, t_tac, injRad = 150, bodymass = 85)
2728
#' fit2 <- SUV(tac, dur_tac = dur_tac, injRad = 150, bodymass = 85)
29+
#' fit3 <- SUV(tac, t_tac = t_tac, dur_tac = dur_tac, injRad = 150, bodymass = 85)
30+
#' fit4 <- SUV(tac, t_tac = t_tac, dur_tac = dur_tac, injRad = 150, bodymass = 85, frameStartEnd = c(1,5))
2831
#' @author Granville J Matheson, \email{mathesong@@gmail.com}
2932
#'
3033
#' @export
3134

32-
SUV <- function(tac, t_tac = NULL, dur_tac = NULL, injRad = 1, bodymass = 1, frameStartEnd = NULL) {
35+
SUV <- function(tac, t_tac = NULL, dur_tac = NULL, injRad = 1, bodymass = 1,
36+
frameStartEnd = NULL, timeStartEnd = NULL) {
3337

3438
# Tidying
3539

36-
if (is.null(dur_tac)) {
37-
tidyinput <- tidyinput_art(t_tac, tac, tac,
38-
frameStartEnd) # Don't need weights, thus just set to same as tac
39-
t_tac <- tidyinput$t_tac
40-
} else {
40+
if( is.null(frameStartEnd) && !is.null(timeStartEnd) && is.null(t_tac) ) {
41+
stop("timeStartEnd can only be used if t_tac is provided.")
42+
}
43+
44+
# Convert timeStartEnd to frameStartEnd if needed
45+
if (is.null(frameStartEnd) && !is.null(timeStartEnd)) {
46+
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
47+
tail(which(t_tac <= timeStartEnd[2]), 1))
48+
}
49+
50+
if (!is.null(dur_tac) & is.null(t_tac)) {
51+
4152
tidyinput <- tidyinput_art(dur_tac, tac, tac,
4253
frameStartEnd) # Don't need weights, thus just set to same as tac
4354
dur_tac <- tidyinput$t_tac
55+
56+
tac <- tidyinput$tac
4457
}
4558

59+
if (is.null(dur_tac) & !is.null(t_tac)) {
60+
tidyinput <- tidyinput_art(t_tac, tac, tac,
61+
frameStartEnd) # Don't need weights, thus just set to same as tac
62+
t_tac <- tidyinput$t_tac
63+
64+
tac <- tidyinput$tac
65+
}
66+
67+
if (is.null(dur_tac) & is.null(t_tac)) {
68+
stop("Either t_tac or dur_tac must be provided")
69+
}
4670

47-
tac <- tidyinput$tac
71+
if (!is.null(dur_tac) & !is.null(t_tac)) {
72+
tidyinput1 <- tidyinput_art(dur_tac, tac, tac,
73+
frameStartEnd) # Don't need weights, thus just set to same as tac
74+
dur_tac <- tidyinput1$t_tac
75+
76+
tidyinput2 <- tidyinput_art(t_tac, tac, tac,
77+
frameStartEnd) # Don't need weights, thus just set to same as tac
78+
t_tac <- tidyinput2$t_tac
79+
80+
tac <- tidyinput1$tac
81+
}
4882

4983

5084
# 'Model'

R/kinfitr_frtm.R

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#' in the fitting. We include zero at time zero: if not included, it is added.
1616
#' If not specified, uniform weights will be used.
1717
#' @param frameStartEnd Optional. This allows one to specify the beginning and
18-
#' final frame to use for modelling, e.g. c(1,20). This is to assess time
19-
#' stability.
18+
#' final frame to use for modelling, e.g. c(1,20). This can be used to assess time stability for example.
19+
#' @param timeStartEnd Optional. This allows one to specify the beginning and end time point instead of defining the frame numbers using frameStartEnd. This function will restrict the model to all time frames whose t_tac is between the values, i.e. c(0,5) will select all frames with midtimes during the first 5 minutes.
2020
#' @param R1.start Optional. Starting parameter for fitting of R1. Default is 1.
2121
#' @param R1.lower Optional. Lower bound for the fitting of R1. Default is 0.
2222
#' @param R1.upper Optional. Upper bound for the fitting of R1. Default is 10.
@@ -71,14 +71,19 @@
7171
#'
7272
#' @export
7373

74-
frtm <- function(t_tac, reftac, roitac, weights = NULL, frameStartEnd = NULL,
74+
frtm <- function(t_tac, reftac, roitac, weights = NULL, frameStartEnd = NULL, timeStartEnd = NULL,
7575
R1.start = 1, R1.lower = 0, R1.upper = 10,
7676
k2.start = 0.1, k2.lower = 0, k2.upper = 1,
7777
bp.start = 1.5, bp.lower = 0, bp.upper = 15,
7878
k4.start = 0.1, k4.lower = 0, k4.upper = 1,
7979
multstart_iter = 1, multstart_lower = NULL, multstart_upper = NULL,
8080
printvals = F) {
8181

82+
# Convert timeStartEnd to frameStartEnd if needed
83+
if (is.null(frameStartEnd) && !is.null(timeStartEnd)) {
84+
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
85+
tail(which(t_tac <= timeStartEnd[2]), 1))
86+
}
8287

8388
# Tidying
8489

R/kinfitr_lin2tcm.R

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
#' not included, the integrals will be calculated using trapezoidal
2525
#' integration.
2626
#' @param frameStartEnd Optional: This allows one to specify the beginning and
27-
#' final frame to use for modelling, e.g. c(1,20). This is to assess time
28-
#' stability.
27+
#' final frame to use for modelling, e.g. c(1,20). This can be used to assess time stability for example.
28+
#' @param timeStartEnd Optional. This allows one to specify the beginning and end time point instead of defining the frame numbers using frameStartEnd. This function will restrict the model to all time frames whose t_tac is between the values, i.e. c(0,5) will select all frames with midtimes during the first 5 minutes.
2929
#'
3030
#' @return A list with a data frame of the fitted parameters \code{out$par}, the
3131
#' model fit object \code{out$fit}, a dataframe containing the TACs of the
@@ -62,9 +62,15 @@
6262
#'
6363
#' @export
6464
lin2tcm <- function(t_tac, tac, input, weights = NULL, inpshift = 0,
65-
vB = NULL, dur = NULL, frameStartEnd = NULL) {
65+
vB = NULL, dur = NULL, frameStartEnd = NULL, timeStartEnd = NULL) {
6666

6767

68+
# Convert timeStartEnd to frameStartEnd if needed
69+
if (is.null(frameStartEnd) && !is.null(timeStartEnd)) {
70+
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
71+
tail(which(t_tac <= timeStartEnd[2]), 1))
72+
}
73+
6874
# Tidying
6975

7076
tidyinput <- tidyinput_art(t_tac, tac, weights, frameStartEnd)
@@ -341,8 +347,8 @@ plot_lin2tcmfit <- function(lin2tcmout, roiname = NULL) {
341347
#' not included, the integrals will be calculated using trapezoidal
342348
#' integration.
343349
#' @param frameStartEnd Optional: This allows one to specify the beginning and
344-
#' final frame to use for modelling, e.g. c(1,20). This is to assess time
345-
#' stability.
350+
#' final frame to use for modelling, e.g. c(1,20). This can be used to assess time stability for example.
351+
#' @param timeStartEnd Optional. This allows one to specify the beginning and end time point instead of defining the frame numbers using frameStartEnd. This function will restrict the model to all time frames whose t_tac is between the values, i.e. c(0,5) will select all frames with midtimes during the first 5 minutes.
346352
#' @param inpshift_vals Optional. The values of the inpshift to assess with the
347353
#' grid. By default, a grid between -1 and 1 with spacing of 0.01 will be
348354
#' used.
@@ -381,7 +387,13 @@ plot_lin2tcmfit <- function(lin2tcmout, roiname = NULL) {
381387
#' @export
382388
lin2tcm_inpshiftProfile <- function(t_tac, tac, input, weights = NULL, vB = NULL,
383389
dur = NULL, frameStartEnd = NULL,
384-
inpshift_vals = NULL) {
390+
timeStartEnd = NULL, inpshift_vals = NULL) {
391+
392+
# Convert timeStartEnd to frameStartEnd if needed
393+
if (is.null(frameStartEnd) && !is.null(timeStartEnd)) {
394+
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
395+
tail(which(t_tac <= timeStartEnd[2]), 1))
396+
}
385397

386398
if ( is.null(inpshift_vals) ) {
387399
inpshift_vals <- seq(from = -1, to = 1, by = 0.01)

0 commit comments

Comments
 (0)