mathesong / kinfitr Goto Github PK
View Code? Open in Web Editor NEWkinfitr: PET Kinetic Modelling Using R
License: Other
kinfitr: PET Kinetic Modelling Using R
License: Other
Hi,
Great package, I really enjoy using it.
I was playing around with fitting input functions and I think i discovered a bug in the blmod_exp
function.
blooddata <- create_blooddata_bids(kinfitr::pbr28$jsondata[[1]])
blooddata <- bd_blood_dispcor(blooddata)
aif <- bd_getdata(blooddata, output = "AIF")
blood_fit <- blmod_exp(aif$time,
aif$aif,
Method = aif$Method, multstart_iter = 1)
Works as intended. However, when you define starting parameters yourself, then it buggs out:
startpars <- blood_fit$par
blood_fit2 <- blmod_exp(aif$time,
aif$aif,
Method = aif$Method, multstart_iter = 1, start = startpars)
Produces:
Error in purrr::map(startvals, ~(.x - abs(.x * 0.5))) :
object 'startvals' not found
I think startvals
never gets defined when the user supply inputarg start
, but then the code calls on startvals
at a later point anyways (e.g. line 16 and 25).
Hope it can be solved whenever you have the time!
In case anyone else runs into this issue, I'm trying to follow your blog (post)[https://www.granvillematheson.com/post/nonlinear-modelling-using-nls-nlme-and-brms/], but am am getting the following error when initially looking at the data
data(pbr28)
pbr28$jsondata[[1]]$Metabolite
## Warning: Unknown or uninitialised column: `jsondata`.
## NULL
I looked at the code in data-raw/pbr28_data_extraction.R
and found the following
bidsdat <- jsondat %>%
group_by(Subjname, PETNo) %>%
mutate(petinfo = map(jsondata, jsondat2petinfo),
blooddata = map(jsondata, jsondat2bd),
tactimes = map(jsondata, jsondat2tactimes)) %>%
select(-jsondata)
I have forked your repo and tried removing that line, installing the package from my repo, but that didn't fix things. I was able to work around this problem by installing an earlier version of your package. using remotes::install_github("mathesong/kinfitr", ref = "6ba08e7")
Hi,
Love the package, keep up the good work!
I was playing around with fitting input functions, and I think I found a potential issue in blmod_exp_startpars()
. When I have noisy data and get some negative values at the end of my AIF I would like to set them to zero. However, doing so means that line 20 bugs out, were it tries to do some fitting of the end of the AIF:
exp3_mod <- lm(log(abs(activity)) ~ time, data = blood_exp_part3)
Produces
Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
NA/NaN/Inf in 'y'
I assume this is due to log(abs(0))
producing -Inf
. Perhaps any zero values inside blood_exp_part3
can be filtered out?
Here's a reproducible example (I think):
blooddata <- create_blooddata_bids(kinfitr::pbr28$jsondata[[1]])
blooddata <- bd_blood_dispcor(blooddata)
aif <- bd_getdata(blooddata, output = "AIF")
aif$aif[length(aif$aif)] <- 0
blood_fit <- blmod_exp(aif$time,
aif$aif,
Method = aif$Method, multstart_iter = 1)
At present, the input data frame makes it difficult to perform modelling, and it's too large to include in outputs.
The goals of this issue are to:
When it comes to modelling, there should be the possibility of a few different things:
Considering having a blooddata
object, as well as an input
object, which makes it easier to keep existing functions. But the idea is to include the blooddata object in the input and output of kinetic models, and to interpolate it within. Or perhaps allow user input of input
objects too just in case there's an edge case which makes it more convenient (consider).
All outputs need classes
A few things need to be done to sort out the tstar finders, because they're currently pretty ugly.
According to the BIDS-specification it was chosen to have arbitrary units as "arbitrary" instead of "unitless" as previously defined in the PET-BIDS specification. Currently, the https://github.com/mathesong/kinfitr/blob/master/R/kinfitr_bids.R used to parse blood data in BIDS only allows "unitless" and hence produces an error when parsing the data.
Solution: To update the code in https://github.com/mathesong/kinfitr/blob/master/R/kinfitr_bids.R to have "arbitrary" instead of "unitless" for the metabolite_parent_fraction.
At present the dispersion correction method only handles a single interval between measurements, and if this changes, then it needs to interpolate. It it also important that it can return the values, with the same times as in the original. This is currently not possible if the intervals differ.
After the upgrading to v0.3.0 i get an weird error using kinfitr::twotcm
and purrr:pmap
, se below:
#Make function for fitting 2TCM
fit2tcm <- function(tacs, input, delayFit) {
twotcm(t_tac = tacs$time, tac = tacs$TAC, input = input, weights = tacs$Weights,
inpshift = delayFit$par$inpshift, vB=delayFit$par$vB)
}
#Fit 2TCM
TidyDataNestedLong %>%
mutate(fit_2tcm = pmap(list(TACs, input, delayFit), fit2tcm))
Throws the following error:
Error in mutate_impl(.data, dots) :
Evaluation error: argument 6 matches multiple formal arguments.
When I downgrade to kinfitr 0.2.0 everything works beautifully, so I'm pretty sure that its something funky with 0.3.0. I cant find anything in the documentation suggesting that the code above is missing a newly added mandatory inarg. Not sure but looks like the only thing that's new is the nls.multstart inarg. Did something maybe go funky-wonky when this was added to kinfitr::twotcm
?
For now, my quick-fix is to just run kinfitr::twotcm
on 0.2.0, then upgrade to 0.3.0 and then run everything else.
Edit: Downgrading gets around the error above for now: devtools::install_github("mathesong/[email protected]")
but means that nls.multstart can't be used.
Hi, awesome package - I use it every day!
I found that when you miscode some dplyr
syntax and calls on kinfitr::bd_extract()
, the function returns an error message that is not relevant for the coding error the user commits. E.g.:
library(tidyverse)
library(kinfitr)
alldat <- kinfitr::pbr28
aif.data <- kinfitr::bd_extract(blooddata = alldat$tacs,
output = 'AIF',
what = 'raw')
Throws the following error message:
stop("It appears that you are using a blooddata object created using an\n older version of kinfitr, based on an older version of the PET BIDS\n standard. Ideally, please create your blooddata objects afresh.\n Otherwise, please use the update_blooddata_bids command to keep only\n the bare essentials.")
Since I'm running v0.6 of kinfitr I know that the blooddata is up to the latest bids-standard, so the reported error should only be about to the fact that the user gives the wrong input to kinfitr::bd_extract
(e.g., tacs
instead of e.g. blooddata[[1]]
here).
Basically I think the error catch inside kinfitr:::bd_tidy_times
is too "inclusive" and should, if possible, be made to only react when a truly deprecated blooddata structure is used as input.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.