Coder Social home page Coder Social logo

kinfitr's Introduction

๏ฟฝ๏ฟฝ# mathesong

kinfitr's People

Contributors

mathesong avatar mnoergaard avatar nakulrrraval avatar pontusps avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

kinfitr's Issues

Bug in blmod_exp, unused argument (startpars)

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! ๐Ÿ˜ƒ

jsondata no longer part of pbr28 dataset

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")

Error in `blmod_exp_startpars()` when end of AIF contains zero values

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)

Rethink input

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:

  • Enable modelling of the raw data
  • Decrease the size of the input object in the output of fits
  • Allow for interpolation of different extents

When it comes to modelling, there should be the possibility of a few different things:

  • Certain models can be included in the package, but the diversity is nearly infinite
    • fit parameters (for canned models), fit objects (for user-models) and fitted values (for externally fitted data)
  • Weights should be possible to be added too.

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).

img_20190211_101732__01
)

Fix up the tstar finders

A few things need to be done to sort out the tstar finders, because they're currently pretty ugly.

  • They should return a plot, and optionally an image too
  • The functions need to be genericised
  • They need frameStartEnd input arguments

FIX: change units for metabolite_parent_fraction in BIDS blood data to arbitrary

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.

twotcm with purrr:pmap does not work after updating to 0.3.0 version - throws error

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.

kinfitr:::bd_tidy_times throws a too inclusive error message

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.