Compute loglik of NetSeries
hangjianli opened this issue · comments
I'm trying to compute the log likelihood of a sequence of networks given a fixed set of parameters. I tried the following and got "Error: 'function' is not a function, but of type 8". I'm new to this package and the error message is not very informative. Does anyone know what was wrong with my example? Thanks!
# sim1 is a list of adjacency matrices
sim1nw = lapply(sim1, network)
sim1NS = NetSeries(sim1nw[1:5])
res = ergm.bridge.dindstart.llk(
object = sim1NS ~ Form(~edges+mutual)+Diss(~edges+mutual),
coef = c(1,1,1,1),
verbose = T
)
Can you please post a traceback (produced by traceback()
) with your report and/or a fully reproducible example?
Yes, of course. My example:
set.seed(1)
n = 10
t = 5
nw_list = vector(mode = 'list', t)
for(i in 1:t){
nw_list[[i]] = matrix(rbinom(n=n^2, size=1, prob = 0.5), n, n)
}
sim1nw = lapply(nw_list, network)
sim1NS = NetSeries(sim1nw)
res = ergm.bridge.dindstart.llk(
object = sim1NS ~ Form(~edges+mutual)+Diss(~edges+mutual),
coef = c(1,1,1,1),
verbose = T
)
Traceback:
14: NextMethod()
13: eval(lhs, parent, parent)
12: eval(lhs, parent, parent)
11: NextMethod() %>% prune.ergm_conlist()
10: c.ergm_conlist(ergm_conlist(object, nw, term.options = term.options,
...), ergm_conlist(hints, nw, term.options = term.options,
...))
9: c(ergm_conlist(object, nw, term.options = term.options, ...),
ergm_conlist(hints, nw, term.options = term.options, ...))
8: ergm_proposal.formula(constraints, hints = control$MCMC.prop,
weights = control$MCMC.prop.weights, control$MCMC.prop.args,
nw, class = proposalclass, reference = reference, term.options = control$term.options)
7: ergm_proposal(constraints, hints = control$MCMC.prop, weights = control$MCMC.prop.weights,
control$MCMC.prop.args, nw, class = proposalclass, reference = reference,
term.options = control$term.options)
6: ergm(dind, estimate = "MPLE", constraints = constraints, obs.constraints = obs.constraints,
eval.loglik = FALSE, control = control.ergm(drop = FALSE,
term.options = control$term.options, MPLE.max.dyad.types = control$MPLE.max.dyad.types),
offset.coef = offset.dind)
5: withCallingHandlers(expr, warning = function(w) if (inherits(w,
classes)) tryInvokeRestart("muffleWarning"))
4: suppressWarnings(ergm(dind, estimate = "MPLE", constraints = constraints,
obs.constraints = obs.constraints, eval.loglik = FALSE, control = control.ergm(drop = FALSE,
term.options = control$term.options, MPLE.max.dyad.types = control$MPLE.max.dyad.types),
offset.coef = offset.dind))
3: withCallingHandlers(expr, message = function(c) if (inherits(c,
classes)) tryInvokeRestart("muffleMessage"))
2: suppressMessages(suppressWarnings(ergm(dind, estimate = "MPLE",
constraints = constraints, obs.constraints = obs.constraints,
eval.loglik = FALSE, control = control.ergm(drop = FALSE,
term.options = control$term.options, MPLE.max.dyad.types = control$MPLE.max.dyad.types),
offset.coef = offset.dind)))
1: ergm.bridge.dindstart.llk(object = sim1NS ~ Form(~edges + mutual) +
Diss(~edges + mutual), coef = c(1, 1, 1, 1), verbose = T)
This code works for me, so it may have gotten fixed since the last release. Can you try installing a development version (i.e., install.packages("remotes"); remotes::install_github("statnet/tergm")
) and seeing if it works for you?
I updated the package and it works now. Thank you!
Good to know!