Skip to content

Commit 2cf7926

Browse files
committed
Moved tstar time frame calculation to after tidying with frameStartend
1 parent 512d430 commit 2cf7926

16 files changed

+127
-125
lines changed

R/kinfitr_loganplot.R

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#' @param input Data frame containing the blood, plasma, and parent fraction
1212
#' concentrations over time. This can be generated using the
1313
#' \code{blood_interp} function.
14-
#' @param tstar The t* specification for regression. If tstar_type="frames",
14+
#' @param tstar The t* specification for regression. If tstar_type="frames",
1515
#' this is the number of frames from the end to include (e.g., 10 means last 10 frames).
16-
#' If tstar_type="time", this is the time point (in minutes) after which all frames
16+
#' If tstar_type="time", this is the time point (in minutes) after which all frames
1717
#' with midpoints later than this time are included. This value can be estimated using \code{Logan_tstar}.
1818
#' @param tstar_type Either "frames" (default) or "time", specifying how to interpret tstar.
1919
#' @param tstarIncludedFrames Deprecated. Use 'tstar' with 'tstar_type="frames"' instead.
@@ -77,7 +77,7 @@ Loganplot <- function(t_tac, tac, input, tstar, weights = NULL,
7777

7878
# Convert timeStartEnd to frameStartEnd if needed
7979
if (is.null(frameStartEnd) && !is.null(timeStartEnd)) {
80-
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
80+
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
8181
tail(which(t_tac <= timeStartEnd[2]), 1))
8282
}
8383

@@ -101,14 +101,6 @@ Loganplot <- function(t_tac, tac, input, tstar, weights = NULL,
101101
warning("No value specified for tstar: defaulting to including all frames. This may produce biased outcomes.", call. = FALSE)
102102
}
103103

104-
# Convert tstar based on type
105-
if (tstar_type == "time") {
106-
frames_after_tstar <- which(t_tac >= tstar)
107-
tstarIncludedFrames <- length(frames_after_tstar)
108-
} else {
109-
tstarIncludedFrames <- tstar
110-
}
111-
112104
# Tidying
113105

