statnet / ergm.ego

Fit, Simulate and Diagnose Exponential-Family Random Graph Models to Egocentrically Sampled Network Data https://statnet.org
Other
14 stars 4 forks source link

logLik and AIC methods #81

Open mbojan opened 4 months ago

mbojan commented 4 months ago

What it would take to have logLik and AIC methods for ergm.ego objects? It seems that we need ergm.bridge.dindstart.llk and friends? Currently using existing .ergm methods trip:

library(ergm.ego)
#> Loading required package: ergm
#> Loading required package: network
#> 
#> 'network' 1.18.2 (2023-12-04), part of the Statnet Project
#> * 'news(package="network")' for changes since last version
#> * 'citation("network")' for citation information
#> * 'https://statnet.org' for help, support, and other information
#> 
#> 'ergm' 4.6.0 (2023-12-17), part of the Statnet Project
#> * 'news(package="ergm")' for changes since last version
#> * 'citation("ergm")' for citation information
#> * 'https://statnet.org' for help, support, and other information
#> 'ergm' 4 is a major update that introduces some backwards-incompatible
#> changes. Please type 'news(package="ergm")' for a list of major
#> changes.
#> Loading required package: egor
#> Loading required package: dplyr
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
#> Loading required package: tibble
#> 
#> 'ergm.ego' 1.1.0 (2023-05-30), part of the Statnet Project
#> * 'news(package="ergm.ego")' for changes since last version
#> * 'citation("ergm.ego")' for citation information
#> * 'https://statnet.org' for help, support, and other information
#> 
#> Attaching package: 'ergm.ego'
#> The following objects are masked from 'package:ergm':
#> 
#>     COLLAPSE_SMALLEST, snctrl
#> The following object is masked from 'package:base':
#> 
#>     sample

data("faux.mesa.high", package = "ergm")
net <- as.egor(faux.mesa.high)

fit1 <- ergm.ego(net ~ edges)
#> Constructing pseudopopulation network.
#> Starting maximum pseudolikelihood estimation (MPLE):
#> Obtaining the responsible dyads.
#> Evaluating the predictor and response matrix.
#> Maximizing the pseudolikelihood.
#> Finished MPLE.
#> Starting Monte Carlo maximum likelihood estimation (MCMLE):
#> Iteration 1 of at most 60:
#> Optimizing with step length 1.0000.
#> The log-likelihood improved by < 0.0001.
#> Convergence test p-value: < 0.0001. Converged with 99% confidence.
#> Finished MCMLE.
#> This model was fit using MCMC.  To examine model diagnostics and check
#> for degeneracy, use the mcmc.diagnostics() function.
try(AIC(fit1))
#> Error in eval(substitute(expr), data, enclos = parent.frame()) : 
#>   Log-likelihood was not estimated for this fit. To get deviances, AIC, and/or BIC, use ‘*fit* <-logLik(*fit*, add=TRUE)’ to add it to the object or rerun this function with eval.loglik=TRUE.
try(logLik(fit1))
#> Error in eval(substitute(expr), data, enclos = parent.frame()) : 
#>   Log-likelihood was not estimated for this fit. To get deviances, AIC, and/or BIC, use ‘*fit* <-logLik(*fit*, add=TRUE)’ to add it to the object or rerun this function with eval.loglik=TRUE.

try(logLik(fit1, add = TRUE))
#> Fitting the dyad-independent submodel...
#> Bridging between the dyad-independent submodel and the full model...
#> Setting up bridge sampling...
#> Error in simulate.ergm_model(m, nsim = nsim, seed = seed, coef = coef,  : 
#>   coef has 3 elements, while the model requires 2 parameters.
krivit commented 4 months ago

ergm.ego doesn't use maximum likelihood estimation but rather a pseudo-maximum-likelihood approach of Binder (1983), in which we first estimate the population values of sufficient statistics then transfer their properties to model parameters; so a likelihood is not meaningful.

mbojan commented 4 months ago

Right. What would you suggest as an AIC alternative for model selection?

mbojan commented 4 months ago

ergm.ego doesn't use maximum likelihood estimation but rather a pseudo-maximum-likelihood approach of Binder (1983), in which we first estimate the population values of sufficient statistics then transfer their properties to model parameters; so a likelihood is not meaningful.

Perhaps I'll add e.g. logLik.ergm.ego() that will produce that kind of message as it is not obvious to users.