Skip to contents

Computes the joined likelihood of all the events in an individual life-history (time of maturity, reproductive events, death) and estimates the parameters of the model using maximum likelihood.

Usage

lifelihood(
  lifelihoodData,
  path_config,
  path_to_Lifelihood = NULL,
  param_bounds_df = NULL,
  group_by_group = FALSE,
  MCMC = 0,
  interval = 25,
  SEcal = FALSE,
  saveprobevent = 0,
  fitness = 0,
  r = 0,
  seeds = NULL,
  ntr = 2,
  nst = 2,
  To = 50,
  Tf = 1,
  climbrate = 1,
  precision = 0.001,
  raise_estimation_warning = TRUE,
  delete_temp_files = TRUE
)

Arguments

lifelihoodData

lifelihoodData object created with lifelihoodData().

path_config

A character string specifying the file path to the YAML configuration file.

path_to_Lifelihood

A character string specifying the file path to the compile Lifelihood program (default is NULL)

param_bounds_df

Dataframe with the parameter ranges/boundaries/boundaries

group_by_group

Boolean option to fit the full factorail model with all the interactions between each of the factors

MCMC

Perform MCMC sampling of the parameter after convergence to estimate their 95% confidence interval

interval

TBD - Check the actual meaning

SEcal

If TRUE, Lifelihood computes the standard error of each parameter using the Hessian matrix (output with value of -1 if standard error cannot be computed due to singularity of the Hessian matrix)

saveprobevent

TBD - Check the actual meaning

fitness

Reparametrize the model with one parameter as the lifetime reproductive success

r

Reparametrize the model with one parameter as the intrinsic rate of increase

seeds

Numbers used to reproduce results (same seeds = same results). This must be a vector of length 4.

ntr

Number of thread for the paralelisation ?

nst

TBD - Check the actual meaning

To

Initial temperature for the simulated annealing

Tf

Initial temperature for the simulated annealing

climbrate

Rate for the simulated annealing ?

precision

TBD - Check the actual meaning

raise_estimation_warning

Whether or not to raise a warning when the estimate of a parameter is too close to its minimum or maximum bound. Default is TRUE.

delete_temp_files

Indicates whether temporary files should be deleted. TRUE by default and recommended.

Value

A lifelihoodResults object

Examples

library(lifelihood)
library(tidyverse)

df <- fakesample |>
  mutate(
    geno = as.factor(geno),
    type = as.factor(type)
  )
head(df)
#>   type geno sex_start sex_end sex mat_start mat_end clutch_start1 clutch_end1
#> 1    1    0         0    1000   0         0    1000            NA          NA
#> 2    2    0         0    1000   0         2       3             4           3
#> 3    0    1         0    1000   0         3       4             2           4
#> 4    0    1         0    1000   0         3       4             2           4
#> 5    0    1         0    1000   0         3       4             2           4
#> 6    1    0         0    1000   0         0    1000            NA          NA
#>   clutch_size1 clutch_start2 clutch_end2 clutch_size2 death_start death_end
#> 1           NA            NA          NA           NA         0.1         1
#> 2            4             2           4            5         9.0        10
#> 3            5            NA          NA           NA         5.0         6
#> 4            5            NA          NA           NA         5.0         6
#> 5            5            NA          NA           NA         5.0         6
#> 6           NA            NA          NA           NA         0.1         1

clutchs <- c(
  "clutch_start1", "clutch_end1", "clutch_size1",
  "clutch_start2", "clutch_end2", "clutch_size2"
)

dataLFH <- lifelihoodData(
  df = df,
  sex = "sex",
  sex_start = "sex_start",
  sex_end = "sex_end",
  maturity_start = "mat_start",
  maturity_end = "mat_end",
  clutchs = clutchs,
  death_start = "death_start",
  death_end = "death_end",
  covariates = c("geno", "type"),
  model_specs = c("gam", "lgn", "wei")
)