114106
tidyinput <- tidyinput_art(t_tac, tac, weights, frameStartEnd)
@@ -122,6 +114,14 @@ Loganplot <- function(t_tac, tac, input, tstar, weights = NULL,
122114
tac <- tidyinput$tac
123115
weights <- tidyinput$weights
124116

117+
# Convert tstar based on type
118+
if (tstar_type == "time") {
119+
frames_after_tstar <- which(t_tac >= tstar)
120+
tstarIncludedFrames <- length(frames_after_tstar)
121+
} else {
122+
tstarIncludedFrames <- tstar
123+
}
124+
125125
newvals <- shift_timings(
126126
t_tac = t_tac,
127127
tac = tac,

R/kinfitr_ma1.R

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,6 @@ ma1 <- function(t_tac, tac, input, tstar, weights = NULL,
8787
warning("No value specified for tstar: defaulting to including all frames. This may produce biased outcomes.", call. = FALSE)
8888
}
8989

90-
# Convert tstar based on type
91-
if (tstar_type == "time") {
92-
frames_after_tstar <- which(t_tac >= tstar)
93-
tstarIncludedFrames <- length(frames_after_tstar)
94-
} else {
95-
tstarIncludedFrames <- tstar
96-
}
97-
9890
# Tidying
9991

10092
tidyinput <- tidyinput_art(t_tac, tac, weights, frameStartEnd)
@@ -108,6 +100,16 @@ ma1 <- function(t_tac, tac, input, tstar, weights = NULL,
108100
tac <- tidyinput$tac
109101
weights <- tidyinput$weights
110102

103+
104+
# Convert tstar based on type
105+
if (tstar_type == "time") {
106+
frames_after_tstar <- which(t_tac >= tstar)
107+
tstarIncludedFrames <- length(frames_after_tstar)
108+
} else {
109+
tstarIncludedFrames <- tstar
110+
}
111+
112+
111113
newvals <- shift_timings(
112114
t_tac = t_tac,
113115
tac = tac,

R/kinfitr_mlloganplot.R

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
#' zero: if not included, it is added.
99
#' @param input Data frame containing the blood, plasma, and parent fraction concentrations over time. This can be generated
1010
#' using the \code{blood_interp} function.
11-
#' @param tstar The t* specification for regression. If tstar_type="frames",
11+
#' @param tstar The t* specification for regression. If tstar_type="frames",
1212
#' this is the number of frames from the end to include (e.g., 10 means last 10 frames).
13-
#' If tstar_type="time", this is the time point (in minutes) after which all frames
13+
#' If tstar_type="time", this is the time point (in minutes) after which all frames
1414
#' with midpoints later than this time are included. This value can be estimated using \code{mlLogan_tstar}.
1515
#' @param tstar_type Either "frames" (default) or "time", specifying how to interpret tstar.
1616
#' @param tstarIncludedFrames Deprecated. Use 'tstar' with 'tstar_type="frames"' instead.
@@ -65,7 +65,7 @@ mlLoganplot <- function(t_tac, tac, input, tstar, weights = NULL,
6565

6666
# Convert timeStartEnd to frameStartEnd if needed
6767
if (is.null(frameStartEnd) && !is.null(timeStartEnd)) {
68-
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
68+
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
6969
tail(which(t_tac <= timeStartEnd[2]), 1))
7070
}
7171

@@ -89,14 +89,6 @@ mlLoganplot <- function(t_tac, tac, input, tstar, weights = NULL,
8989
warning("No value specified for tstar: defaulting to including all frames. This may produce biased outcomes.", call. = FALSE)
9090
}
9191

92-
# Convert tstar based on type
93-
if (tstar_type == "time") {
94-
frames_after_tstar <- which(t_tac >= tstar)
95-
tstarIncludedFrames <- length(frames_after_tstar)
96-
} else {
97-
tstarIncludedFrames <- tstar
98-
}
99-
10092
# Tidying
10193

10294
tidyinput <- tidyinput_art(t_tac, tac, weights, frameStartEnd)
@@ -111,6 +103,14 @@ mlLoganplot <- function(t_tac, tac, input, tstar, weights = NULL,
111103
weights <- tidyinput$weights
112104

113105

106+
# Convert tstar based on type
107+
if (tstar_type == "time") {
108+
frames_after_tstar <- which(t_tac >= tstar)
109+
tstarIncludedFrames <- length(frames_after_tstar)
110+
} else {
111+
tstarIncludedFrames <- tstar
112+
}
113+
114114
newvals <- shift_timings(
115115
t_tac = t_tac,
116116
tac = tac,
@@ -304,7 +304,7 @@ plot_mlLoganfit <- function(mlloganout, roiname = NULL) {
304304
mlLogan_tstar <- function(t_tac, lowroi, medroi, highroi, input, filename = NULL, inpshift = 0, vB = 0, frameStartEnd = NULL, timeStartEnd = NULL, gridbreaks = 2) {
305305
# Convert timeStartEnd to frameStartEnd if needed
306306
if (is.null(frameStartEnd) && !is.null(timeStartEnd)) {
307-
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
307+
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
308308
tail(which(t_tac <= timeStartEnd[2]), 1))
309309
}
310310

R/kinfitr_mrtm1.R

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
#' @param roitac Numeric vector of radioactivity concentrations in the target
1414
#' tissue for each frame. We include zero at time zero: if not included, it is
1515
#' added.
16-
#' @param tstar Optional. The t* specification for regression. If tstar_type="frames",
16+
#' @param tstar Optional. The t* specification for regression. If tstar_type="frames",
1717
#' this is the number of frames from the end to include (e.g., 10 means last 10 frames).
18-
#' If tstar_type="time", this is the time point (in minutes) after which all frames
18+
#' If tstar_type="time", this is the time point (in minutes) after which all frames
1919
#' with midpoints later than this time are included. This value can be estimated using \code{mrtm1_tstar}.
2020
#' Note that this t* differs from that of the non-invasive Logan plot (which is the point at which
2121
#' pseudo-equilibrium is reached). Rather, with MRTM1 and MRTM2, all frames
@@ -69,7 +69,7 @@ mrtm1 <- function(t_tac, reftac, roitac, tstar = NULL, weights = NULL,
6969

7070
# Convert timeStartEnd to frameStartEnd if needed
7171
if (is.null(frameStartEnd) && !is.null(timeStartEnd)) {
72-
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
72+
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
7373
tail(which(t_tac <= timeStartEnd[2]), 1))
7474
}
7575

@@ -83,19 +83,6 @@ mrtm1 <- function(t_tac, reftac, roitac, tstar = NULL, weights = NULL,
8383
tstar_type <- "frames"
8484
}
8585

86-
# Validate tstar_type
87-
if (!is.null(tstar)) {
88-
tstar_type <- match.arg(tstar_type, c("frames", "time"))
89-
90-
# Convert tstar based on type
91-
if (tstar_type == "time") {
92-
frames_after_tstar <- which(t_tac >= tstar)
93-
tstarIncludedFrames <- length(frames_after_tstar)
94-
} else {
95-
tstarIncludedFrames <- tstar
96-
}
97-
}
98-
9986
# Tidying
10087

10188
tidyinput <- tidyinput_ref(t_tac, reftac, roitac, weights, frameStartEnd)
@@ -110,6 +97,19 @@ mrtm1 <- function(t_tac, reftac, roitac, tstar = NULL, weights = NULL,
11097
roitac <- tidyinput$roitac
11198
weights <- tidyinput$weights
11299

100+
# Validate tstar_type
101+
if (!is.null(tstar)) {
102+
tstar_type <- match.arg(tstar_type, c("frames", "time"))
103+
104+
# Convert tstar based on type
105+
if (tstar_type == "time") {
106+
frames_after_tstar <- which(t_tac >= tstar)
107+
tstarIncludedFrames <- length(frames_after_tstar)
108+
} else {
109+
tstarIncludedFrames <- tstar
110+
}
111+
}
112+
113113
if (is.null(tstarIncludedFrames)) {
114114
tstarIncludedFrames <- length(reftac)
115115
}
@@ -239,7 +239,7 @@ plot_mrtm1fit <- function(mrtm1out, roiname = NULL, refname = NULL) {
239239
refname <- "Reference"
240240
}
241241

242-
measured <- dplyr::rename(measured,
242+
measured <- dplyr::rename(measured,
243243
!!paste0(roiname, ".measured") := ROI.measured,
244244
!!refname := Reference
245245
)
@@ -318,7 +318,7 @@ plot_mrtm1fit <- function(mrtm1out, roiname = NULL, refname = NULL) {
318318
mrtm1_tstar <- function(t_tac, reftac, lowroi, medroi, highroi, filename = NULL, frameStartEnd = NULL, timeStartEnd = NULL, gridbreaks = 2) {
319319
# Convert timeStartEnd to frameStartEnd if needed
320320
if (is.null(frameStartEnd) && !is.null(timeStartEnd)) {
321-
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
321+
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
322322
tail(which(t_tac <= timeStartEnd[2]), 1))
323323
}
324324

R/kinfitr_mrtm2.R

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
#' tissue-to-plasma clearance rate. This can be obtained from MRTM1 of SRTM,
1818
#' or set at a specified value. If using SRTM to estimate this value, it is
1919
#' equal to k2 / R1.
20-
#' @param tstar Optional. The t* specification for regression. If tstar_type="frames",
20+
#' @param tstar Optional. The t* specification for regression. If tstar_type="frames",
2121
#' this is the number of frames from the end to include (e.g., 10 means last 10 frames).
22-
#' If tstar_type="time", this is the time point (in minutes) after which all frames
22+
#' If tstar_type="time", this is the time point (in minutes) after which all frames
2323
#' with midpoints later than this time are included. This value can be estimated using \code{mrtm2_tstar}.
2424
#' Note that this t* differs from that of the non-invasive Logan plot (which is the point at which
2525
#' pseudo-equilibrium is reached). Rather, with MRTM1 and MRTM2, all frames
@@ -75,7 +75,7 @@ mrtm2 <- function(t_tac, reftac, roitac, k2prime, tstar = NULL, weights = NULL,
7575

7676
# Convert timeStartEnd to frameStartEnd if needed
7777
if (is.null(frameStartEnd) && !is.null(timeStartEnd)) {
78-
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
78+
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
7979
tail(which(t_tac <= timeStartEnd[2]), 1))
8080
}
8181

@@ -89,19 +89,6 @@ mrtm2 <- function(t_tac, reftac, roitac, k2prime, tstar = NULL, weights = NULL,
8989
tstar_type <- "frames"
9090
}
9191

92-
# Validate tstar_type
93-
if (!is.null(tstar)) {
94-
tstar_type <- match.arg(tstar_type, c("frames", "time"))
95-
96-
# Convert tstar based on type
97-
if (tstar_type == "time") {
98-
frames_after_tstar <- which(t_tac >= tstar)
99-
tstarIncludedFrames <- length(frames_after_tstar)
100-
} else {
101-
tstarIncludedFrames <- tstar
102-
}
103-
}
104-
10592
# Tidying
10693

10794
tidyinput <- tidyinput_ref(t_tac, reftac, roitac, weights, frameStartEnd)
@@ -116,6 +103,19 @@ mrtm2 <- function(t_tac, reftac, roitac, k2prime, tstar = NULL, weights = NULL,
116103
roitac <- tidyinput$roitac
117104
weights <- tidyinput$weights
118105

106+
# Validate tstar_type
107+
if (!is.null(tstar)) {
108+
tstar_type <- match.arg(tstar_type, c("frames", "time"))
109+
110+
# Convert tstar based on type
111+
if (tstar_type == "time") {
112+
frames_after_tstar <- which(t_tac >= tstar)
113+
tstarIncludedFrames <- length(frames_after_tstar)
114+
} else {
115+
tstarIncludedFrames <- tstar
116+
}
117+
}
118+
119119
if (is.null(tstarIncludedFrames)) {
120120
tstarIncludedFrames <- length(reftac)
121121
}
@@ -236,7 +236,7 @@ plot_mrtm2fit <- function(mrtm2out, roiname = NULL, refname = NULL) {
236236
refname <- "Reference"
237237
}
238238

239-
measured <- dplyr::rename(measured,
239+
measured <- dplyr::rename(measured,
240240
!!paste0(roiname, ".measured") := ROI.measured,
241241
!!refname := Reference
242242
)
@@ -305,7 +305,7 @@ plot_mrtm2fit <- function(mrtm2out, roiname = NULL, refname = NULL) {
305305
mrtm2_tstar <- function(t_tac, reftac, lowroi, medroi, highroi, k2prime, filename = NULL, frameStartEnd = NULL, timeStartEnd = NULL, gridbreaks = 2) {
306306
# Convert timeStartEnd to frameStartEnd if needed
307307
if (is.null(frameStartEnd) && !is.null(timeStartEnd)) {
308-
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
308+
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
309309
tail(which(t_tac <= timeStartEnd[2]), 1))
310310
}
311311

R/kinfitr_patlakplot.R

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,6 @@ Patlakplot <- function(t_tac, tac, input, tstar, weights = NULL,
9595
warning("No value specified for tstar: defaulting to including all frames. This may produce biased outcomes.", call. = FALSE)
9696
}
9797

98-
# Convert tstar based on type
99-
if (tstar_type == "time") {
100-
frames_after_tstar <- which(t_tac >= tstar)
101-
tstarIncludedFrames <- length(frames_after_tstar)
102-
} else {
103-
tstarIncludedFrames <- tstar
104-
}
105-
10698
# Tidying
10799

108100
tidyinput <- tidyinput_art(t_tac, tac, weights, frameStartEnd)
@@ -112,6 +104,15 @@ Patlakplot <- function(t_tac, tac, input, tstar, weights = NULL,
112104
weights <- tidyinput$weights
113105

114106

107+
# Convert tstar based on type
108+
if (tstar_type == "time") {
109+
frames_after_tstar <- which(t_tac >= tstar)
110+
tstarIncludedFrames <- length(frames_after_tstar)
111+
} else {
112+
tstarIncludedFrames <- tstar
113+
}
114+
115+
115116
newvals <- shift_timings(
116117
t_tac = t_tac,
117118
tac = tac,

R/kinfitr_refPatlak.R

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
#' time zero: if not included, it is added.
99
#' @param roitac Numeric vector of radioactivity concentrations in the target tissue for each frame. We include zero at time
1010
#' zero: if not included, it is added.
11-
#' @param tstar The t* specification for regression. If tstar_type="frames",
11+
#' @param tstar The t* specification for regression. If tstar_type="frames",
1212
#' this is the number of frames from the end to include (e.g., 10 means last 10 frames).
13-
#' If tstar_type="time", this is the time point (in minutes) after which all frames
13+
#' If tstar_type="time", this is the time point (in minutes) after which all frames
1414
#' with midpoints later than this time are included. This value can be estimated using \code{refPatlak_tstar}.
1515
#' @param tstar_type Either "frames" (default) or "time", specifying how to interpret tstar.
1616
#' @param tstarIncludedFrames Deprecated. Use 'tstar' with 'tstar_type="frames"' instead.
@@ -50,7 +50,7 @@ refPatlak <- function(t_tac, reftac, roitac, tstar, weights = NULL,
5050

5151
# Convert timeStartEnd to frameStartEnd if needed
5252
if (is.null(frameStartEnd) && !is.null(timeStartEnd)) {
53-
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
53+
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
5454
tail(which(t_tac <= timeStartEnd[2]), 1))
5555
}
5656

@@ -74,14 +74,6 @@ refPatlak <- function(t_tac, reftac, roitac, tstar, weights = NULL,
7474
warning("No value specified for tstar: defaulting to including all frames. This may produce biased outcomes.", call. = FALSE)
7575
}
7676

77-
# Convert tstar based on type
78-
if (tstar_type == "time") {
79-
frames_after_tstar <- which(t_tac >= tstar)
80-
tstarIncludedFrames <- length(frames_after_tstar)
81-
} else {
82-
tstarIncludedFrames <- tstar
83-
}
84-
8577
# Tidying
8678

8779
tidyinput <- tidyinput_ref(t_tac, reftac, roitac, weights, frameStartEnd)
@@ -96,6 +88,13 @@ refPatlak <- function(t_tac, reftac, roitac, tstar, weights = NULL,
9688
roitac <- tidyinput$roitac
9789
weights <- tidyinput$weights
9890

91+
# Convert tstar based on type
92+
if (tstar_type == "time") {
93+
frames_after_tstar <- which(t_tac >= tstar)
94+
tstarIncludedFrames <- length(frames_after_tstar)
95+
} else {
96+
tstarIncludedFrames <- tstar
97+
}
9998

10099
# Parameters
101100

@@ -243,7 +242,7 @@ plot_refPatlakfit <- function(refpatlakout, roiname = NULL) {
243242
refPatlak_tstar <- function(t_tac, reftac, lowroi, medroi, highroi, filename = NULL, frameStartEnd = NULL, timeStartEnd = NULL, gridbreaks = 2) {
244243
# Convert timeStartEnd to frameStartEnd if needed
245244
if (is.null(frameStartEnd) && !is.null(timeStartEnd)) {
246-
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
245+
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
247246
tail(which(t_tac <= timeStartEnd[2]), 1))
248247
}
249248

0 commit comments

Comments
 (0)