cxr_pm_multifit: Multi-species parameter optimization

View source: R/cxr_pm_multifit.R

cxr_pm_multifitR Documentation

Multi-species parameter optimization


This function is a wrapper for estimating parameters for several focal species, instead of making separate calls to cxr_pm_fit.


  model_family = c("BH"),
  focal_column = NULL,
  covariates = NULL,
  optimization_method = c("BFGS", "CG", "Nelder-Mead", "ucminf", "L-BFGS-B", "nlm",
    "nlminb", "Rcgmin", "Rvmmin", "spg", "bobyqa", "nmkb", "hjkb", "nloptr_CRS2_LM",
    "nloptr_ISRES", "nloptr_DIRECT_L_RAND", "DEoptimR", "GenSA"),
  alpha_form = c("none", "global", "pairwise"),
  lambda_cov_form = c("none", "global"),
  alpha_cov_form = c("none", "global", "pairwise"),
  initial_values = NULL,
  lower_bounds = NULL,
  upper_bounds = NULL,
  fixed_terms = NULL,
  bootstrap_samples = 0



named list in which each component is a dataframe with a fitness column and a number of columns representing neighbours


family of model to use. Available families are BH (Beverton-Holt), LV (Lotka-Volterra), RK (Ricker), and LW (Law-Watkinson). Users may also define their own families and models (see vignette 4).


character vector with the same length as data, giving the names of the columns representing intraspecific observations for each species, or numeric vector giving the position of such columns.


optional named list in which each component is a dataframe with values of each covariate for each observation. The ith component of covariates are the covariate values that correspond to the ith component of data, so they must have the same number of observations.


numerical optimization method.


what form does the alpha parameter take? one of "none" (no alpha in the model), "global" (a single alpha for all pairwise interactions), or "pairwise" (one alpha value for every interaction).


form of the covariate effects on lambda. Either "none" (no covariate effects) or "global" (one estimate per covariate).


form of the covariate effects on alpha. One of "none" (no covariate effects), "global" (one estimate per covariate on every alpha), or "pairwise" (one estimate per covariate and pairwise alpha)


list with components "lambda","alpha_intra","alpha_inter","lambda_cov", "alpha_cov", specifying the initial values for numerical optimization. Single values are allowed.


optional list with single values for "lambda","alpha_intra","alpha_inter","lambda_cov", "alpha_cov".


optional list with single values for "lambda","alpha_intra","alpha_inter","lambda_cov", "alpha_cov".


optional named list in which each component is itself a list containing fixed terms for each focal species.


number of bootstrap samples for error calculation. Defaults to 0, i.e. no error is calculated.


an object of class 'cxr_pm_multifit' which is a list with the following components:

  • model_name: string with the name of the fitness model

  • model: model function

  • data: data supplied

  • taxa: names of the taxa fitted

  • covariates: covariate data supplied

  • optimization_method: optimization method used

  • initial_values: list with initial values

  • fixed_terms: list with fixed terms

  • lambda: fitted values for lambda, or NULL if fixed

  • alpha_intra: fitted values for alpha_intra, or NULL if fixed

  • alpha_inter: fitted values for alpha_inter, or NULL if fixed

  • lambda_cov: fitted values for lambda_cov, or NULL if fixed

  • alpha_cov: fitted values for alpha_cov, or NULL if fixed

  • lambda_standard_error: standard errors for lambda, if computed

  • alpha_standard_error: standard errors for alpha, if computed

  • lambda_cov_standard_error: standard errors for lambda_cov, if computed

  • alpha_cov_standard_error: standard errors for alpha_cov, if computed

  • log_likelihood: log-likelihoods of the fits


# fit three species at once
data <- neigh_list[1:3]
# keep only fitness and neighbours columns
for(i in 1:length(data)){
  data[[i]] <- data[[i]][,2:length(data[[i]])]
# be explicit about the focal species
focal.sp <- names(data)
# covariates: salinity
salinity <- salinity_list[1:3]
# keep only salinity column
for(i in 1:length(salinity)){
  salinity[[i]] <- data.frame(salinity = salinity[[i]][,2:length(salinity[[i]])])

  fit_3sp <- cxr_pm_multifit(data = data,
                             optimization_method = "bobyqa",
                             model_family = "BH",
                             focal_column = focal.sp,
                             covariates = salinity,
                             alpha_form = "pairwise",
                             lambda_cov_form = "global",
                             alpha_cov_form = "global",
                             initial_values = list(lambda = 1,
                                                   alpha_intra = 0.1,
                                                   alpha_inter = 0.1,
                                                   lambda_cov = 0.1, 
                                                   alpha_cov = 0.1),
                             lower_bounds = list(lambda = 0.01,
                                                 alpha_intra = 0,
                                                 alpha_inter = 0,
                                                 lambda_cov = 0, 
                                                 alpha_cov = 0),
                             upper_bounds = list(lambda = 100,
                                                 alpha_intra = 1,
                                                 alpha_inter = 1,
                                                 lambda_cov = 1, 
                                                 alpha_cov = 1),
                             bootstrap_samples = 3)
  # brief summary
  # interaction matrix

cxr documentation built on Oct. 27, 2023, 1:08 a.m.