分位数回归和p值-获得更多小数位 [英] Quantile regression and p-values - getting more decimal places
问题描述
使用R和程序包quantreg
,我正在对数据进行分位数回归分析.
Using R, and package quantreg
, I am performing quantile regression analyses to my data.
我可以使用摘要函数中的se(标准误差)估计器访问p值,如下所示,但是我只能得到5个小数位,并且还想要更多.
I can get access to the p-values using the se (standard error) estimator in the summary function, as below, however I only get 5 decimal places, and would like more.
model <- rq(outcome ~ predictor)
summary(model, se="ker")
Call: rq(formula = outcome ~ predictor)
tau: [1] 0.5
Coefficients:
Value Std. Error t value Pr(>|t|)
(Intercept) 78.68182 2.89984 27.13312 0.00000
predictor 0.22727 0.03885 5.84943 0.00000
我如何获得p值的更多小数位?
How might I get access to more decimal places on the p-values?
好,所以我可以通过选择包含数值结果矩阵的子对象来获得更多的小数位;
Ok, so I can get some more decimal places by selecting the sub-object that contains the matrix of numerical results;
> summary(model, se="ker")[[3]]
Value Std. Error t value Pr(>|t|)
(Intercept) 78.6818182 3.13897835 25.066059 0.000000e+00
predictor 0.2272727 0.04105681 5.535567 4.397638e-08
然而,当值<1e-12时,P值仍四舍五入(上面的输出是简化的示例模型).通过应用@seancarmody的建议,我可以得到更多;
However the P-value is still rounded to 0 when the value is <1e-12 (the above output is a simplified example model). I can get some more by applying the suggestion from @seancarmody ;
format(summary(model, se="ker")[[3]], digits=22)
但是如果P< 1e-22仍然四舍五入,并且如果"digits"设置为> 22,则会出现以下错误;
But if P < 1e-22 it is still rounded to 0, and if "digits" is set to > 22 I get the following error;
format(summary(model, se="ker")[[3]], digits=23)
prettyNum(.Internal(format(x,trim,digits,nsmall,width,3L,: 无效的数字"参数
Error in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, : invalid 'digits' argument
是否可以访问更多的小数位?
Is it possible to access even more decimal places?
推荐答案
要想进一步了解,我认为您必须深入了解p值的计算方式.特别是summary.rq
具有以下代码段:
To get any farther I think you have to dig in and see how the p values are calculated. In particular, summary.rq
has the following snippet:
coef[, 4] <- if (rdf > 0)
2 * (1 - pt(abs(coef[, 3]), rdf))
else NA
这实际上是p值的相当不精确的计算(在通常情况下这并不重要).您可以通过检索p值的 log 来获得最大的精度[例如,原则上您可以检索小于10 ^ {-308}的p值,即R可以表示为双精度值],例如
This is actually a fairly imprecise calculation of the p-value (which under ordinary circumstances doesn't really matter). You can probably get the maximum amount of precision by retrieving the log of the p-value [for example, you could in principle retrieve p-values less than 10^{-308}, the smallest value that R can represent as a double-precision value], e.g.
ss <- summary(model,se="ker")
log(2)+pt(abs(ss$coefficients[,"t value"]),
lower.tail=FALSE,log.p=TRUE,df=ss$rdf)
lower.tail=FALSE
参数为您提供CDF的补码(上尾)值; log.p=TRUE
表示您需要日志值;添加log(2)
使其两面.
The lower.tail=FALSE
argument gives you the complement (upper-tail) value of the CDF; log.p=TRUE
says you want the log value; adding the log(2)
makes it two-sided.
这篇关于分位数回归和p值-获得更多小数位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!