Movatterモバイル変換


[0]ホーム

URL:


An Introduction to Estimating JointProbability Models withiglm

Overview

This vignette provides an introduction to theiglmpackage, which is designed for estimating joint probability models thatincorporate network structures. The package allows users to analyze howindividual attributes and network connections jointly influence outcomesof interest.

Basic Usage

To use theiglm package, you first need to load it intoyour R session

library(iglm)

Next, you can create aiglm object by specifying thenetwork structure and the attributes of interest. Here is a simpleexample:

n_actors=100attribute_info=rnorm(n_actors)attribute_cov=diag(attribute_info)edge_cov=outer(attribute_info, attribute_info,FUN =function(x,y){abs(x-y)})set.seed(123)alpha=0.3block<-matrix(nrow =50,ncol =50,data =1)neighborhood<-as.matrix(Matrix::bdiag(replicate(n_actors/50, block,simplify=FALSE)))overlapping_degree=0.5neighborhood=matrix(nrow = n_actors,ncol = n_actors,data =0)block<-matrix(nrow =5,ncol =5,data =0)size_neighborhood<-5size_overlap<-ceiling(size_neighborhood*overlapping_degree)end<-floor((n_actors-size_neighborhood)/size_overlap)for(iin0:end){  neighborhood[(1+size_overlap*i):(size_neighborhood+size_overlap*i), (1+size_overlap*i):(size_neighborhood+size_overlap*i)]=1}neighborhood[(n_actors-size_neighborhood+1):(n_actors), (n_actors-size_neighborhood+1):(n_actors)]=1type_x<-"binomial"type_y<-"binomial"formula_beg=as.formula("xyz_obj ~ 1 ")formula_model=as.formula("xyz_object ~ 1 ")object=iglm.data(neighborhood = neighborhood,directed = F,type_x = type_x,type_y = type_y)

Model Specification

You can specify a model formula that includes various networkstatistics and attribute effects. For example:

formula<- object~ edges+ attribute_y+ attribute_x+ popularity

To fully define the model, you need to set up a sampler for the MCMCestimation and set all necessary parameters:

# Parameters of edges(mode = "local"), attribute_y, and attribute_xgt_coef=c(3,-1,-1)# Parameters for popularity effectgt_coef_pop=c(rnorm(n = n_actors,-2,1))# Define the samplersampler_tmp=sampler.iglm(n_burn_in =100,n_simulation =10,sampler_x =sampler.net.attr(n_proposals =  n_actors*10,seed =13),sampler_y =sampler.net.attr(n_proposals =  n_actors*10,seed =32),sampler_z =sampler.net.attr(n_proposals =sum(neighborhood>0)*10,seed =134),init_empty = F)model_tmp_new<-iglm(formula = formula,coef = gt_coef,coef_popularity = gt_coef_pop,sampler = sampler_tmp,control =control.iglm(accelerated = F,max_it =200,display_progress = F,var = T))

Model Simulation

Once you have specified a model, you can simulate new data based onthe fitted parameters:

# Simulate new networksmodel_tmp_new$simulate()# Get the samplestmp<- model_tmp_new$get_samples()

Model Estimation

You can estimate the model parameters using theestimatemethod:

# First set the first simulated network as the target for estimationmodel_tmp_new$set_target(tmp[[1]])model_tmp_new$estimate()model_tmp_new$iglm.data$degree_distribution(plot =TRUE)

Model Assessment

After estimation, you can assess the model fit using variousdiagnostics:

model_tmp_new$model_assessment(formula =~  degree_distribution+                                 geodesic_distances_distribution+ edgewise_shared_partner_distribution+ mcmc_diagnostics)

model_tmp_new$results$plot(model_assessment = T)


[8]ページ先頭

©2009-2025 Movatter.jp