Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
rms包fastbw回归函数的P值_R_Regression_Linear Regression_Rms - Fatal编程技术网

rms包fastbw回归函数的P值

rms包fastbw回归函数的P值,r,regression,linear-regression,rms,R,Regression,Linear Regression,Rms,我正在尝试rms包的fastbw函数,用于如下反向回归(使用mtcars数据集): 以下是该模型的结构: > str(modbw) List of 10 $ result : num [1:4, 1:8] 0.0463 0.1701 0.5775 0.4152 1 ... ..- attr(*, "dimnames")=List of 2 .. ..$ : chr [1:4] "drat" "vs" "am" "gear" .. ..$ : chr [1:8]

我正在尝试rms包的fastbw函数,用于如下反向回归(使用mtcars数据集):

以下是该模型的结构:

> str(modbw)
List of 10
 $ result         : num [1:4, 1:8] 0.0463 0.1701 0.5775 0.4152 1 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:4] "drat" "vs" "am" "gear"
  .. ..$ : chr [1:8] "Chi-Sq" "d.f." "P" "Residual" ...
 $ names.kept     : chr [1:2] "cyl" "wt"
 $ factors.kept   : int [1:2] 3 5
 $ factors.deleted: int [1:4] 4 2 1 6
 $ parms.kept     : int [1:3] 1 4 6
 $ parms.deleted  : int [1:4] 5 3 2 7
 $ coefficients   : Named num [1:3] 39.69 -1.51 -3.19
  ..- attr(*, "names")= chr [1:3] "Intercept" "cyl" "wt"
 $ var            : num [1:3, 1:3] 3.254 -0.303 -0.358 -0.303 0.19 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:3] "Intercept" "cyl" "wt"
  .. ..$ : chr [1:3] "Intercept" "cyl" "wt"
 $ Coefficients   : num [1:4, 1:7] 41.26 43.17 42.39 39.69 1.68 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:7] "Intercept" "am" "vs" "cyl" ...
 $ force          : NULL
 - attr(*, "class")= chr "fastbw"
> summary(modbw)
                Length Class  Mode     
result          32     -none- numeric  
names.kept       2     -none- character
factors.kept     2     -none- numeric  
factors.deleted  4     -none- numeric  
parms.kept       3     -none- numeric  
parms.deleted    4     -none- numeric  
coefficients     3     -none- numeric  
var              9     -none- numeric  
Coefficients    28     -none- numeric  
force            0     -none- NULL     
> 
> summary.lm(modbw)
Error in if (p == 0) { : argument is of length zero
以下是summary的输出结构(summary.lm函数在此模型上不起作用):


但我找不到其中任何一个的p值。如何获取fastbw函数最终模型的P值列表?

P值的计算发生在

print.fastbw
函数中,由于某种原因,它们不会从函数返回。我本来打算自己使用
print.fastbw
的源代码来重新计算它们,但我发现重新编写自己的
print.fastbw
函数来返回p值要快得多

以下是经过修改的函数(注意print2不是通用函数):


它们是动态计算的。深入挖掘
rms:::print.fastbw
(类对象的
print
方法
fastbw
)您可以找到:

   cof <- coef(x)
   vv <- if (length(cof) > 1) diag(x$var) else x$var
   z <- cof/sqrt(vv)
   stats <- cbind(cof, sqrt(vv), z, 1 - pchisq(z^2, 1))

cof我很确定
fastbw
不是用于统计推断的。。。你有哈雷尔的书《回归建模策略》吗?P值出现在输出中。因此,它在这里也一定相当重要。为什么在建筑物的任何地方都看不到它?
print2.fastbw <- function (x, digits = 4, estimates = TRUE, ...) 
{
  res <- x$result
  fd <- x$factors.deleted
  if (length(fd)) {
    cres <- cbind(dimnames(res)[[1]], format(round(res[, 
                                                       1], 2)), format(res[, 2]), format(round(res[, 3], 
                                                                                               4)), format(round(res[, 4], 2)), format(res[, 5]), 
                  format(round(res[, 6], 4)), format(round(res[, 7], 
                                                           2)), if (ncol(res) > 7) 
                                                             format(round(res[, 8], 3)))
    dimnames(cres) <- list(rep("", nrow(cres)), c("Deleted", 
                                                  dimnames(res)[[2]]))
    cat("\n")
    if (length(x$force)) 
      cat("Parameters forced into all models:\n", paste(x$force, 
                                                        collapse = ", "), "\n\n")
    print(cres, quote = FALSE)
    if (estimates && length(x$coef)) {
      cat("\nApproximate Estimates after Deleting Factors\n\n")
      cof <- coef(x)
      vv <- if (length(cof) > 1) 
        diag(x$var)
      else x$var
      z <- cof/sqrt(vv)
      stats <- cbind(cof, sqrt(vv), z, 1 - pchisq(z^2, 
                                                  1))
      dimnames(stats) <- list(names(cof), c("Coef", "S.E.", 
                                            "Wald Z", "P"))
      return(stats)
    }
  }
  else cat("\nNo Factors Deleted\n")
  cat("\nFactors in Final Model\n\n")
  nk <- x$names.kept
  if (length(nk)) 
    print(nk, quote = FALSE)
  else cat("None\n")
}
> results <- print2.fastbw(modbw)

 Deleted Chi-Sq d.f. P      Residual d.f. P      AIC   R2   
 drat    0.05   1    0.8296 0.05     1    0.8296 -1.95 0.838
 vs      0.17   1    0.6800 0.22     2    0.8974 -3.78 0.837
 am      0.58   1    0.4473 0.79     3    0.8509 -5.21 0.833
 gear    0.42   1    0.5194 1.21     4    0.8766 -6.79 0.830

Approximate Estimates after Deleting Factors

> results
               Coef      S.E.    Wald Z            P
Intercept 39.686261 1.8039853 21.999216 0.000000e+00
cyl       -1.507795 0.4362091 -3.456588 5.470608e-04
wt        -3.190972 0.7961871 -4.007817 6.128261e-05
> results[,4]
   Intercept          cyl           wt 
0.000000e+00 5.470608e-04 6.128261e-05 
   cof <- coef(x)
   vv <- if (length(cof) > 1) diag(x$var) else x$var
   z <- cof/sqrt(vv)
   stats <- cbind(cof, sqrt(vv), z, 1 - pchisq(z^2, 1))