Skip to content

Commit 73091da

Browse files
authored
Merge pull request #38 from mathesong/add_spline_tacfit
Add spline tacfit
2 parents 9bf8da7 + 37fa882 commit 73091da

14 files changed

+645
-16
lines changed

.Rbuildignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
^\.github$
66
^README.Rmd
77
^data-raw
8+
^CLAUDE\.md$
9+
^LICENSE\.md$
10+
^docker*

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: kinfitr
22
Title: Kinetic Modelling of PET Time Activity Curves
3-
Date: 2025-10-14
4-
Version: 0.9.0
3+
Date: 2025-10-23
4+
Version: 0.9.1
55
Authors@R: person("Granville", "Matheson", email = "[email protected]", role = c("aut", "cre"))
66
Description: This package calculates outcome parameters for PET data using time activity curves (TACs). This will allow for more reproducible PET modelling research.
77
Depends:

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ S3method(plot,blooddata)
44
S3method(plot,interpblood)
55
S3method(plot,kinfit)
66
S3method(predict,blmod)
7+
S3method(predict,spline_tac)
78
export("%>%")
89
export(Logan_tstar)
910
export(Loganplot)
@@ -105,6 +106,7 @@ export(plot_refLoganfit)
105106
export(plot_refPatlakfit)
106107
export(plot_refmlLoganfit)
107108
export(plot_residuals)
109+
export(plot_spline_tacfit)
108110
export(plot_srtm2fit)
109111
export(plot_srtm_vfit)
110112
export(plot_srtmfit)
@@ -122,6 +124,7 @@ export(refmlLogan)
122124
export(refmlLogan_tstar)
123125
export(shift_timings)
124126
export(shift_timings_df)
127+
export(spline_tac)
125128
export(srtm)
126129
export(srtm2)
127130
export(srtm2_model)

R/kinfitr_feng_1tc_ref.R

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@
1919
#' accommodate zero values in the TAC before rising. If FALSE, the TAC must
2020
#' rise at time = 0.
2121
#' @param frameStartEnd Optional. This allows one to specify the beginning and
22-
#' final frame to use for modelling, e.g. c(1,20).
22+
#' final frame to use for modelling, e.g. c(1,20). This can be used to assess
23+
#' time stability for example.
24+
#' @param timeStartEnd Optional. This allows one to specify the beginning and
25+
#' end time point instead of defining the frame numbers using frameStartEnd.
26+
#' This function will restrict the model to all time frames whose t_tac is
27+
#' between the values, i.e. c(0,5) will select all frames with midtimes
28+
#' during the first 5 minutes.
2329
#' @param multstart_iter Number of iterations for starting parameters. Default
2430
#' is 500. For more information, see
2531
#' \code{\link[nls.multstart]{nls_multstart}}.
@@ -49,8 +55,14 @@
4955
feng_1tc_tac <- function(t_tac, tac, weights = NULL,
5056
fit_t0 = TRUE,
5157
frameStartEnd = NULL,
58+
timeStartEnd = NULL,
5259
multstart_iter = 500) {
5360

61+
# Convert timeStartEnd to frameStartEnd if needed
62+
if (is.null(frameStartEnd) && !is.null(timeStartEnd)) {
63+
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
64+
tail(which(t_tac <= timeStartEnd[2]), 1))
65+
}
5466

5567
# Tidying
5668

R/kinfitr_ma1.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
#' Function to fit the MA1 of Ichise et al (2002) to data.
44
#'
55
#' @param t_tac Numeric vector of times for each frame in minutes. We use the time halfway through the frame as well as a
6-
#' zero. If a time zero frame is not included, it will be added.
6+
#' zero. If a time zero frame is not included, it will be added.
77
#' @param tac Numeric vector of radioactivity concentrations in the target tissue for each frame. We include zero at time
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{ma1_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.
@@ -63,7 +63,7 @@ ma1 <- function(t_tac, tac, input, tstar, weights = NULL,
6363

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

@@ -317,7 +317,7 @@ plot_ma1fit <- function(ma1out, roiname = NULL) {
317317
ma1_tstar <- function(t_tac, lowroi, medroi, highroi, input, filename = NULL, inpshift = 0, vB = 0, frameStartEnd = NULL, timeStartEnd = NULL, gridbreaks = 2) {
318318
# Convert timeStartEnd to frameStartEnd if needed
319319
if (is.null(frameStartEnd) && !is.null(timeStartEnd)) {
320-
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
320+
frameStartEnd <- c(which(t_tac >= timeStartEnd[1])[1],
321321
tail(which(t_tac <= timeStartEnd[2]), 1))
322322
}
323323

0 commit comments

Comments
 (0)