Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 556ae2b
  • /
  • MSD_fit.R
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:25bac37888e93a758472386a704c4ff66268a265
directory badge
swh:1:dir:556ae2bc64148ce20ea1932926caefc179fe614c

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
MSD_fit.R


track_msd_fit <- function(x,n=5,fitzero=T,framerate=1/33,pxsize=100,offset=4*0.01^2){

  #apply function for every track (column V4)
  coef <- ddply(x[,-6],.variables = "track", function(x) {
    mst <- t(x[,-1])
    time <- seq(1,length(mst),1)
    time <- time/framerate/1000 #covert frame to second
    #plot(mst,ylim=c(0,0.5),xlim=c(0,10))

    if(fitzero){

      mst <- mst-offset

      fit <- tryCatch(lm(formula = mst ~ time-1), error=function(e) NULL)

    } else if (fitzero==FALSE) {

      fit <- tryCatch(nls(formula = mst[,1] ~ time*x1+x2,lower = list(x1=0,x2=0),start=list(x1=0,x2=0),algorithm = "port"), error=function(e) NULL)
    }
    if (!is.null(fit)){
      RSS.p <- sum(residuals(fit)^2)
      TSS <- sum((mst - mean(mst,na.rm = T))^2,na.rm = T)
      rsq <- 1-(RSS.p/TSS)

      coef <- c(coef(fit)[1],offset,rsq)
      coef[1] <- coef[1]/4
      return(coef)

    }

    # MSD=4*D*t


  })
  names(coef) <-  c("track","D","intercept","Rsquared")#,paste("dx_",1:n,sep=""),paste("N_",1:n,sep=""))

  return (coef)
}

TRACK_MSD_fit <- function(x,n,fitzero,framerate,pxsize,offset){
  UseMethod("TRACK_MSD_fit")
}

TRACK_MSD_fit.default <- function(x,n=5,fitzero=T,framerate=1/33,pxsize=100,offset=4*0.01^2){
  stop("MSD_fit requires data frame")
}

TRACK_MSD_fit.data.frame <-  function(x,n=5,fitzero=T,framerate=1/33,pxsize=100,offset=4*0.01^2){
  track_msd_fit(x,n,fitzero,framerate,pxsize,offset)

}

TRACK_MSD_fit.list <-  function(x,n=5,fitzero=T,framerate=1/33,pxsize=100,offset=4*0.01^2){
  llply(x,.progress = "text",function(x){
    out <- TRACK_MSD_fit(x,n,fitzero,framerate,pxsize,offset)
    out$cellID <- x$cellID[1]
    return(out)
  })
}

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API