当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R broom tidy.ergm 整理 a(n) ergm 对象


Tidy 总结了有关模型组件的信息。模型组件可能是回归中的单个项、单个假设、聚类或类。 tidy 所认为的模型组件的确切含义因模型而异,但通常是不言而喻的。如果模型具有多种不同类型的组件,您将需要指定要返回哪些组件。

这些方法应该适用于符合以下要求的任何模型尔格姆类,例如由加权网络产生的类ergm.count包。

用法

# S3 method for ergm
tidy(x, conf.int = FALSE, conf.level = 0.95, exponentiate = FALSE, ...)

参数

x

从调用 ergm::ergm() 返回的 ergm 对象。

conf.int

逻辑指示是否在整理的输出中包含置信区间。默认为 FALSE

conf.level

用于置信区间的置信水平(如果 conf.int = TRUE )。必须严格大于 0 且小于 1。默认为 0.95,对应于 95% 的置信区间。

exponentiate

逻辑指示是否对系数估计值取幂。这对于逻辑回归和多项回归来说是典型的,但如果没有 log 或 logit 链接,那么这是一个坏主意。默认为 FALSE

...

要传递给 ergm::summary() 的其他参数。注意:错误指定的参数可能会被默默地忽略。

tibble::tibble,指数随机图模型中的每个系数占一行,列为:

term

正在估计和测试的模型中的项

estimate

估计系数

std.error

标准误

mcmc.error

MCMC 错误

p.value

两侧 p 值

参考

Hunter DR、Handcock MS、Butts CT、Goodreau SM、Morris M (2008b)。尔格姆:用于拟合、模拟和诊断 Exponential-Family 网络模型的软件包。统计软件杂志,24(3)。https://www.jstatsoft.org/v24/i03/.

也可以看看

例子


# load libraries for models and data
library(ergm)
#> 
#> ‘ergm’ 4.5.0 (2023-05-27), 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.
#> 
#> Attaching package: ‘ergm’
#> The following object is masked from ‘package:btergm’:
#> 
#>     gof

# load the Florentine marriage network data
data(florentine)

# fit a model where the propensity to form ties between
# families depends on the absolute difference in wealth
gest <- ergm(flomarriage ~ edges + absdiff("wealth"))
#> Starting maximum pseudolikelihood estimation (MPLE):
#> Obtaining the responsible dyads.
#> Evaluating the predictor and response matrix.
#> Maximizing the pseudolikelihood.
#> Finished MPLE.
#> Evaluating log-likelihood at the estimate. 
#> 

# show terms, coefficient estimates and errors
tidy(gest)
#> # A tibble: 2 × 6
#>   term           estimate std.error mcmc.error statistic      p.value
#>   <chr>             <dbl>     <dbl>      <dbl>     <dbl>        <dbl>
#> 1 edges           -2.30     0.402            0     -5.73 0.0000000102
#> 2 absdiff.wealth   0.0155   0.00616          0      2.52 0.0117      

# show coefficients as odds ratios with a 99% CI
tidy(gest, exponentiate = TRUE, conf.int = TRUE, conf.level = 0.99)
#> Warning: Exponentiating but model didn't use log or logit link.
#> # A tibble: 2 × 8
#>   term  estimate std.error mcmc.error statistic p.value conf.low conf.high
#>   <chr>    <dbl>     <dbl>      <dbl>     <dbl>   <dbl>    <dbl>     <dbl>
#> 1 edges    0.100   0.402            0     -5.73 1.02e-8   0.0355     0.282
#> 2 absd…    1.02    0.00616          0      2.52 1.17e-2   1.00       1.03 

# take a look at likelihood measures and other
# control parameters used during MCMC estimation
glance(gest)
#> # A tibble: 1 × 5
#>   independence iterations logLik   AIC   BIC
#>   <lgl>             <int>  <dbl> <dbl> <dbl>
#> 1 TRUE                  4  -51.0  106.  112.
glance(gest, deviance = TRUE)
#> # A tibble: 1 × 9
#>   independence iterations logLik null.deviance df.null residual.deviance
#>   <lgl>             <int>  <dbl> <logLik>        <int>             <dbl>
#> 1 TRUE                  4  -51.0 166.3553          120              102.
#> # ℹ 3 more variables: df.residual <int>, AIC <dbl>, BIC <dbl>
glance(gest, mcmc = TRUE)
#> Though `glance` was supplied `mcmc = TRUE`, the model was not fittedusing MCMC, so the corresponding columns will be omitted.
#> # A tibble: 1 × 5
#>   independence iterations logLik   AIC   BIC
#>   <lgl>             <int>  <dbl> <dbl> <dbl>
#> 1 TRUE                  4  -51.0  106.  112.
源代码:R/ergm-tidiers.R

相关用法


注:本文由纯净天空筛选整理自大神的英文原创作品 Tidy a(n) ergm object。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。