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

https://github.com/emkcosta/KillifishAutomaticFeederPaper
08 June 2025, 20:12:30 UTC
  • Code
  • Branches (2)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/add-license-1
    • refs/heads/main
    • 451bc5d78cd266a00b53612585d201d404f73920
    No releases to show
  • 336b4b1
  • /
  • Fig4_SuppFig4
  • /
  • gompertz.jl
Raw File Download
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

Permalinks

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
  • revision
  • snapshot
origin badgecontent badge Iframe embedding
swh:1:cnt:5a3022f5987cbe2a2d3faaf490292591bb9e0ed6
origin badgedirectory badge Iframe embedding
swh:1:dir:8a499e0c074c721e8839328c2e26c39d0c5d5c31
origin badgerevision badge
swh:1:rev:451bc5d78cd266a00b53612585d201d404f73920
origin badgesnapshot badge
swh:1:snp:a9f2e10f0b2ec00bc74865a9a1af5fd0004baa95
Citations

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
  • revision
  • snapshot
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 ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: 451bc5d78cd266a00b53612585d201d404f73920 authored by Emma on 24 October 2022, 20:33:32 UTC
Delete SuppFig2 directory
Tip revision: 451bc5d
gompertz.jl
using DelimitedFiles, Plots, Dates

cd(joinpath(ENV["HOME"], "Dropbox", "KillifishFeederPaper_AndrewMcKay","Revision", "Code", "Fig4"))

function createhazardrate(df, win)
    headers = df[2]
    df = df[1]
    # get rid of censored
    ObservedIndex = findall(p -> p == "Observed", headers)[1][2] + 1
    WeeksIndex = findall(p -> p == "Lifespan_3weeks", headers)[1][2] + 1
    df = df[df[:,ObservedIndex] .==1,:]
    lifespans = df[:,WeeksIndex]
    hz = []
    for t in 1:win:maximum(df[:,WeeksIndex])+1
        # deaths in the time window
        Dx = count(p -> t <= p < t+win, lifespans)
        #Dx = count(p -> t < p <= t+win, lifespans)
        # individuals at risk
        Nx = count(p -> p >= t, lifespans)
        #Nx = count(p -> p > t, lifespans)
        # hazard function
        hzr = Dx/Nx
        push!(hz, [t hzr])
    end
    hz = vcat(hz...)
    # hazard rate
    #hz[:,2] = -log.(1 .- hz[:,2])
    # LN of hazard rate?
  #  hz[:,2] = log.(hz[:,2])

    return hz
end

function plotgompertz(hz, IMR, RoA)
    p =scatter(hz[:,1], hz[:,2], leg = false)
    f(x) = log(IMR) + x*(RoA)
    plot!(f, 0:maximum(hz[:,1]), leg = false)
    return p
end

function plotgompertz(hz, IMR, RoA, label, hz2, IMR2, RoA2, label2)
    p =scatter(hz[:,1], hz[:,2], label = label, color = "red")
    scatter!(p, hz2[:,1], hz2[:,2], label = label2, color = "blue")
    f(x) = (RoA)*x + log(IMR)
    plot!(f, 0:maximum(hz[:,1]),  label = label, color = "red")
    g(x) = (RoA2)*x + log(IMR2)
    plot!(g, 0:maximum(hz2[:,1]),  label = label2, color = "blue")
    return p
end

function lnhaz(hz)
    hz = hz[hz[:,2] .!= Inf, :]
    hz = hz[hz[:,2] .!= -Inf, :]
    hz = hz[hz[:,2] .!= 0, :]
    hz = hz[.!isnan.(hz[:,2]), :]
    hz[:,2] = log.(hz[:,2])
    return hz
end

function convertplotlife(df, win, IMR, RoA)
    hz = createhazardrate(df, win)
    hz= lnhaz(hz)
    plotgompertz(hz, IMR, RoA)
end

function convertplotlife(df1, IMR1, RoA1, label1, df2, IMR2, RoA2, label2,  win)
    hz1 = createhazardrate(df1, win)
    hz2 = createhazardrate(df2, win)
    hz1= lnhaz(hz1)
    hz2= lnhaz(hz2)
    return plotgompertz(hz1, IMR1, RoA1, label1, hz2, IMR2, RoA2, label2)
end

##################################################################

##################################################################
# male (after processing with GompertzCalcs.R)
##################################################################
#
dfmal = readdlm("male_al.csv", ',',header =true)
dfmdr = readdlm("male_dr.csv", ',', header =true)

#hzdfmal = lnhaz(createhazardrate(dfmal, 1))
#scatter(hzdfmal[:,1], hzdfmal[:,2])

#hzdfmdr = lnhaz(createhazardrate(dfmdr, 1))
#scatter!(hzdfmdr[:,1], hzdfmdr[:,2])

# These values come from Fig4.R
shape =0.3388
rate =0.0385
IMRal = rate
RoAal = shape

#convertplotlife(dfmal, 1, IMRal, RoAal)

# These values come from Fig4.R
shape=0.1457
rate =0.0557
IMRdr = rate
RoAdr = shape

#convertplotlife(dfmdr, 1, IMRdr, RoAdr)

# NOTE: these are in 3 week intervals
p = convertplotlife(dfmal, IMRal, RoAal, "AL", dfmdr, IMRdr, RoAdr, "DR", 1)
dirout = "KillifishFeederPaper_AndrewMcKay"
savefig(p, joinpath(ENV["HOME"], "Dropbox/$dirout/Revision/Code/Fig4/secondcohortMales_ALvsDRGompertz_flexsurvreg.pdf"))

Software Heritage — Copyright (C) 2015–2025, 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— Contact— JavaScript license information— Web API

back to top