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

Revision b45bed846d8e04eeb29a107dbe3d817f5a3b20f7 authored by Maarten Paul on 04 January 2021, 21:06:39 UTC, committed by GitHub on 04 January 2021, 21:06:39 UTC
Update README.md
1 parent 88146b9
  • Files
  • Changes
  • 54199e0
  • /
  • R
  • /
  • 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.

  • revision
  • directory
  • content
revision badge
swh:1:rev:b45bed846d8e04eeb29a107dbe3d817f5a3b20f7
directory badge
swh:1:dir:db804ffc182ff31af707e8611c61b1d6fb479105
content badge
swh:1:cnt:430a950022fa52692376c10408fb9ff9f43884c3

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.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
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,dim=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 #convert 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]/(2*dim)
      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,dim){
  UseMethod("TRACK_MSD_fit")
}

TRACK_MSD_fit.default <- function(x,n=5,fitzero=T,framerate=1/33,pxsize=100,offset=4*0.01^2,dim=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,dim=2){
  track_msd_fit(x,n,fitzero,framerate,pxsize,offset,dim)

}

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

The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

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