### Install and Load remstimate Package Source: https://tilburgnetworkgroup.github.io/remstimate/index.html Installs the remstimate package from CRAN and loads it into the R session. This is the initial setup required to use the package's functionalities. ```r install.packages("remstimate") library(remify) ``` -------------------------------- ### Example: Tie-oriented model MLE diagnostics Source: https://tilburgnetworkgroup.github.io/remstimate/reference/plot.remstimate.html Demonstrates the setup for plotting diagnostics of a tie-oriented model using the Maximum Likelihood Estimation (MLE) approach. This involves loading data, processing it with 'remify', specifying the model, and calculating statistics. ```R # loading data data(tie_data) # processing event sequence with remify tie_reh <- remify::remify(edgelist = tie_data$edgelist, model = "tie") # specifying linear predictor tie_model <- ~ 1 + remstats::indegreeSender()+ remstats::inertia()+ remstats::reciprocity() # calculating statistics tie_reh_stats <- remstats::remstats(reh = tie_reh, tie_effects = tie_model) ``` -------------------------------- ### Print remstimate Object (Tie-Oriented Model) Source: https://tilburgnetworkgroup.github.io/remstimate/reference/print.remstimate.html This example demonstrates how to print a remstimate object for a tie-oriented model. It includes data loading, model specification, statistics calculation, and estimation. ```R # loading data data(tie_data) # processing event sequence with remify tie_reh <- remify::remify(edgelist = tie_data$edgelist, model = "tie") # specifying linear predictor tie_model <- ~ 1 + remstats::indegreeSender()+ remstats::inertia()+ remstats::reciprocity() # calculating statistics tie_reh_stats <- remstats::remstats(reh = tie_reh, tie_effects = tie_model) # running estimation tie_mle <- remstimate::remstimate(reh = tie_reh, stats = tie_reh_stats, method = "BSIR", nsim = 100, ncores = 1) # print tie_mle ``` -------------------------------- ### Estimate Tie-Oriented Model with remstimate Source: https://tilburgnetworkgroup.github.io/remstimate/reference/bic.html This example shows the full process of estimating a tie-oriented model using remify, remstats, and remstimate. It includes data loading, processing, specifying the model, calculating statistics, and running the estimation. ```R # loading data data(tie_data) # processing event sequence with remify tie_reh <- remify::remify(edgelist = tie_data$edgelist, model = "tie") # specifying linear predictor tie_model <- ~ 1 + remstats::indegreeSender()+ remstats::inertia()+ remstats::reciprocity() # calculating statistics tie_reh_stats <- remstats::remstats(reh = tie_reh, tie_effects = tie_model) # running estimation tie_mle <- remstimate::remstimate(reh = tie_reh, stats = tie_reh_stats, method = "MLE", ncores = 1) ``` -------------------------------- ### Estimate Model Parameters with remstimate() Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Run the model estimation using the remstimate() function with specified statistics and method. This example uses the 'MLE' method. ```r # for example the method "MLE" remstimate::remstimate(reh = ao_reh, stats = ao_stats, method = "MLE", ncores = ncores) ``` -------------------------------- ### Print remstimate Object (Actor-Oriented Model) Source: https://tilburgnetworkgroup.github.io/remstimate/reference/print.remstimate.html This example shows how to print a remstimate object for an actor-oriented model. It covers data preparation, model specification for sender rate and receiver choice, statistics calculation, and estimation. ```R # loading data data(ao_data) # processing event sequence with remify ao_reh <- remify::remify(edgelist = ao_data$edgelist, model = "actor") # specifying linear predictor (for sender rate and receiver choice model) rate_model <- ~ 1 + remstats::indegreeSender() choice_model <- ~ remstats::inertia() + remstats::reciprocity() # calculating statistics ao_reh_stats <- remstats::remstats(reh = ao_reh, sender_effects = rate_model, receiver_effects = choice_model) # running estimation ao_mle <- remstimate::remstimate(reh = ao_reh, stats = ao_reh_stats, method = "BSIR", nsim = 100, ncores = 1) # print ao_mle ``` -------------------------------- ### List Available Vignettes Source: https://tilburgnetworkgroup.github.io/remstimate/index.html Lists all vignettes available for the remstimate package. Vignettes provide detailed examples and explanations of the package's features. ```r vignette(package = "remstimate") ``` -------------------------------- ### Estimate REM using BSIR with Custom Priors Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Fit a relational event model using the Bayesian Sampling Importance Resampling (BSIR) method. This example demonstrates setting custom prior distributions and their arguments for both sender and receiver models. ```R library(mvnfast) # loading package for fast simulation from a multivariate Student t distribution priormvt <- mvnfast::dmvt # defining which distribution we want to use from the 'mvnfast' package ao_bsir <- remstimate::remstimate(reh = ao_reh, stats = ao_stats, ncores = ncores, method = "BSIR", nsim = 100L, # 100 draws from the posterior distribution prior = list(sender_model = priormvt, receiver_model = priormvt), # defining prior here, prior parameters follow below prior_args = list(sender_model = list(mu = rep(0,dim(ao_stats$sender_stats)[3]), # prior mu value for sender_model sigma = diag(dim(ao_stats$sender_stats)[3])*1.5, # prior sigma value for sender_model df = 1), # prior df value receiver_model = list(mu = rep(0,dim(ao_stats$receiver_stats)[3]), # prior mu value for receiver_model sigma = diag(dim(ao_stats$receiver_stats)[3])*1.5, # prior sigma value for receiver_model df = 1)), # prior df value log = TRUE, # requiring log density values from the prior, seed = 20929, # set a seed only for reproducibility purposes WAIC = TRUE, # setting WAIC computation to TRUE nsimWAIC = 100 # number of draws for the computation of the WAIC set to 100 ) # summary summary(ao_bsir) ``` -------------------------------- ### Calculate AICC for a remstimate object Source: https://tilburgnetworkgroup.github.io/remstimate/reference/aicc.html This example demonstrates how to calculate the AICC value for a 'remstimate' object after processing network data and running an estimation. Ensure remify, remstats, and remstimate packages are loaded and data is prepared. ```R # loading data data(tie_data) # processing event sequence with remify tie_reh <- remify::remify(edgelist = tie_data$edgelist, model = "tie") # specifying linear predictor tie_model <- ~ 1 + remstats::indegreeSender()+ remstats::inertia()+ remstats::reciprocity() # calculating statistics tie_reh_stats <- remstats::remstats(reh = tie_reh, tie_effects = tie_model) # running estimation tie_mle <- remstimate::remstimate(reh = tie_reh, stats = tie_reh_stats, method = "MLE", ncores = 1) # AICC aicc(tie_mle) #> [1] 1219.046 ``` -------------------------------- ### WAIC Function Signature Source: https://tilburgnetworkgroup.github.io/remstimate/reference/waic.html Defines the S3 method signature for the waic function when applied to a 'remstimate' object. No examples are currently available. ```R waic(object, ...) # S3 method for class 'remstimate' waic(object, ...) ``` -------------------------------- ### Summary for tie-oriented model (BSIR) Source: https://tilburgnetworkgroup.github.io/remstimate/reference/summary.remstimate.html Generates a summary for a tie-oriented relational event model estimated using the BSIR method. Requires prior estimation of the model. ```R # loading data data(tie_data) # processing event sequence with remify tie_reh <- remify::remify(edgelist = tie_data$edgelist, model = "tie") # specifying linear predictor tie_model <- ~ 1 + remstats::indegreeSender()+ remstats::inertia()+ remstats::reciprocity() # calculating statistics tie_reh_stats <- remstats::remstats(reh = tie_reh, tie_effects = tie_model) # running estimation tie_mle <- remstimate::remstimate(reh = tie_reh, stats = tie_reh_stats, method = "BSIR", nsim = 100, ncores = 1) # summary summary(tie_mle) ``` -------------------------------- ### Compute Diagnostics for Tie-Oriented Model (MLE) Source: https://tilburgnetworkgroup.github.io/remstimate/reference/diagnostics.html This snippet demonstrates how to compute diagnostics for a tie-oriented model estimated using the Maximum Likelihood Estimation (MLE) method. It includes data loading, event sequence processing, specifying the linear predictor, calculating statistics, running the estimation, and finally computing the diagnostics. ```R data(tie_data) # processing event sequence with remify tie_reh <- remify::remify(edgelist = tie_data$edgelist, model = "tie") # specifying linear predictor tie_model <- ~ 1 + remstats::indegreeSender()+ remstats::inertia()+ remstats::reciprocity() # calculating statistics tie_reh_stats <- remstats::remstats(reh = tie_reh, tie_effects = tie_model) # running estimation tie_mle <- remstimate::remstimate(reh = tie_reh, stats = tie_reh_stats, method = "MLE", ncores = 1) # diagnostics tie_diagnostics <- diagnostics(object = tie_mle, reh = tie_reh, stats = tie_reh_stats) names(tie_diagnostics) #> [1] "residuals" "rates" ".reh.processed" ``` -------------------------------- ### Estimate Model using MLE and Summarize Source: https://tilburgnetworkgroup.github.io/remstimate/reference/ao_data.html Estimates a relational event model using the Maximum Likelihood Estimation (MLE) method with the 'remstimate' function and then prints a summary of the estimation results. ```r mle_ao <- remstimate::remstimate(reh = ao_reh, stats = ao_reh_stats, method = "MLE") summary(mle_ao) ``` -------------------------------- ### Load remestimate Package in R Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Load the remestimate package to begin using its functionalities for relational event modeling. This also loads the 'remify' and 'remstats' packages. ```r library(remstimate) ``` -------------------------------- ### Summarize MLE estimation for tie-oriented model Source: https://tilburgnetworkgroup.github.io/remstimate/reference/tie_data.html Prints a summary of the Maximum Likelihood Estimation (MLE) results for the tie-oriented relational event model, including coefficients, standard errors, and model fit statistics. ```r summary(mle_tie) ``` -------------------------------- ### Summarize remstimate Object Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Generate a detailed summary of the fitted relational event model, including model calls, coefficients with standard errors, z-values, p-values, and various model fit statistics. ```r # summary of the 'remstimate' object summary(ao_mle) ``` -------------------------------- ### Summary for actor-oriented model (BSIR) Source: https://tilburgnetworkgroup.github.io/remstimate/reference/summary.remstimate.html Generates a summary for an actor-oriented relational event model estimated using the BSIR method. This involves separate models for call rate and receiver choice. ```R # loading data data(ao_data) # processing event sequence with remify ao_reh <- remify::remify(edgelist = ao_data$edgelist, model = "actor") # specifying linear predictor (for sender rate and receiver choice model) rate_model <- ~ 1 + remstats::indegreeSender() choice_model <- ~ remstats::inertia() + remstats::reciprocity() # calculating statistics ao_reh_stats <- remstats::remstats(reh = ao_reh, sender_effects = rate_model, receiver_effects = choice_model) # running estimation ao_mle <- remstimate::remstimate(reh = ao_reh, stats = ao_reh_stats, method = "BSIR", nsim = 100, ncores = 1) # summary summary(ao_mle) ``` -------------------------------- ### Print remstimate Object Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Display the results of a fitted relational event model. This provides a summary of coefficients, deviance, and information criteria. ```r # printing the 'remstimate' object ao_mle ``` -------------------------------- ### Estimate Model with MLE and WAIC using remstimate Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Fit a relational event model using MLE and simultaneously compute the Widely Applicable Information Criterion (WAIC). This involves setting `WAIC = TRUE` and specifying `nsimWAIC` for the number of draws. ```R tie_mle <- remstimate::remstimate( reh = tie_reh, stats = tie_stats, ncores = ncores, method = "MLE", WAIC = TRUE, # setting WAIC computation to TRUE nsimWAIC = 100) # number of draws for the computation of the WAIC set to 100 ``` -------------------------------- ### Load tie_data Source: https://tilburgnetworkgroup.github.io/remstimate/reference/tie_data.html Loads the tie_data object into the R workspace. This dataset contains a simulated sequence of relational events. ```r data(tie_data) ``` -------------------------------- ### Print remstimate Object Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Display the estimated coefficients and model fit statistics for a `remstimate` object. This provides a concise overview of the model results. ```R # printing the 'remstimate' object tie_mle ``` -------------------------------- ### Plot RemEstimate Results Source: https://tilburgnetworkgroup.github.io/remstimate/reference/plot.remstimate.html Creates a plot visualizing the estimation results and diagnostics. Requires the estimated object, reh, and diagnostics. ```R plot(x = tie_mle, reh = tie_reh, diagnostics = tie_diagnostics) ``` -------------------------------- ### Load and Process Relational Event Data in R Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Loads simulated relational event data and processes it for actor-oriented modeling using the remify package. Sets the number of cores for processing. ```r ncores <- 1L # loading data data(ao_data) # true parameters' values ao_data$true.pars ``` ```r # processing event sequence with 'remify' ao_reh <- remify::remify(edgelist = ao_data$edgelist, model = "actor") # summary of the relational event network summary(ao_reh) ``` -------------------------------- ### Set ncores and load tie_data Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Sets the number of cores for processing and loads the simulated relational event sequence data. Adjust `ncores` as needed. ```r # setting `ncores` to 1 (the user can change this parameter) ncores <- 1L # loading data data(tie_data) # true parameters' values tie_data$true.pars ``` -------------------------------- ### Summarize remstimate Object Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Generate a detailed summary of the `remstimate` object, including coefficient estimates, standard errors, z-values, p-values, and model fit information. This is useful for in-depth analysis of the model. ```R # summary of the 'remstimate' object summary(tie_mle) ``` -------------------------------- ### Run RemEstimate MLE Source: https://tilburgnetworkgroup.github.io/remstimate/reference/plot.remstimate.html Runs a Maximum Likelihood Estimation (MLE) for network data. Requires reh and stats objects. Specify ncores for parallel processing. ```R tie_mle <- remstimate::remstimate( reh = tie_reh, stats = tie_reh_stats, method = "MLE", ncores = 1 ) ``` -------------------------------- ### Estimate Model using MLE with remstimate Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Estimate the relational event model using the Maximum Likelihood Estimation (MLE) method with the `remstimate` function. This requires the processed network, calculated statistics, and the desired method. ```R # for example the method "MLE" remstimate::remstimate(reh = tie_reh, stats = tie_stats, method = "MLE", ncores = ncores) ``` -------------------------------- ### Perform Diagnostics Source: https://tilburgnetworkgroup.github.io/remstimate/reference/plot.remstimate.html Generates diagnostic statistics for a remestimate object. Requires the estimated object, reh, and stats. ```R tie_diagnostics <- diagnostics(object = tie_mle, reh = tie_reh, stats = tie_reh_stats) ``` -------------------------------- ### Process event sequence with remify Source: https://tilburgnetworkgroup.github.io/remstimate/reference/tie_data.html Processes the raw edgelist from tie_data into a relational event history object using the remify function with a tie-oriented model. ```r tie_reh <- remify::remify(edgelist = tie_data$edgelist, model = "tie") ``` -------------------------------- ### Estimate tie-oriented model using MLE Source: https://tilburgnetworkgroup.github.io/remstimate/reference/tie_data.html Estimates the parameters of the tie-oriented relational event model using the Maximum Likelihood Estimation (MLE) method with the remstimate function. Requires the remified event history and calculated statistics. ```r mle_tie <- remstimate::remstimate(reh = tie_reh, stats = tie_reh_stats, method = "MLE") ``` -------------------------------- ### Estimate Model with MLE and WAIC Calculation Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Perform Maximum Likelihood Estimation (MLE) for an actor-oriented model, including the computation of WAIC. Set WAIC computation to TRUE and specify the number of draws for WAIC calculation. ```r ao_mle <- remstimate::remstimate(reh = ao_reh, stats = ao_stats, ncores = ncores, method = "MLE", WAIC = TRUE, # setting WAIC computation to TRUE nsimWAIC = 100) # number of draws for the computation of the WAIC set to 100 ``` -------------------------------- ### Calculate Diagnostics for remstimate Object Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Compute diagnostic statistics for a `remstimate` model object. This requires the fitted model, the original relational event network, and the calculated statistics. ```R # diagnostics tie_mle_diagnostics <- diagnostics(object = tie_mle, reh = tie_reh, stats = tie_stats) ``` -------------------------------- ### Load ao_data Dataset Source: https://tilburgnetworkgroup.github.io/remstimate/reference/ao_data.html Loads the predefined 'ao_data' dataset into the R workspace. This dataset contains a simulated sequence of relational events. ```r data(ao_data) ``` -------------------------------- ### R S3 method for remstimate object Source: https://tilburgnetworkgroup.github.io/remstimate/reference/plot.remstimate.html This is the S3 method signature for plotting diagnostics of a 'remstimate' object. It outlines the main parameters for controlling which diagnostics are plotted and for which effects. ```R # S3 method for class 'remstimate' plot( x, reh, diagnostics = NULL, which = c(1:4), effects = NULL, sender_effects = NULL, receiver_effects = NULL, ... ) ``` -------------------------------- ### Open Specific Vignette Source: https://tilburgnetworkgroup.github.io/remstimate/index.html Opens a specific vignette for the remstimate package, such as the main 'remstimate' vignette. This is useful for understanding how to use the package in practice. ```r vignette(topic = "remstimate", package = "remstimate") # or simply vignette("remstimate") ``` -------------------------------- ### Run HMC Diagnostics Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Runs Hamiltonian Monte Carlo (HMC) diagnostics on a tie object. This is useful for assessing the convergence and quality of MCMC simulations. ```R tie_hmc_diagnostics <- diagnostics(object = tie_hmc, reh = tie_reh, stats = tie_stats) ``` -------------------------------- ### Estimate Actor-Oriented Model using MLE Source: https://tilburgnetworkgroup.github.io/remstimate/reference/remstimate.html Estimates parameters for an actor-oriented relational event model using Maximum Likelihood Estimation (MLE). This involves specifying separate models for sender rate and receiver choice, along with processed event data. ```R # loading data data(ao_data) # processing event sequence with remify ao_reh <- remify::remify(edgelist = ao_data$edgelist, model = "actor") # specifying linear predictor (for sender rate and receiver choice model) rate_model <- ~ 1 + remstats::indegreeSender() choice_model <- ~ remstats::inertia() + remstats::reciprocity() # calculating statistics ao_reh_stats <- remstats::remstats(reh = ao_reh, sender_effects = rate_model, receiver_effects = choice_model) # running estimation ao_mle <- remstimate::remstimate(reh = ao_reh, stats = ao_reh_stats, method = "MLE", ncores = 1) # summary summary(ao_mle) ``` -------------------------------- ### Estimate REM with BSIR Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Employ Bayesian Sampling Importance Resampling (BSIR) for estimation. Requires loading the 'mvnfast' package and specifying prior distributions and parameters. WAIC computation is optional. ```r library(mvnfast) # loading package for fast simulation from a multivariate Student t distribution priormvt <- mvnfast::dmvt # defining which distribution we want to use from the 'mvnfast' package tie_bsir <- remstimate::remstimate(reh = tie_reh, stats = tie_stats, ncores = ncores, method = "BSIR", nsim = 200L, # 200 draws from the posterior distribution prior = priormvt, # defining prior here, prior parameters follow below mu = rep(0,dim(tie_stats)[3]), # prior mu value sigma = diag(dim(tie_stats)[3])*1.5, # prior sigma value df = 1, # prior df value log = TRUE, # requiring log density values from the prior, seed = 23029, # set a seed only for reproducibility purposes WAIC = TRUE, # setting WAIC computation to TRUE nsimWAIC = 100 # number of draws for the computation of the WAIC set to 100 ) # summary summary(tie_bsir) ``` -------------------------------- ### Calculate Network Statistics with remstats() Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Compute the network statistics defined in the linear predictor using the remstats() function. This prepares the data for model estimation. ```r # calculating statistics (with `remstats`) ao_stats <- remstats::remstats(reh = ao_reh, sender_effects = rate_model, receiver_effects = choice_model) # the 'aomstats' 'remstats' object ao_stats ``` -------------------------------- ### Calculate statistics for tie-oriented model Source: https://tilburgnetworkgroup.github.io/remstimate/reference/tie_data.html Calculates the necessary statistics for the defined tie-oriented model using the remstats function, based on the remified event history. ```r tie_reh_stats <- remstats::remstats(reh = tie_reh, tie_effects = tie_model) ``` -------------------------------- ### Estimate REM using GDADAMAX Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Fit a relational event model using the Adaptive Gradient Descent Optimization (GDADAMAX) method. This method requires specifying the number of epochs and optionally WAIC computation. ```R ao_gd <- remstimate::remstimate(reh = ao_reh, stats = ao_stats, ncores = ncores, method = "GDADAMAX", epochs = 200L, # number of iterations of the Gradient-Descent algorithm WAIC = TRUE, # setting WAIC computation to TRUE nsimWAIC = 100) # number of draws for the computation of the WAIC set to 100 # print ao_gd ``` -------------------------------- ### Plot remstimate Object with Diagnostics Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Generate a plot visualizing the results of a `remstimate` model, incorporating diagnostic information. This helps in assessing the model's fit and performance. ```R # plot plot(x = tie_mle, reh = tie_reh, diagnostics = tie_mle_diagnostics) ``` -------------------------------- ### Specify Linear Predictor with remstats Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Define the linear predictor for the relational event model using a formula interface with `remstats`. This allows for the inclusion of various network statistics. ```R # specifying linear predictor (with `remstats`) using a 'formula' tie_model <- ~ 1 + remstats::indegreeSender() + remstats::inertia() + remstats::reciprocity() ``` -------------------------------- ### Define Linear Predictors and Calculate Statistics Source: https://tilburgnetworkgroup.github.io/remstimate/reference/ao_data.html Defines the linear predictors for both the rate and choice models using 'remstats' functions and then calculates the corresponding statistics for the relational event history. ```r rate_model <- ~ 1 + remstats::indegreeSender() choice_model <- ~ remstats::inertia() + remstats::reciprocity() ao_reh_stats <- remstats::remstats(reh = ao_reh, sender_effects = rate_model, receiver_effects = choice_model) ``` -------------------------------- ### Estimate REM with GDADAMAX Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Use GDADAMAX for adaptive gradient descent optimization. Set WAIC computation to TRUE and specify the number of draws for WAIC calculation. ```r tie_gd <- remstimate::remstimate(reh = tie_reh, stats = tie_stats, ncores = ncores, method = "GDADAMAX", epochs = 200L, # number of iterations for the Gradient-Descent algorithm WAIC = TRUE, # setting WAIC computation to TRUE nsimWAIC = 100) # number of draws for the computation of the WAIC set to 100 # print tie_gd ``` -------------------------------- ### BibTeX Citation for remstimate Package Source: https://tilburgnetworkgroup.github.io/remstimate/authors.html Use this BibTeX entry for academic citations of the remstimate R package. Ensure the version and URL are up-to-date. ```bibtex @Manual{ title = {remstimate: Optimization Frameworks for Tie-Oriented and Actor-Oriented Relational Event Models}, author = {Giuseppe Arena and Rumana Lakdawala and Fabio {Generoso Vieira}}, year = {2025}, note = {R package version 2.3.14}, url = {https://tilburgnetworkgroup.github.io/remstimate/}, } ``` -------------------------------- ### Compute Diagnostics Source: https://tilburgnetworkgroup.github.io/remstimate/reference/diagnostics.html The `diagnostics` function computes and returns the diagnostics of a `remstimate` object. This includes standardized Schoenfeld's residuals and estimated event rates. ```APIDOC ## diagnostics ### Description Computes the diagnostics of a `remstimate` object. The output object contains the residuals of the model estimated in the `remstimate` object, and the event rates estimated from the model at each time point. ### Method Signature ```R diagnostics(object, reh, stats, ...) # S3 method for class 'remstimate' diagnostics(object, reh, stats, ...) ``` ### Arguments * `object` (remstimate): The `remstimate` object for which to compute diagnostics. * `reh` (remify): The `remify` object used for the `remstimate` object. * `stats` (remstats): The `remstats` object used for the `remstimate` object. * `...`: Further arguments to be passed to the `diagnostics` method. ### Value A object of class `"diagnostics" "remstimate"` containing standardized Schoenfeld's residuals and estimated event rates. ### Examples ```R # loading data data(tie_data) # processing event sequence with remify tie_reh <- remify::remify(edgelist = tie_data$edgelist, model = "tie") # specifying linear predictor tie_model <- ~ 1 + remstats::indegreeSender()+ remstats::inertia()+ remstats::reciprocity() # calculating statistics tie_reh_stats <- remstats::remstats(reh = tie_reh, tie_effects = tie_model) # running estimation tie_mle <- remstimate::remstimate(reh = tie_reh, stats = tie_reh_stats, method = "MLE", ncores = 1) # diagnostics tie_diagnostics <- diagnostics(object = tie_mle, reh = tie_reh, stats = tie_reh_stats) names(tie_diagnostics) #> [1] "residuals" "rates" ".reh.processed" ``` ``` -------------------------------- ### remstimate Function Signature Source: https://tilburgnetworkgroup.github.io/remstimate/reference/remstimate.html This is the usage signature for the remstimate function. It outlines the required and optional parameters for optimizing network likelihoods. ```R remstimate( reh, stats, method = c("MLE", "GDADAMAX", "BSIR", "HMC"), ncores = attr(reh, "ncores"), prior = NULL, nsim = 1000L, nchains = 1L, burnin = 500L, thin = 10L, init = NULL, epochs = 1000L, L = 50L, epsilon = ifelse(method == "GDADAMAX", 0.001, 0.002), seed = NULL, WAIC = FALSE, silent = TRUE, ... ) ``` -------------------------------- ### Process Event Sequence with remify Source: https://tilburgnetworkgroup.github.io/remstimate/reference/ao_data.html Processes the raw event sequence from 'ao_data$edgelist' using the 'remify' function to create a relational event history object suitable for actor-oriented models. ```r ao_reh <- remify::remify(edgelist = ao_data$edgelist, model = "actor") ``` -------------------------------- ### Estimate REM using Hamiltonian Monte Carlo (HMC) Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Estimates a Relational Event Model using the Hamiltonian Monte Carlo (HMC) method. This function requires specifying various simulation parameters such as the number of cores, simulation draws, chains, burn-in, leapfrog steps, step size, and thinning. WAIC computation can be enabled. ```R ao_hmc <- remstimate::remstimate(reh = ao_reh, stats = ao_stats, method = "HMC", ncores = ncores, nsim = 300L, # 300 draws to generate per each chain nchains = 4L, # 4 chains (each one long 200 draws) to generate burnin = 300L, # burnin length is 300 L = 100L, # number of leap-frog steps epsilon = 0.1/100, # size of a leap-frog step thin = 2L, # thinning size (this will reduce the final length of each chain will be 150) seed = 23029, # set a seed only for reproducibility purposes WAIC = TRUE, # setting WAIC computation to TRUE nsimWAIC = 100 # number of draws for the computation of the WAIC set to 100 ) ``` -------------------------------- ### Generate Diagnostics for REM Estimate Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Generates diagnostic statistics for a fitted REM object. This is useful for assessing the convergence and quality of the model estimation. ```R ao_bsir_diagnostics <- diagnostics(object = ao_bsir, reh = ao_reh, stats = ao_stats) ``` ```R ao_hmc_diagnostics <- diagnostics(object = ao_hmc, reh = ao_reh, stats = ao_stats) ``` -------------------------------- ### remstimate Function Source: https://tilburgnetworkgroup.github.io/remstimate/reference/remstimate.html Optimizes tie-oriented and actor-oriented likelihood. Supports MLE, GDADAMAX, BSIR, and HMC methods. ```APIDOC ## remstimate ### Description A function for the optimization of tie-oriented and actor-oriented likelihood. There are four optimization algorithms: two Frequentists, Maximum Likelihood Estimation (`MLE`) and Adaptive Gradient Descent (`GDADAMAX`), and two Bayesian, Bayesian Sampling Importance Resampling (`BSIR`) and Hamiltonian Monte Carlo (`HMC`). ### Usage ```R remstimate( reh, stats, method = c("MLE", "GDADAMAX", "BSIR", "HMC"), ncores = attr(reh, "ncores"), prior = NULL, nsim = 1000L, nchains = 1L, burnin = 500L, thin = 10L, init = NULL, epochs = 1000L, L = 50L, epsilon = ifelse(method == "GDADAMAX", 0.001, 0.002), seed = NULL, WAIC = FALSE, silent = TRUE, ... ) ``` ### Parameters * **reh**: Input object for the estimation. * **stats**: Statistical data for the estimation. * **method**: Optimization algorithm to use. Options include "MLE", "GDADAMAX", "BSIR", "HMC". Defaults to "MLE". * **ncores**: Number of cores to use for computation. Defaults to the value in the `reh` attribute. * **prior**: Prior distribution information (for Bayesian methods). * **nsim**: Number of simulations (for BSIR). * **nchains**: Number of MCMC chains (for HMC). * **burnin**: Number of burn-in iterations (for HMC). * **thin**: Thinning interval for MCMC samples (for HMC). * **init**: Initial values for the optimization. * **epochs**: Number of training epochs (for GDADAMAX). * **L**: Number of leapfrog steps (for HMC). * **epsilon**: Step size for gradient descent (GDADAMAX) or HMC. * **seed**: Random seed for reproducibility. * **WAIC**: Whether to compute Widely Applicable Information Criterion. * **silent**: Suppress output messages. * **...**: Additional arguments. ``` -------------------------------- ### Define Linear Predictor for Rate and Choice Models Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Specify the linear predictor for actor-oriented rate and choice models using remstats functions. This sets up the effects to be estimated. ```r # specifying linear predictor (for rate and choice model, with `remstats`) rate_model <- ~ 1 + remstats::indegreeSender() choice_model <- ~ remstats::inertia() + remstats::reciprocity() ``` -------------------------------- ### Plot REM Model Results Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Visualize the results of a fitted REM model, including diagnostics. Ensure the model object, event data, and diagnostics object are available. ```R plot(x = ao_mle, reh = ao_reh, diagnostics = ao_mle_diagnostics) ``` -------------------------------- ### Define linear predictor for tie-oriented model Source: https://tilburgnetworkgroup.github.io/remstimate/reference/tie_data.html Defines the linear predictor for a tie-oriented relational event model, including terms for baseline, indegree of the sender, inertia, and reciprocity. ```r tie_model <- ~ 1 + remstats::indegreeSender() + remstats::inertia() + remstats::reciprocity() ``` -------------------------------- ### Estimate REM with HMC Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Utilize Hamiltonian Monte Carlo (HMC) for estimation. Specify the number of simulations per chain, number of chains, burn-in period, and thinning interval. WAIC computation is optional. ```r tie_hmc <- remstimate::remstimate(reh = tie_reh, stats = tie_stats, method = "HMC", ncores = ncores, nsim = 200L, # 200 draws to generate per each chain nchains = 4L, # 4 chains to generate burnin = 200L, # burnin length is 200 thin = 2L, # thinning size set to 2 (the final length of the chains will be 100) seed = 23029, # set a seed only for reproducibility purposes WAIC = TRUE, # setting WAIC computation to TRUE nsimWAIC = 100 # number of draws for the computation of the WAIC set to 100 ) # summary summary(tie_hmc) ``` -------------------------------- ### Calculate AIC for remstimate Object Source: https://tilburgnetworkgroup.github.io/remstimate/reference/aic.html This snippet shows how to calculate the AIC value for a 'remstimate' object after model estimation. Ensure the 'remstimate' object is correctly prepared and estimated. ```R # loading data data(tie_data) # processing event sequence with remify tie_reh <- remify::remify(edgelist = tie_data$edgelist, model = "tie") # specifying linear predictor tie_model <- ~ 1 + remstats::indegreeSender()+ remstats::inertia()+ remstats::reciprocity() # calculating statistics tie_reh_stats <- remstats::remstats(reh = tie_reh, tie_effects = tie_model) # running estimation tie_mle <- remstimate::remstimate(reh = tie_reh, stats = tie_reh_stats, method = "MLE", ncores = 1) # AIC aic(tie_mle) # #> [1] 1218.625 ``` -------------------------------- ### Calculate Information Criteria for REM Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Use these functions to compute AIC, AICC, BIC, and WAIC for a fitted REM object. Ensure the model object (e.g., ao_mle) is already defined. ```R aic(ao_mle) ``` ```R aicc(ao_mle) ``` ```R bic(ao_mle) ``` ```R waic(ao_mle) ``` -------------------------------- ### waic Function Source: https://tilburgnetworkgroup.github.io/remstimate/reference/waic.html The `waic` function computes the WAIC (Watanabe-Akaike's Information Criterion) for a given 'remstimate' object. It is an S3 method designed for objects of class 'remstimate'. ```APIDOC ## waic Function ### Description Computes the WAIC (Watanabe-Akaike's Information Criterion) for a 'remstimate' object. ### Usage ```R waic(object, ...) # S3 method for class 'remstimate' waic(object, ...) ``` ### Arguments * `object` (remstimate): An object of class 'remstimate'. * `...`: Further arguments to be passed to the 'waic' method. ### Value Returns the WAIC value of the 'remstimate' object. ``` -------------------------------- ### Perform Diagnostics for REM Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Generate diagnostic statistics for a fitted REM object. This requires the fitted model, the event data (reh), and the statistics object (stats). ```R ao_mle_diagnostics <- diagnostics(object = ao_mle, reh = ao_reh, stats = ao_stats) ``` -------------------------------- ### plot.remstimate Function Source: https://tilburgnetworkgroup.github.io/remstimate/reference/plot.remstimate.html Generates diagnostic plots for a 'remstimate' object. The type of plots generated depends on the 'approach' attribute of the object and the 'which' argument. ```APIDOC ## plot.remstimate ### Description A function that returns a plot of diagnostics given a 'remstimate' object and depending on the 'approach' attribute. ### Usage ```R plot(x, reh, diagnostics = NULL, which = c(1:4), effects = NULL, sender_effects = NULL, receiver_effects = NULL, ...) ``` ### Arguments * **x** (`remstimate` object): The input remestimate object for which to generate plots. * **reh** (`remify` object): The remify object that was used to create the 'remstimate' object. * **diagnostics** (`'diagnostics' 'remstimate'` object): An object containing diagnostic information. * **which** (numeric vector): Specifies which diagnostic plots to generate. Possible values are: * 1: Q-Q plot of waiting times and density plot of rescaled waiting times. * 2: Standardized Schoenfeld's residuals. * 3: Distributions of posterior draws (histograms, for BSIR and HMC methods). * 4: Trace plots of posterior draws after thinning (for HMC method). Defaults to `c(1:4)`. * **effects** (character vector, optional): For tie-oriented models, the names of statistics for which to plot diagnostics. Defaults to all available statistics. * **sender_effects** (character vector, optional): For actor-oriented models, the names of sender statistics for which to plot diagnostics. Defaults to all available sender statistics. * **receiver_effects** (character vector, optional): For actor-oriented models, the names of receiver statistics for which to plot diagnostics. Defaults to all available receiver statistics. * **...**: Further arguments to be passed to the 'plot' method. ### Value This function does not return a value. It generates plots as a side effect. ### Examples ```R # Example for a tie-oriented model ('MLE') # Load data data(tie_data) # Process event sequence with remify tie_reh <- remify::remify(edgelist = tie_data$edgelist, model = "tie") # Specify linear predictor tie_model <- ~ 1 + remstats::indegreeSender()+ remstats::inertia()+ remstats::reciprocity() # Calculate statistics tie_reh_stats <- remstats::remstats(reh = tie_reh, tie_effects = tie_model) # Note: The actual plotting command using plot.remstimate would follow here, # but requires a 'remstimate' object which is not fully constructed in this snippet. # Example: plot(remestimate_object, tie_reh) ``` ``` -------------------------------- ### Calculate Statistics with remstats Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Compute the network statistics defined in the linear predictor using the `remstats` function. This function requires the processed relational event network (`reh`) and the model formula (`tie_effects`). ```R # calculating statistics (with `remstats`) tie_stats <- remstats::remstats(reh = tie_reh, tie_effects = tie_model) # the 'tomstats' 'remstats' object tie_stats ``` -------------------------------- ### Generate REM Diagnostics Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Generate diagnostic information for a fitted REM object. This function requires the fitted object, the 'reh' object, and the 'stats' object. ```r # diagnostics tie_gd_diagnostics <- diagnostics(object = tie_gd, reh = tie_reh, stats = tie_stats) ``` ```r # diagnostics tie_bsir_diagnostics <- diagnostics(object = tie_bsir, reh = tie_reh, stats = tie_stats) ``` -------------------------------- ### Calculate WAIC for remstimate Object Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Compute the Widely Applicable Information Criterion (WAIC) for a fitted `remstimate` model. WAIC is a Bayesian model comparison criterion. ```R #waic waic(tie_mle) ``` -------------------------------- ### Calculate BIC for remstimate Object Source: https://tilburgnetworkgroup.github.io/remstimate/reference/bic.html Use this function to retrieve the BIC value from a fitted remstimate object. This is typically done after model estimation to evaluate model fit. ```R # BIC bic(tie_mle) #> [1] 1229.045 ``` -------------------------------- ### aic Function for remestimate Objects Source: https://tilburgnetworkgroup.github.io/remstimate/reference/aic.html Calculates and returns the Akaike's Information Criterion (AIC) value for a 'remstimate' object. This is useful for comparing different models fitted to the same data. ```APIDOC ## aic A function that returns the AIC (Akaike's Information Criterion) value in a 'remstimate' object. ### Usage ```R aic(object, ...) # S3 method for class 'remstimate' aic(object, ...) ``` ### Arguments * `object` (remstimate): An object of class 'remstimate'. * `...`: Further arguments to be passed to the 'aic' method. ### Value AIC value of a 'remstimate' object. ### Methods (by class) * `aic(remstimate)`: AIC (Akaike's Information Criterion) value of a 'remstimate' object. ### Examples ```R # loading data data(tie_data) # processing event sequence with remify tie_reh <- remify::remify(edgelist = tie_data$edgelist, model = "tie") # specifying linear predictor tie_model <- ~ 1 + remstats::indegreeSender()+ remstats::inertia()+ remstats::reciprocity() # calculating statistics tie_reh_stats <- remstats::remstats(reh = tie_reh, tie_effects = tie_model) # running estimation tie_mle <- remstimate::remstimate(reh = tie_reh, stats = tie_reh_stats, method = "MLE", ncores = 1) # AIC aic(tie_mle) # #> [1] 1218.625 ``` ``` -------------------------------- ### Calculate BIC for remstimate Object Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Compute the Bayesian Information Criterion (BIC) for a fitted `remstimate` model. BIC is another measure of model fit that penalizes model complexity, with a stronger penalty than AIC. ```R # bic bic(tie_mle) ``` -------------------------------- ### Perform Diagnostics for GDADAMAX REM Source: https://tilburgnetworkgroup.github.io/remstimate/articles/remstimate.html Calculate diagnostic statistics for a REM model fitted with GDADAMAX. This requires the fitted model object, event data, and statistics object. ```R ao_gd_diagnostics <- diagnostics(object = ao_gd, reh = ao_reh, stats = ao_stats) # plot # plot(x = ao_gd, reh = ao_reh, diagnostics = ao_gd_diagnostics) # uncomment to use the plot function ```