results <- lifelihood(
  lifelihoodData = dataLFH,
  path_config = get_config_path("config"),
  seeds = c(1, 2, 3, 4),
  raise_estimation_warning = FALSE
)
summary(results)
#> LIFELIHOOD RESULTS
#> 
#> Likelihood:
#> [1] -829.0578
#> 
#> Effects:
#>                                       name   estimation stderror
#> 1                           int_expt_death -14.95337701        0
#> 2                    eff_expt_death_geno_1   2.27064527        0
#> 3                    eff_expt_death_type_1  -9.55371757        0
#> 4                    eff_expt_death_type_2   0.53315647        0
#> 5                       int_survival_shape  10.28792377        0
#> 6                eff_survival_shape_geno_1  -1.93963186        0
#> 7                eff_survival_shape_type_1   7.57026237        0
#> 8                eff_survival_shape_type_2   4.74998927        0
#> 9         eff_survival_shape_type_1:geno_1  -0.24718760        0
#> 10        eff_survival_shape_type_2:geno_1   3.52427897        0
#> 11                    int_ratio_expt_death  -1.45299283        0
#> 12             eff_ratio_expt_death_geno_1   3.02680049        0
#> 13                          int_prob_death -17.15815657        0
#> 14                   eff_prob_death_geno_1   0.02066385        0
#> 15                       int_expt_maturity  -0.07781130        0
#> 16                eff_expt_maturity_geno_1  -0.34729932        0
#> 17                eff_expt_maturity_type_1  -0.76380036        0
#> 18                eff_expt_maturity_type_2  -0.75476253        0
#> 19                      int_maturity_shape -10.02261060        0
#> 20               eff_maturity_shape_geno_1  -3.30865726        0
#> 21                 int_ratio_expt_maturity   1.74264178        0
#> 22          eff_ratio_expt_maturity_geno_1   3.36233997        0
#> 23          eff_ratio_expt_maturity_type_1  -2.79189482        0
#> 24          eff_ratio_expt_maturity_type_2  -4.87384990        0
#> 25                   int_expt_reproduction  -1.79104715        0
#> 26            eff_expt_reproduction_geno_1  -0.89759305        0
#> 27                               int_pontn  -2.96400432        0
#> 28                        eff_pontn_geno_1  -1.03064224        0
#> 29               int_increase_death_hazard   3.32326622        0
#> 30        eff_increase_death_hazard_geno_1   2.18470307        0
#> 31        eff_increase_death_hazard_type_1  -0.38970742        0
#> 32        eff_increase_death_hazard_type_2  -3.84713473        0
#> 33 eff_increase_death_hazard_type_1:geno_1  -1.13985166        0
#> 34 eff_increase_death_hazard_type_2:geno_1  -3.69784224        0
#> 35                  int_tof_reduction_date  -1.27913674        0
#> 36           eff_tof_reduction_date_geno_1  -3.51198283        0
#> 37            int_increase_tof_n_offspring   0.24026695        0
#> 38     eff_increase_tof_n_offspring_geno_1  -0.32428130        0
#> 39                 int_lin_decrease_hazard   0.81074061        0
#> 40          eff_lin_decrease_hazard_geno_1   0.19505972        0
#> 41          eff_lin_decrease_hazard_type_1   5.50927699        0
#> 42          eff_lin_decrease_hazard_type_2  -0.85842716        0
#> 43   eff_lin_decrease_hazard_type_1:geno_1   3.98397092        0
#> 44   eff_lin_decrease_hazard_type_2:geno_1   0.69812447        0
#> 45                     int_quad_senescence  -0.49711337        0
#> 46              eff_quad_senescence_geno_1   0.47173154        0
#> 47                int_quad_decrease_hazard  -0.07370047        0
#> 48         eff_quad_decrease_hazard_geno_1  -0.14027753        0
#> 49             int_quad_change_n_offspring   0.07862816        0
#> 50      eff_quad_change_n_offspring_geno_1   0.00640363        0
#> 51                     int_tof_n_offspring  -0.21320110        0
#>                   parameter        kind        event
#> 1                expt_death   intercept    mortality
#> 2                expt_death coefficient    mortality
#> 3                expt_death coefficient    mortality
#> 4                expt_death coefficient    mortality
#> 5            survival_shape   intercept    mortality
#> 6            survival_shape coefficient    mortality
#> 7            survival_shape coefficient    mortality
#> 8            survival_shape coefficient    mortality
#> 9            survival_shape coefficient    mortality
#> 10           survival_shape coefficient    mortality
#> 11         ratio_expt_death   intercept    mortality
#> 12         ratio_expt_death coefficient    mortality
#> 13               prob_death   intercept    mortality
#> 14               prob_death coefficient    mortality
#> 15            expt_maturity   intercept     maturity
#> 16            expt_maturity coefficient     maturity
#> 17            expt_maturity coefficient     maturity
#> 18            expt_maturity coefficient     maturity
#> 19           maturity_shape   intercept     maturity
#> 20           maturity_shape coefficient     maturity
#> 21      ratio_expt_maturity   intercept     maturity
#> 22      ratio_expt_maturity coefficient     maturity
#> 23      ratio_expt_maturity coefficient     maturity
#> 24      ratio_expt_maturity coefficient     maturity
#> 25        expt_reproduction   intercept reproduction
#> 26        expt_reproduction coefficient reproduction
#> 27                    pontn   intercept reproduction
#> 28                    pontn coefficient reproduction
#> 29    increase_death_hazard   intercept reproduction
#> 30    increase_death_hazard coefficient reproduction
#> 31    increase_death_hazard coefficient reproduction
#> 32    increase_death_hazard coefficient reproduction
#> 33    increase_death_hazard coefficient reproduction
#> 34    increase_death_hazard coefficient reproduction
#> 35       tof_reduction_date   intercept reproduction
#> 36       tof_reduction_date coefficient reproduction
#> 37 increase_tof_n_offspring   intercept reproduction
#> 38 increase_tof_n_offspring coefficient reproduction
#> 39      lin_decrease_hazard   intercept reproduction
#> 40      lin_decrease_hazard coefficient reproduction
#> 41      lin_decrease_hazard coefficient reproduction
#> 42      lin_decrease_hazard coefficient reproduction
#> 43      lin_decrease_hazard coefficient reproduction
#> 44      lin_decrease_hazard coefficient reproduction
#> 45          quad_senescence   intercept reproduction
#> 46          quad_senescence coefficient reproduction
#> 47     quad_decrease_hazard   intercept reproduction
#> 48     quad_decrease_hazard coefficient reproduction
#> 49  quad_change_n_offspring   intercept reproduction
#> 50  quad_change_n_offspring coefficient reproduction
#> 51          tof_n_offspring   intercept reproduction
#>