library(latentnet)
## 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
## Loading required package: ergm
##
## '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.
##
## 'latentnet' 2.11.0 (2024-02-19), part of the Statnet Project
## * 'news(package="latentnet")' for changes since last version
## * 'citation("latentnet")' for citation information
## * 'https://statnet.org' for help, support, and other information
## NOTE: BIC calculation prior to latentnet 2.7.0 had a bug in the calculation of the effective number of parameters. See help(summary.ergmm) for details.
## NOTE: Prior to version 2.8.0, handling of fixed effects for directed networks had a bug: the covariate matrix was transposed.
library(network)
library(ggplot2)
data <- read.csv("data/arms_data/trade-register-cleaned-year-order.csv")
set.seed(123)
latent_model <- function(year) {
data_year <- subset(data, Year == year)
data_year$Source <- as.character(data_year$Source)
data_year$Target <- as.character(data_year$Target)
nodes <- unique(c(data_year$Source, data_year$Target))
adjacency_matrix <- matrix(0, nrow = length(nodes), ncol = length(nodes), dimnames = list(nodes, nodes))
for (i in 1:nrow(data_year)) {
source <- data_year$Source[i]
target <- data_year$Target[i]
weight <- data_year$Weight[i]
adjacency_matrix[source, target] <- weight
}
net <- network(adjacency_matrix, directed = TRUE, ignore.eval = FALSE, names.eval = "weight")
variance = var(data_year$Weight)
fam.par <- list(prior.var = variance, prior.var.df = 1)
data.fit <- ergmm(net ~ euclidean(d = 2), response = "weight", verbose = TRUE,
family = "normal", fam.par = fam.par)
summary(data.fit)
plot(data.fit, pie=TRUE)
}
years <- c(2018, 2019, 2020, 2021, 2022, 2023)
for (year in years) {
latent_model(year)
}
## Generating initial values for MCMC:
## Computing geodesic distances... Finished.
## Computing MDS locations... Finished.
## Computing other initial values... Finished.
## Finding the conditional posterior mode... Finished.
## Burning in... Backing off: too few acceptances. If you see this message several times in a row, use a longer burnin.
## Finished.
## Starting sampling run... Finished.
## Post-processing the MCMC output:
## Fitting the MKL locations... Finished.
## MKL MBC is not available or non-latent-cluster model.
## Performing Procrustes transformation... Finished.
## NOTE: It is not certain whether it is appropriate to use latentnet's BIC to select latent space dimension, whether or not to include actor-specific random effects, and to compare clustered models with the unclustered model.

## Generating initial values for MCMC:
## Computing geodesic distances... Finished.
## Computing MDS locations... Finished.
## Computing other initial values... Finished.
## Finding the conditional posterior mode... Finished.
## Burning in... Backing off: too few acceptances. If you see this message several times in a row, use a longer burnin.
## Finished.
## Starting sampling run... Finished.
## Post-processing the MCMC output:
## Fitting the MKL locations... Finished.
## MKL MBC is not available or non-latent-cluster model.
## Performing Procrustes transformation... Finished.

## Generating initial values for MCMC:
## Computing geodesic distances... Finished.
## Computing MDS locations... Finished.
## Computing other initial values... Finished.
## Finding the conditional posterior mode... Finished.
## Burning in... Backing off: too few acceptances. If you see this message several times in a row, use a longer burnin.
## Finished.
## Starting sampling run... Finished.
## Post-processing the MCMC output:
## Fitting the MKL locations... Finished.
## MKL MBC is not available or non-latent-cluster model.
## Performing Procrustes transformation... Finished.

## Generating initial values for MCMC:
## Computing geodesic distances... Finished.
## Computing MDS locations... Finished.
## Computing other initial values... Finished.
## Finding the conditional posterior mode... Finished.
## Burning in... Backing off: too few acceptances. If you see this message several times in a row, use a longer burnin.
## Finished.
## Starting sampling run... Finished.
## Post-processing the MCMC output:
## Fitting the MKL locations... Finished.
## MKL MBC is not available or non-latent-cluster model.
## Performing Procrustes transformation... Finished.

## Generating initial values for MCMC:
## Computing geodesic distances... Finished.
## Computing MDS locations... Finished.
## Computing other initial values... Finished.
## Finding the conditional posterior mode... Finished.
## Burning in... Backing off: too few acceptances. If you see this message several times in a row, use a longer burnin.
## Finished.
## Starting sampling run... Finished.
## Post-processing the MCMC output:
## Fitting the MKL locations... Finished.
## MKL MBC is not available or non-latent-cluster model.
## Performing Procrustes transformation... Finished.

## Generating initial values for MCMC:
## Computing geodesic distances... Finished.
## Computing MDS locations... Finished.
## Computing other initial values... Finished.
## Finding the conditional posterior mode... Finished.
## Burning in... Finished.
## Starting sampling run... Finished.
## Post-processing the MCMC output:
## Fitting the MKL locations... Finished.
## MKL MBC is not available or non-latent-cluster model.
## Performing Procrustes transformation... Finished.
