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


R broom glance.mfx 浏览一个 (n) mfx 对象


Glance 接受模型对象并返回 tibble::tibble(),其中仅包含一行模型摘要。摘要通常是拟合优度度量、残差假设检验的 p 值或模型收敛信息。

Glance 永远不会返返回自对建模函数的原始调用的信息。这包括建模函数的名称或传递给建模函数的任何参数。

Glance 不计算汇总度量。相反,它将这些计算外包给适当的方法并将结果收集在一起。有时拟合优度测量是不确定的。在这些情况下,该度量将报告为 NA

无论模型矩阵是否秩亏,Glance 都会返回相同的列数。如果是这样,则不再具有明确定义值的列中的条目将使用适当类型的 NA 进行填充。

用法

# S3 method for mfx
glance(x, ...)

# S3 method for logitmfx
glance(x, ...)

# S3 method for negbinmfx
glance(x, ...)

# S3 method for poissonmfx
glance(x, ...)

# S3 method for probitmfx
glance(x, ...)

参数

x

logitmfxnegbinmfxpoissonmfxprobitmfx 对象。 (请注意,betamfx 对象接收自己的一组整理器。)

...

附加参数。不曾用过。仅需要匹配通用签名。注意:拼写错误的参数将被吸收到 ... 中,并被忽略。如果拼写错误的参数有默认值,则将使用默认值。例如,如果您传递 conf.lvel = 0.9 ,所有计算将使用 conf.level = 0.95 进行。这里有两个异常:

  • tidy() 方法在提供 exponentiate 参数时会发出警告(如果该参数将被忽略)。

  • augment() 方法在提供 newdata 参数时会发出警告(如果该参数将被忽略)。

细节

此通用概览方法包装 glance.glm(),以获取 mfx 包中的适用对象。

恰好只有一行和一列的 tibble::tibble()

AIC

模型的 Akaike 信息准则。

BIC

模型的贝叶斯信息准则。

deviance

模型的偏差。

df.null

零模型使用的自由度。

df.residual

剩余自由度。

logLik

模型的对数似然。 [stats::logLik()] 可能是一个有用的参考。

nobs

使用的观察数。

null.deviance

零模型的偏差。

例子


# load libraries for models and data
library(mfx)

# get the marginal effects from a logit regression
mod_logmfx <- logitmfx(am ~ cyl + hp + wt, atmean = TRUE, data = mtcars)

tidy(mod_logmfx, conf.int = TRUE)
#> # A tibble: 3 × 8
#>   term  atmean estimate std.error statistic p.value conf.low conf.high
#>   <chr> <lgl>     <dbl>     <dbl>     <dbl>   <dbl>    <dbl>     <dbl>
#> 1 cyl   TRUE    0.0538    0.113       0.475   0.635 -0.178     0.286  
#> 2 hp    TRUE    0.00359   0.00290     1.24    0.216 -0.00236   0.00954
#> 3 wt    TRUE   -1.01      0.668      -1.51    0.131 -2.38      0.359  

# compare with the naive model coefficients of the same logit call
tidy(
  glm(am ~ cyl + hp + wt, family = binomial, data = mtcars),
  conf.int = TRUE
)
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> # A tibble: 4 × 7
#>   term        estimate std.error statistic p.value  conf.low conf.high
#>   <chr>          <dbl>     <dbl>     <dbl>   <dbl>     <dbl>     <dbl>
#> 1 (Intercept)  19.7       8.12       2.43   0.0152   8.56      44.3   
#> 2 cyl           0.488     1.07       0.455  0.649   -1.53       3.12  
#> 3 hp            0.0326    0.0189     1.73   0.0840   0.00332    0.0884
#> 4 wt           -9.15      4.15      -2.20   0.0276 -21.4       -3.48  

