从 R 中的多个分位数的分位数回归中访问 p 值
Access p-value from quantile regression for multiple quantiles in R
我想访问具有多个分位数的分位数回归的 p 值。
fit2 <- rq(speed ~ vsby_avg + snwd_avg, tau=c(.05, 0.95), data = test_data)
fit2_summ <- summary(fit2)
str(fit2_summ)
给出以下结果
List of 2
$ :List of 6
..$ call : language rq(formula = speed ~ vsby_avg + snwd_avg, tau = c(0.05, 0.95), data = test_data)
..$ terms :Classes 'terms', 'formula' language speed ~ vsby_avg + snwd_avg
.. .. ..- attr(*, "variables")= language list(speed, vsby_avg, snwd_avg)
..$ coefficients: num [1:3, 1:4] 57.63195 0.13474 -0.00337 0.1919 0.01212 ...
我无法使用 fit2_summ$coefficients[,4]
访问第 50 和第 95 分位数的 p 值,因为摘要模型存在于 2 个分位数而不是单个分位数,在这种情况下,上述命令将具有成功了。
你应该指定一个计算se的方法:
# using mtcars
library(quantreg)
fit <- rq(mpg ~ cyl + disp, tau = c(0.05, 0.95), data = mtcars)
fit.smy <- summary(fit, se = 'boot')
# > fit.smy
#
# Call: rq(formula = mpg ~ cyl + disp, tau = c(0.05, 0.95), data = mtcars)
#
# tau: [1] 0.05
#
# Coefficients:
# Value Std. Error t value Pr(>|t|)
# (Intercept) 29.02978 1.85711 15.63170 0.00000
# cyl -1.43979 0.55214 -2.60766 0.01426
# disp -0.01546 0.00773 -1.99955 0.05499
#
# Call: rq(formula = mpg ~ cyl + disp, tau = c(0.05, 0.95), data = mtcars)
#
# tau: [1] 0.95
#
# Coefficients:
# Value Std. Error t value Pr(>|t|)
# (Intercept) 51.82250 6.18594 8.37747 0.00000
# cyl -4.70281 1.84648 -2.54691 0.01644
# disp 0.01250 0.02616 0.47785 0.63634
访问P.values
# fit.smy is a list, its length is the same as tau;
lapply(fit.smy, function(x){
x$coefficients[,4]
})
# [[1]]
# (Intercept) cyl disp
# 3.996803e-14 2.205166e-02 5.699536e-02
#
# [[2]]
# (Intercept) cyl disp
# 3.263261e-08 4.381427e-02 6.903882e-01
我想访问具有多个分位数的分位数回归的 p 值。
fit2 <- rq(speed ~ vsby_avg + snwd_avg, tau=c(.05, 0.95), data = test_data)
fit2_summ <- summary(fit2)
str(fit2_summ)
给出以下结果
List of 2
$ :List of 6
..$ call : language rq(formula = speed ~ vsby_avg + snwd_avg, tau = c(0.05, 0.95), data = test_data)
..$ terms :Classes 'terms', 'formula' language speed ~ vsby_avg + snwd_avg
.. .. ..- attr(*, "variables")= language list(speed, vsby_avg, snwd_avg)
..$ coefficients: num [1:3, 1:4] 57.63195 0.13474 -0.00337 0.1919 0.01212 ...
我无法使用 fit2_summ$coefficients[,4]
访问第 50 和第 95 分位数的 p 值,因为摘要模型存在于 2 个分位数而不是单个分位数,在这种情况下,上述命令将具有成功了。
你应该指定一个计算se的方法:
# using mtcars
library(quantreg)
fit <- rq(mpg ~ cyl + disp, tau = c(0.05, 0.95), data = mtcars)
fit.smy <- summary(fit, se = 'boot')
# > fit.smy
#
# Call: rq(formula = mpg ~ cyl + disp, tau = c(0.05, 0.95), data = mtcars)
#
# tau: [1] 0.05
#
# Coefficients:
# Value Std. Error t value Pr(>|t|)
# (Intercept) 29.02978 1.85711 15.63170 0.00000
# cyl -1.43979 0.55214 -2.60766 0.01426
# disp -0.01546 0.00773 -1.99955 0.05499
#
# Call: rq(formula = mpg ~ cyl + disp, tau = c(0.05, 0.95), data = mtcars)
#
# tau: [1] 0.95
#
# Coefficients:
# Value Std. Error t value Pr(>|t|)
# (Intercept) 51.82250 6.18594 8.37747 0.00000
# cyl -4.70281 1.84648 -2.54691 0.01644
# disp 0.01250 0.02616 0.47785 0.63634
访问P.values
# fit.smy is a list, its length is the same as tau;
lapply(fit.smy, function(x){
x$coefficients[,4]
})
# [[1]]
# (Intercept) cyl disp
# 3.996803e-14 2.205166e-02 5.699536e-02
#
# [[2]]
# (Intercept) cyl disp
# 3.263261e-08 4.381427e-02 6.903882e-01