从分位数回归rqpd中提取系数和t值

时间:2016-04-13 22:47:38

标签: r coefficients

我有一个分位数回归模型如下:

rqpdfit <- rqpd(cr1 ~ x1 + x2 + x3 + x4 + x5 + x6 +x7|id, 
panel(lambda = 1,taus=c(0.1, 0.25, 0.5, 0.75, 0.9),tauw=rep(1/5, 5), method="pfe"),
 data =pdata)

为了生成输出表,我按分位数划分结果。

cf_10<- summary(rqpdfit)$coefficients[1:8,]

这是第一个分位数输出:

                             Value   Std. Error     t value     Pr(>|t|)                
      (Intercept)[0.1] 14.4864410152 11.670505897  1.24128647 2.145773e-01
    > x1[0.1]          -1.1081682804  1.230039754 -0.90092070 3.676881e-01
    > x2[0.1]           0.5036482698  0.097472484  5.16708152 2.501200e-07
    > x3[0.1]          -0.8077127317  0.282774725 -2.85638234 4.308473e-03
    > x4[0.1]           0.0006560821  0.008695294  0.07545255 9.398587e-01
    > x5[0.1]          -0.0102064486  0.043276674 -0.23584180 8.135683e-01
    > x6[0.1]          -0.1081589250  0.061636404 -1.75478966 7.937665e-02
    > x7[0.1]          -0.7891778648  0.251492587 -3.13797665 1.714334e-03

但是,我不知道如何在矩阵中提取系数和t值(如果可能的话,使用显着星)。

由于

1 个答案:

答案 0 :(得分:0)

只需尝试添加到上述线程。我按照上面的代码将结果导出为csv文件格式。

# y is the dependent variable 
# x6 is a vector of 6 independent variables. 
#setting regression
r6.form <- y ~ x6 |as.factor(cty)
r6090 <- rqpd(r6.form, panel= panel(taus=c(0.1, 0.25, 0.5, 0.75, 0.9), tauw = rep(1/5,5)), 
              na.action = 'na.omit', data=mydata)

#Storing results 
c6090 <- summary(r6090, se = "boot", R=1000, covariance = TRUE)

#making a data frame for results
df6 = as.data.frame(c6090$coefficients)

#coefficients and t-values in a matrix
cf_6 <- df6[1:71, c(1,3)]

#p-values
cf_6.pval <- df6[1:71,4]

#function to print stars
starPrinter <- function(pVal) {
  if(pVal < 0.01) return("***")
  if(pVal < 0.05) return("**")
  if(pVal < 0.1) return("*")

  return("")
}

# a matrix, with digits rounded to 3rd decimal
myTable6 <- round(cf_6, 3)

# get stars and put tvalues in parentheses
for(i in 1:nrow(myTable6)) {
  myTable6[i, 1] <- paste0(myTable6[i, 1], starPrinter(cf_6.pval[i]))
  myTable6[i, 2] <- paste0("(", myTable6[i, 2], ")")
}

#creating a vector
table.cf_6 <- (t(myTable6))

#exporting it to CSV file
write.table(table.cf_6, "c6090.csv", sep =',', row.names = TRUE)

这会将结果提取到具有变量名称的不同列中。