{"id":31041736,"url":"https://github.com/stocnet/erpm","last_synced_at":"2026-02-27T01:02:41.167Z","repository":{"id":45004352,"uuid":"260239810","full_name":"stocnet/ERPM","owner":"stocnet","description":"Simulation and estimation of Exponential Random Partition Models","archived":false,"fork":false,"pushed_at":"2025-07-28T06:53:11.000Z","size":15908,"stargazers_count":11,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-08T18:57:49.626Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stocnet.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-04-30T14:50:58.000Z","updated_at":"2025-05-15T12:15:09.000Z","dependencies_parsed_at":"2024-02-29T14:45:31.436Z","dependency_job_id":"ccf1b6e2-13a9-4bc7-bd46-015bf4719f4c","html_url":"https://github.com/stocnet/ERPM","commit_stats":null,"previous_names":["stocnet/erpm","marion-hoffman/erpm"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/stocnet/ERPM","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stocnet%2FERPM","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stocnet%2FERPM/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stocnet%2FERPM/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stocnet%2FERPM/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stocnet","download_url":"https://codeload.github.com/stocnet/ERPM/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stocnet%2FERPM/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275094398,"owners_count":25404446,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-14T02:00:10.474Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-09-14T10:40:36.055Z","updated_at":"2026-02-27T01:02:41.114Z","avatar_url":"https://github.com/stocnet.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n\n# ERPM\n\n\u003c!-- badges: start --\u003e\n\u003c!-- badges: end --\u003e\n\nERPM is the software implementation of the statistical model outlined in:\n\nHoffman, M., Block, P., \u0026 Snijders, T. A. (2023). Modeling partitions of individuals. Sociological Methodology, 53(1), 1-41.\n\n[Link to the study in Sociological Methodology](https://doi.org/10.1177/00811750221145166).\n\nThe model allows for the analysis of emergent group compositions in partitions, i.e., sets of non-overlapping groups. For a given partition of individuals (or nodes, to follow the language of network analysis), we can use this model to understand group formation processes that led to the observation of this partition, based on individual attributes, relations between individuals, and size-related factors. It can be seen as an extension of Exponential Random Graph Models (ERGMs) to the case of partition objects. With this package, one can either simulate this model or estimate its parameters for a given dataset.\n\nThis package also provides a longitudinal extension of the model, for a list of partitions, where each partition depends on the previous partitions. It follows the definition proposed in:\n\nHoffman, M., \u0026 Chabot, T. (2023). The role of selection in socioeconomic homophily: Evidence from an adolescent summer camp. Social Networks, 74, 259-274.\n\nThe **ERPM Manual** is available here on github in the documentation folder.\n\n# Note from the developers\n\nThe package and the documentation might still have bugs or errors, or you might not be able to do what you want. \nIn that case, or if you are unsure please create an issue here or directly send an email to the package maintainer (marion.hoffman[at]iast.fr).\n\nWe are currently (Mar 2024) on version 0.1.0 on github. \n\n# Installation\n\nYou can install ERPM either from GitHub or from CRAN.\n\n``` r\n# from GitHub:\n# install.packages(\"remotes\")\nremotes::install_github(\"stocnet/ERPM\")\n```\n\n``` r\n# from CRAN:\ninstall.packages(\"ERPM\")\n```\n\n# Cross-sectional example\n\nIn this section, we outline a simple example with synthetic data.\n\n```{r}\nlibrary(ERPM)\n```\n\n## The Data\n\nLet us define a set of n = 6 nodes with three attributes (label, gender, and age), and an arbitrary covariate matrix (friendship). \nWe create the following dataframe.\n\n```{r}\nn \u003c- 6 \nnodes \u003c- data.frame(label = c(\"A\",\"B\",\"C\",\"D\",\"E\",\"F\"),\n                    gender = c(1,1,2,1,2,2),\n                    age = c(20,22,25,30,30,31)) \nfriendship \u003c- matrix(c(0, 1, 1, 1, 0, 0,\n                       1, 0, 0, 0, 1, 0,\n                       1, 0, 0, 0, 1, 0,\n                       1, 0, 0, 0, 0, 0,\n                       0, 1, 1, 0, 0, 1,\n                       0, 0, 0, 0, 1, 0), 6, 6, TRUE) \n```\n\nWe consider a partition for these 6 individuals. We define a vector with six elements, indicating the id of each individual's group.\n\n```{r}\npartition \u003c- c(1,1,2,2,2,3)\n```\n\n## Model specification\n\nFirst, we need to choose the effects (i.e., explaining variables) we want to include. For example we set four (which is of course not reasonable for 6 nodes):\n  1. \"num_groups\": tendency to form more groups\n  2. \"same\" (for the gender covariate): tendency to form groups with individuals with the same gender\n  3. \"diff\" (for the age covariate): tendency to form groups with individuals with high age differences\n  4. \"tie\" (for the friendship covariate): tendency to form groups with friends\n\n```{r}\neffects \u003c- list(names = c(\"num_groups\",\"same\",\"diff\",\"tie\"),\n                objects = c(\"partition\",\"gender\",\"age\",\"friendship\"))\nobjects \u003c- list()\nobjects[[1]] \u003c- list(name = \"friendship\", object = friendship)\n```\n\nThe effect objects should contain names of pre-written functions in the package (see manual for all effect names) as well as objects they are referring to (either the partition, or covariates). When objects are not individual covariates, we need to create an additional list to store these extra objects.\n\n## Estimation \n\nThe parameters of the model can be estimated using Maximum-likelihood estimation (equivalent to the Method of Moment estimation). For more details on the parametrization of the estimation algorithm, see the manual.\n\n```{r}\nestimation \u003c- estimate_ERPM(partition, \n                          nodes, \n                          objects, \n                          effects, \n                          startingestimates = c(-1.5,0.2,-0.2,0.2), \n                          burnin = 100, \n                          thining = 20,\n                          length.p1 = 500, # number of samples in phase 1\n                          multiplication.iter.p2 = 20,  # multiplication factor for the number of iteration in phase 2 subphases \n                          num.steps.p2 = 4, # number of phase 2 subphases\n                          length.p3 = 1000) # number of samples in phase 3\nestimation$results\n```\n\n\n### Simulation\n\nWe can check how the model reproduces statistics of the observed data by simulating the estimated model. We can also use this function to simulate theoretical models.\n\n```{r}\nnsimulations \u003c- 1000\nsimulations \u003c- draw_Metropolis_single(theta = estimation$results$est, \n                          first.partition = partition, \n                          nodes = nodes, \n                          effects = effects, \n                          objects = objects, \n                          burnin = 100, \n                          thining = 20, \n                          num.steps = nsimulations, \n                          neighborhood = c(1,1,1), \n                          sizes.allowed = 1:n,\n                          sizes.simulated = 1:n,\n                          return.all.partitions = T)\n```\n\n\n### Log-likelihood and AIC\n\nFinally, we can estimate the log-likelihood and AIC of the model (useful to compare two models for example). First we need to estimate the ML estimates of a simple model with only one parameter for number of groups (this parameter should be in the model!).\n\n```{r}\nlikelihood_function \u003c- function(x){ exp(x*max(partition)) / compute_numgroups_denominator(n,x)}\ncurve(likelihood_function, from=-2, to=0)\nparameter_base \u003c- optimize(likelihood_function, interval=c(-2, 0), maximum=TRUE)\nparameters_basemodel \u003c- c(parameter_base$maximum,0,0,0)\n```\n\nThen we can get our estimated logL and AIC.\n\n```{r}\nlogL_AIC \u003c- estimate_logL(partition,\n                         nodes,\n                         effects, \n                         objects,\n                         theta = estimation$results$est,\n                         theta_0 = parameters_basemodel,\n                         M = 3,\n                         num.steps = 200,\n                         burnin = 100,\n                         thining = 20)\nlogL_AIC$logL\nlogL_AIC$AIC\n```\n\n# More ...\n\nFor more details on the longitudinal version of the model or other functions, have a look at the manual in the documentation folder or the example script in the scripts folder.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstocnet%2Ferpm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstocnet%2Ferpm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstocnet%2Ferpm/lists"}