Skip to content

likelihood() function needs parameters as explicit numeric #311

Description

@avallecam

Is it expected that epichains::likelihood() needs explicit numeric input parameters, which are not required for epichains::simulate_chains()?

In reprex, I needed to force as.numeric(param_vector["mu"]).

set.seed(121)
# randomly generate 20 chains of size 1 to 10
chain_sizes <- sample(1:10, 20, replace = TRUE)
param_vector <- c(mu = 0.6, size = 0.02)

param_vector
#>   mu size 
#> 0.60 0.02

# works
epichains::simulate_chains(
  n_chains = 10,
  statistic = "size",
  offspring_dist = rnbinom,
  mu = param_vector["mu"],
  size = param_vector["size"],
  generation_time = function(n) rep(3, n)
)
#> `<epichains>` object
#> 
#> < epichains head (from first known infector) >
#> 
#>    chain infector infectee generation time
#> 11     2        1        2          2    3
#> 
#> 
#> Number of chains: 10
#> Number of infectors (known): 2
#> Number of generations: 2
#> Use `as.data.frame(<object_name>)` to view the full output in the console.

# works
epichains::likelihood(
  chains = chain_sizes,
  statistic = "size",
  offspring_dist = rnbinom,
  mu = as.numeric(param_vector["mu"]),
  size = as.numeric(param_vector["size"])
)
#> [1] -96.3688

# not works
epichains::likelihood(
  chains = chain_sizes,
  statistic = "size",
  offspring_dist = rnbinom,
  mu = param_vector["mu"],
  size = param_vector["size"]
)
#> Error in (function (x, size, prob, mu) : unused arguments (mu.mu = 0.6, size.size = 0.02)

Created on 2025-07-14 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingshort-termasap and before august 2025 ends

    Type

    No type

    Projects

    Status
    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions