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


R broom tidy.sarlm 空间自回归模型的整理方法


这些方法整理了 spatialreg 包中的函数生成的空间自回归模型的系数。

用法

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

参数

x

spatialreg::lagsarlm()spatialreg::errorsarlm() 返回的对象。

conf.int

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

conf.level

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

...

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

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

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

带有列的 tibble::tibble()

conf.high

估计置信区间的上限。

conf.low

估计置信区间的下限。

estimate

回归项的估计值。

p.value

与观察到的统计量相关的两侧 p 值。

statistic

在回归项非零的假设中使用的 T-statistic 的值。

std.error

回归项的标准误差。

term

回归项的名称。

例子



# load libraries for models and data
library(spatialreg)
library(spdep)

# load data
data(oldcol, package = "spdep")

listw <- nb2listw(COL.nb, style = "W")

# fit model
crime_sar <-
  lagsarlm(CRIME ~ INC + HOVAL,
    data = COL.OLD,
    listw = listw,
    method = "eigen"
  )

# summarize model fit with tidiers
tidy(crime_sar)
#> # A tibble: 4 × 5
#>   term        estimate std.error statistic  p.value
#>   <chr>          <dbl>     <dbl>     <dbl>    <dbl>
#> 1 rho            0.431    0.118       3.66 2.50e- 4
#> 2 (Intercept)   45.1      7.18        6.28 3.37e-10
#> 3 INC           -1.03     0.305      -3.38 7.23e- 4
#> 4 HOVAL         -0.266    0.0885     -3.00 2.66e- 3
tidy(crime_sar, conf.int = TRUE)
#> # A tibble: 4 × 7
#>   term        estimate std.error statistic  p.value conf.low conf.high
#>   <chr>          <dbl>     <dbl>     <dbl>    <dbl>    <dbl>     <dbl>
#> 1 rho            0.431    0.118       3.66 2.50e- 4    0.200    0.662 
#> 2 (Intercept)   45.1      7.18        6.28 3.37e-10   31.0     59.1   
#> 3 INC           -1.03     0.305      -3.38 7.23e- 4   -1.63    -0.434 
#> 4 HOVAL         -0.266    0.0885     -3.00 2.66e- 3   -0.439   -0.0925
glance(crime_sar)
#> # A tibble: 1 × 6
#>   r.squared   AIC   BIC deviance logLik  nobs
#>       <dbl> <dbl> <dbl>    <dbl>  <dbl> <int>
#> 1     0.652  375.  384.    4679.  -182.    49
augment(crime_sar)
#> # A tibble: 49 × 6
#>    `(Intercept)`   INC HOVAL  CRIME .fitted .resid
#>            <dbl> <dbl> <dbl>  <dbl>   <dbl>  <dbl>
#>  1             1 21.2   44.6 18.8      22.6  -3.84
#>  2             1  4.48  33.2 32.4      46.6 -14.2 
#>  3             1 11.3   37.1 38.4      41.4  -2.97
#>  4             1  8.44  75    0.178    37.9 -37.7 
#>  5             1 19.5   80.5 15.7      14.2   1.54
#>  6             1 16.0   26.4 30.6      34.3  -3.66
#>  7             1 11.3   23.2 50.7      44.7   5.99
#>  8             1 16.0   28.8 26.1      38.4 -12.3 
#>  9             1  9.87  18   48.6      51.7  -3.12
#> 10             1 13.6   96.4 34.0      16.3  17.7 
#> # ℹ 39 more rows

# fit another model
crime_sem <- errorsarlm(CRIME ~ INC + HOVAL, data = COL.OLD, listw)

# summarize model fit with tidiers
tidy(crime_sem)
#> # A tibble: 4 × 5
#>   term        estimate std.error statistic   p.value
#>   <chr>          <dbl>     <dbl>     <dbl>     <dbl>
#> 1 (Intercept)   59.9      5.37       11.2  0        
#> 2 INC           -0.941    0.331      -2.85 0.00441  
#> 3 HOVAL         -0.302    0.0905     -3.34 0.000836 
#> 4 lambda         0.562    0.134       4.20 0.0000271
tidy(crime_sem, conf.int = TRUE)
#> # A tibble: 4 × 7
#>   term        estimate std.error statistic   p.value conf.low conf.high
#>   <chr>          <dbl>     <dbl>     <dbl>     <dbl>    <dbl>     <dbl>
#> 1 (Intercept)   59.9      5.37       11.2  0           49.4      70.4  
#> 2 INC           -0.941    0.331      -2.85 0.00441     -1.59     -0.293
#> 3 HOVAL         -0.302    0.0905     -3.34 0.000836    -0.480    -0.125
#> 4 lambda         0.562    0.134       4.20 0.0000271    0.299     0.824
glance(crime_sem)
#> # A tibble: 1 × 6
#>   r.squared   AIC   BIC deviance logLik  nobs
#>       <dbl> <dbl> <dbl>    <dbl>  <dbl> <int>
#> 1     0.658  377.  386.    4683.  -183.    49
augment(crime_sem)
#> # A tibble: 49 × 6
#>    `(Intercept)`   INC HOVAL  CRIME .fitted  .resid
#>            <dbl> <dbl> <dbl>  <dbl>   <dbl>   <dbl>
#>  1             1 21.2   44.6 18.8      22.5  -3.70 
#>  2             1  4.48  33.2 32.4      44.9 -12.5  
#>  3             1 11.3   37.1 38.4      38.2   0.223
#>  4             1  8.44  75    0.178    35.0 -34.8  
#>  5             1 19.5   80.5 15.7      13.3   2.45 
#>  6             1 16.0   26.4 30.6      35.0  -4.33 
#>  7             1 11.3   23.2 50.7      42.3   8.41 
#>  8             1 16.0   28.8 26.1      39.4 -13.3  
#>  9             1  9.87  18   48.6      49.3  -0.721
#> 10             1 13.6   96.4 34.0      16.6  17.4  
#> # ℹ 39 more rows

# fit another model
crime_sac <- sacsarlm(CRIME ~ INC + HOVAL, data = COL.OLD, listw)

# summarize model fit with tidiers
tidy(crime_sac)
#> # A tibble: 5 × 5
#>   term        estimate std.error statistic    p.value
#>   <chr>          <dbl>     <dbl>     <dbl>      <dbl>
#> 1 rho            0.368    0.197      1.87  0.0613    
#> 2 (Intercept)   47.8      9.90       4.83  0.00000140
#> 3 INC           -1.03     0.326     -3.14  0.00167   
#> 4 HOVAL         -0.282    0.0900    -3.13  0.00176   
#> 5 lambda         0.167    0.297      0.562 0.574     
tidy(crime_sac, conf.int = TRUE)
#> # A tibble: 5 × 7
#>   term        estimate std.error statistic    p.value conf.low conf.high
#>   <chr>          <dbl>     <dbl>     <dbl>      <dbl>    <dbl>     <dbl>
#> 1 rho            0.368    0.197      1.87  0.0613      -0.0174     0.754
#> 2 (Intercept)   47.8      9.90       4.83  0.00000140  28.4       67.2  
#> 3 INC           -1.03     0.326     -3.14  0.00167     -1.67      -0.386
#> 4 HOVAL         -0.282    0.0900    -3.13  0.00176     -0.458     -0.105
#> 5 lambda         0.167    0.297      0.562 0.574       -0.415      0.748
glance(crime_sac)
#> # A tibble: 1 × 6
#>   r.squared   AIC   BIC deviance logLik  nobs
#>       <dbl> <dbl> <dbl>    <dbl>  <dbl> <int>
#> 1     0.652  376.  388.    4685.  -182.    49
augment(crime_sac)
#> # A tibble: 49 × 6
#>    `(Intercept)`   INC HOVAL  CRIME .fitted .resid
#>            <dbl> <dbl> <dbl>  <dbl>   <dbl>  <dbl>
#>  1             1 21.2   44.6 18.8      22.2  -3.37
#>  2             1  4.48  33.2 32.4      46.4 -14.0 
#>  3             1 11.3   37.1 38.4      40.4  -2.00
#>  4             1  8.44  75    0.178    37.5 -37.3 
#>  5             1 19.5   80.5 15.7      13.5   2.25
#>  6             1 16.0   26.4 30.6      34.4  -3.74
#>  7             1 11.3   23.2 50.7      44.1   6.60
#>  8             1 16.0   28.8 26.1      39.0 -12.9 
#>  9             1  9.87  18   48.6      51.5  -2.93
#> 10             1 13.6   96.4 34.0      15.8  18.2 
#> # ℹ 39 more rows
源代码:R/spdep-tidiers.R

相关用法


注:本文由纯净天空筛选整理自大神的英文原创作品 Tidying methods for spatially autoregressive models。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。