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 withlifelihoodData()
.- 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.
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
)
#> [1] "/private/var/folders/y6/nj790rtn62lfktb1sh__79hc0000gn/T/Rtmp2lbF6M/temp_libpath1e0a2a79ba80/lifelihood/bin/lifelihood/Users/runner/work/Lifelihood/Lifelihood/lifelihood_1_2_3_4/temp_file_data_lifelihood.txt /Users/runner/work/Lifelihood/Lifelihood/lifelihood_1_2_3_4/temp_param_range_path.txt FALSE 0 25 FALSE 0 0 0 1 2 3 4 10 20 1000 0.3 NULL 2 2 50 1 1 0.001"
#> lifelihood Pascal program status code 0
summary(results)
#> LIFELIHOOD RESULTS
#>
#> Likelihood:
#> [1] -598.4095
#>
#> Effects:
#> name estimation stderror
#> 1 int_expt_death -17.78869453 0
#> 2 eff_expt_death_geno_1 -2.89709225 0
#> 3 eff_expt_death_type_1 -4.48279290 0
#> 4 eff_expt_death_type_2 -0.30099192 0
#> 5 int_survival_shape 6.14904518 0
#> 6 eff_survival_shape_geno_1 2.96787660 0
#> 7 eff_survival_shape_type_1 3.56630436 0
#> 8 eff_survival_shape_type_2 3.43958754 0
#> 9 eff_survival_shape_type_1:geno_1 -9.78904370 0
#> 10 eff_survival_shape_type_2:geno_1 5.39234946 0
#> 11 int_ratio_expt_death 7.51220924 0
#> 12 eff_ratio_expt_death_geno_1 4.47236458 0
#> 13 int_prob_death -19.85150681 0
#> 14 eff_prob_death_geno_1 -4.66755544 0
#> 15 int_expt_maturity -2.03877432 0
#> 16 eff_expt_maturity_geno_1 1.55444499 0
#> 17 eff_expt_maturity_type_1 0.66072953 0
#> 18 eff_expt_maturity_type_2 -0.65520063 0
#> 19 int_maturity_shape -6.13510368 0
#> 20 eff_maturity_shape_geno_1 -12.66969959 0
#> 21 int_ratio_expt_maturity 9.21718291 0
#> 22 eff_ratio_expt_maturity_geno_1 6.29157951 0
#> 23 eff_ratio_expt_maturity_type_1 4.82061920 0
#> 24 eff_ratio_expt_maturity_type_2 10.81747842 0
#> 25 int_expt_reproduction -4.45837175 0
#> 26 eff_expt_reproduction_geno_1 -5.55089666 0
#> 27 int_pontn -7.93134379 0
#> 28 eff_pontn_geno_1 -16.20606070 0
#> 29 int_increase_death_hazard 7.14071218 0
#> 30 eff_increase_death_hazard_geno_1 2.06010130 0
#> 31 eff_increase_death_hazard_type_1 2.45327099 0
#> 32 eff_increase_death_hazard_type_2 -3.24686063 0
#> 33 eff_increase_death_hazard_type_1:geno_1 0.05537952 0
#> 34 eff_increase_death_hazard_type_2:geno_1 0.48247027 0
#> 35 int_tof_reduction_date -5.98084468 0
#> 36 eff_tof_reduction_date_geno_1 4.27436871 0
#> 37 int_increase_tof_n_offspring 0.70052182 0
#> 38 eff_increase_tof_n_offspring_geno_1 7.73467571 0
#> 39 int_lin_decrease_hazard 2.66887494 0
#> 40 eff_lin_decrease_hazard_geno_1 -2.84465302 0
#> 41 eff_lin_decrease_hazard_type_1 -2.97177934 0
#> 42 eff_lin_decrease_hazard_type_2 3.88660973 0
#> 43 eff_lin_decrease_hazard_type_1:geno_1 -4.75747643 0
#> 44 eff_lin_decrease_hazard_type_2:geno_1 -0.28970093 0
#> 45 int_quad_senescence 2.49832143 0
#> 46 eff_quad_senescence_geno_1 -2.71133455 0
#> 47 int_quad_decrease_hazard -0.06403036 0
#> 48 eff_quad_decrease_hazard_geno_1 0.09121032 0
#> 49 int_quad_change_n_offspring 1.60524468 0
#> 50 eff_quad_change_n_offspring_geno_1 -0.07882676 0
#> 51 int_tof_n_offspring -0.26241118 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
#>