epiverse-trace / quickfit

[SUSPENDED] Toolbox of model fitting helper functions
https://epiverse-trace.github.io/quickfit/
Other
2 stars 1 forks source link

Formula based and survival model fitting #11

Open joshwlambert opened 1 year ago

joshwlambert commented 1 year ago

Sure. survival::survreg() actually computes two loglikelihoods, one for the baseline and one for the full models. So, in this case, we get four loglikelihoods for two models.

library(survival)

# Define fitting function

fit_survreg <- function(data, dist, ...) {
  survival::survreg(
    data = data,
    dist = dist,
    formula = Surv(futime, fustat) ~ ecog.ps + rx, # taken from ?survival::survreg
    scale = 1
  )
}

# Apply multi_fitdist

multi_fitdist(
  data = survival::ovarian,
  models = c(dist = "lognormal", dist = "weibull"),
  func = fit_survreg
)

# Results

     models  loglik.1  loglik.2      aic      bic
1   weibull -96.24333 -97.19804 196.4867 199.0029
2   weibull -96.24333 -97.19804 198.3961 200.9123
3 lognormal -97.74229 -98.03220 199.4846 202.0008
4 lognormal -97.74229 -98.03220 200.0644 202.5806

Created on 2023-05-19 with [reprex v2.0.2](https://reprex.tidyverse.org/)

_Originally posted by @jamesmbaazam in https://github.com/epiverse-trace/quickfit/pull/6#discussion_r1199000779_