augment(mod_logmfx)
#> # A tibble: 32 × 11
#>    .rownames    am   cyl    hp    wt .fitted  .resid   .hat .sigma .cooksd
#>    <chr>     <dbl> <dbl> <dbl> <dbl>   <dbl>   <dbl>  <dbl>  <dbl>   <dbl>
#>  1 Mazda RX4     1     6   110  2.62  2.24    0.449  0.278   0.595 1.42e-2
#>  2 Mazda RX…     1     6   110  2.88 -0.0912  1.22   0.352   0.529 2.30e-1
#>  3 Datsun 7…     1     4    93  2.32  3.46    0.249  0.0960  0.602 9.26e-4
#>  4 Hornet 4…     0     6   110  3.22 -3.20   -0.282  0.0945  0.601 1.17e-3
#>  5 Hornet S…     0     8   175  3.44 -2.17   -0.466  0.220   0.595 1.03e-2
#>  6 Valiant       0     6   105  3.46 -5.61   -0.0856 0.0221  0.604 2.12e-5
#>  7 Duster 3…     0     8   245  3.57 -1.07   -0.766  0.337   0.576 6.55e-2
#>  8 Merc 240D     0     4    62  3.19 -5.51   -0.0897 0.0376  0.603 4.10e-5
#>  9 Merc 230      0     4    95  3.15 -4.07   -0.184  0.122   0.603 6.76e-4
#> 10 Merc 280      0     6   123  3.44 -4.84   -0.126  0.0375  0.603 8.02e-5
#> # ℹ 22 more rows
#> # ℹ 1 more variable: .std.resid <dbl>
glance(mod_logmfx)
#> # A tibble: 1 × 8
#>   null.deviance df.null logLik   AIC   BIC deviance df.residual  nobs
#>           <dbl>   <int>  <dbl> <dbl> <dbl>    <dbl>       <int> <int>
#> 1          43.2      31  -4.92  17.8  23.7     9.84          28    32

# another example, this time using probit regression
mod_probmfx <- probitmfx(am ~ cyl + hp + wt, atmean = TRUE, data = mtcars)
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

tidy(mod_probmfx, conf.int = TRUE)
#> # A tibble: 3 × 8
#>   term  atmean estimate std.error statistic p.value conf.low conf.high
#>   <chr> <lgl>     <dbl>     <dbl>     <dbl>   <dbl>    <dbl>     <dbl>
#> 1 cyl   TRUE    0.0616    0.112       0.548  0.583  -0.169     0.292  
#> 2 hp    TRUE    0.00383   0.00282     1.36   0.174  -0.00194   0.00960
#> 3 wt    TRUE   -1.06      0.594      -1.78   0.0753 -2.27      0.160  
augment(mod_probmfx)
#> # A tibble: 32 × 11
#>    .rownames    am   cyl    hp    wt .fitted  .resid   .hat .sigma .cooksd
#>    <chr>     <dbl> <dbl> <dbl> <dbl>   <dbl>   <dbl>  <dbl>  <dbl>   <dbl>
#>  1 Mazda RX4     1     6   110  2.62   1.21   0.490  0.308   0.585 2.05e-2
#>  2 Mazda RX…     1     6   110  2.88  -0.129  1.27   0.249   0.526 1.36e-1
#>  3 Datsun 7…     1     4    93  2.32   1.85   0.256  0.134   0.594 1.48e-3
#>  4 Hornet 4…     0     6   110  3.22  -1.92  -0.237  0.116   0.594 1.05e-3
#>  5 Hornet S…     0     8   175  3.44  -1.25  -0.474  0.236   0.587 1.20e-2
#>  6 Valiant       0     6   105  3.46  -3.30  -0.0312 0.0111  0.596 1.39e-6
#>  7 Duster 3…     0     8   245  3.57  -0.595 -0.804  0.285   0.567 5.32e-2
#>  8 Merc 240D     0     4    62  3.19  -3.31  -0.0304 0.0179  0.596 2.15e-6
#>  9 Merc 230      0     4    95  3.15  -2.47  -0.116  0.130   0.596 2.89e-4
#> 10 Merc 280      0     6   123  3.44  -2.85  -0.0662 0.0315  0.596 1.84e-5
#> # ℹ 22 more rows
#> # ℹ 1 more variable: .std.resid <dbl>
glance(mod_probmfx)
#> # A tibble: 1 × 8
#>   null.deviance df.null logLik   AIC   BIC deviance df.residual  nobs
#>           <dbl>   <int>  <dbl> <dbl> <dbl>    <dbl>       <int> <int>
#> 1          43.2      31  -4.80  17.6  23.5     9.59          28    32
源代码:R/mfx-tidiers.R

相关用法


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