當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。