Skip to content

Tidy summarizes information about the components of a model. A model component might be a single term in a regression, a single hypothesis, a cluster, or a class. Exactly what tidy considers to be a model component varies across models but is usually self-evident. If a model has several distinct types of components, you will need to specify which components to return.

Usage

# S3 method for class 'rq'
tidy(x, se.type = NULL, conf.int = FALSE, conf.level = 0.95, ...)

Arguments

x

An rq object returned from quantreg::rq().

se.type

Character specifying the method to use to calculate standard errors. Passed to quantreg::summary.rq() se argument. Defaults to "rank" if the sample size is less than 1000, otherwise defaults to "nid".

conf.int

Logical indicating whether or not to include a confidence interval in the tidied output. Defaults to FALSE.

conf.level

The confidence level to use for the confidence interval if conf.int = TRUE. Must be strictly greater than 0 and less than 1. Defaults to 0.95, which corresponds to a 95 percent confidence interval.

...

Additional arguments passed to quantreg::summary.rq().

Details

If se.type = "rank" confidence intervals are calculated by summary.rq and statistic and p.value values are not returned. When only a single predictor is included in the model, no confidence intervals are calculated and the confidence limits are set to NA.

See also

Value

A tibble::tibble() with columns:

conf.high

Upper bound on the confidence interval for the estimate.

conf.low

Lower bound on the confidence interval for the estimate.

estimate

The estimated value of the regression term.

p.value

The two-sided p-value associated with the observed statistic.

statistic

The value of a T-statistic to use in a hypothesis that the regression term is non-zero.

std.error

The standard error of the regression term.

term

The name of the regression term.

Examples


# load modeling library and data
library(quantreg)

data(stackloss)

# median (l1) regression fit for the stackloss data.
mod1 <- rq(stack.loss ~ stack.x, .5)

# weighted sample median
mod2 <- rq(rnorm(50) ~ 1, weights = runif(50))

# summarize model fit with tidiers
tidy(mod1)
#> # A tibble: 4 × 5
#>   term              estimate conf.low conf.high   tau
#>   <chr>                <dbl>    <dbl>     <dbl> <dbl>
#> 1 (Intercept)       -39.7     -53.8    -24.5      0.5
#> 2 stack.xAir.Flow     0.832     0.509    1.17     0.5
#> 3 stack.xWater.Temp   0.574     0.272    3.04     0.5
#> 4 stack.xAcid.Conc.  -0.0609   -0.278    0.0153   0.5
glance(mod1)
#> # A tibble: 1 × 5
#>     tau logLik      AIC   BIC df.residual
#>   <dbl> <logLik>  <dbl> <dbl>       <int>
#> 1   0.5 -50.15272  108.  112.          17
augment(mod1)
#> # A tibble: 21 × 5
#>    stack.loss stack.x[,"Air.Flow"] [,"Water.Temp"]    .resid .fitted  .tau
#>         <dbl>                <dbl>           <dbl>     <dbl>   <dbl> <dbl>
#>  1         42                   80              27  5.06e+ 0    36.9   0.5
#>  2         37                   80              27 -1.42e-14    37     0.5
#>  3         37                   75              25  5.43e+ 0    31.6   0.5
#>  4         28                   62              24  7.63e+ 0    20.4   0.5
#>  5         18                   62              22 -1.22e+ 0    19.2   0.5
#>  6         18                   62              23 -1.79e+ 0    19.8   0.5
#>  7         19                   62              24 -1.00e+ 0    20     0.5
#>  8         20                   62              24 -7.11e-15    20     0.5
#>  9         15                   58              23 -1.46e+ 0    16.5   0.5
#> 10         14                   58              18 -2.03e- 2    14.0   0.5
#> # ℹ 11 more rows
#> # ℹ 1 more variable: stack.x[3] <dbl>

tidy(mod2)
#> # A tibble: 1 × 5
#>   term        estimate conf.low conf.high   tau
#>   <chr>          <dbl> <lgl>    <lgl>     <dbl>
#> 1 (Intercept)    0.124 NA       NA          0.5
glance(mod2)
#> # A tibble: 1 × 5
#>     tau logLik      AIC   BIC df.residual
#>   <dbl> <logLik>  <dbl> <dbl>       <int>
#> 1   0.5 -78.76986  160.  161.          49
augment(mod2)
#> # A tibble: 50 × 5
#>    `rnorm(50)` `(weights)` .resid .fitted  .tau
#>          <dbl>       <dbl>  <dbl>   <dbl> <dbl>
#>  1     0.393       0.696    0.269   0.124   0.5
#>  2     0.458       0.266    0.334   0.124   0.5
#>  3    -1.22        0.660   -1.34    0.124   0.5
#>  4    -1.12        0.212   -1.25    0.124   0.5
#>  5     0.993       0.00527  0.869   0.124   0.5
#>  6    -1.83        0.103   -1.96    0.124   0.5
#>  7     0.124       0.287    0       0.124   0.5
#>  8     0.591       0.444    0.467   0.124   0.5
#>  9     0.805       0.693    0.681   0.124   0.5
#> 10     0.00754     0.0209  -0.116   0.124   0.5
#> # ℹ 40 more rows

# varying tau to generate an rqs object
mod3 <- rq(stack.loss ~ stack.x, tau = c(.25, .5))

tidy(mod3)
#> # A tibble: 8 × 5
#>   term               estimate conf.low conf.high   tau
#>   <chr>                 <dbl>    <dbl>     <dbl> <dbl>
#> 1 (Intercept)       -3.6 e+ 1  -59.0     -7.84    0.25
#> 2 stack.xAir.Flow    5.00e- 1    0.229    0.970   0.25
#> 3 stack.xWater.Temp  1.00e+ 0    0.286    2.26    0.25
#> 4 stack.xAcid.Conc. -4.58e-16   -0.643    0.0861  0.25
#> 5 (Intercept)       -3.97e+ 1  -53.8    -24.5     0.5 
#> 6 stack.xAir.Flow    8.32e- 1    0.509    1.17    0.5 
#> 7 stack.xWater.Temp  5.74e- 1    0.272    3.04    0.5 
#> 8 stack.xAcid.Conc. -6.09e- 2   -0.278    0.0153  0.5 
augment(mod3)
#> # A tibble: 42 × 5
#>    stack.loss stack.x[,"Air.Flow"] [,"Water.Temp"] .tau     .resid .fitted
#>         <dbl>                <dbl>           <dbl> <chr>     <dbl>   <dbl>
#>  1         42                   80              27 0.25   1.10e+ 1    31.0
#>  2         42                   80              27 0.5    5.06e+ 0    36.9
#>  3         37                   80              27 0.25   6.00e+ 0    31.0
#>  4         37                   80              27 0.5   -1.42e-14    37  
#>  5         37                   75              25 0.25   1.05e+ 1    26.5
#>  6         37                   75              25 0.5    5.43e+ 0    31.6
#>  7         28                   62              24 0.25   9.00e+ 0    19  
#>  8         28                   62              24 0.5    7.63e+ 0    20.4
#>  9         18                   62              22 0.25   1.00e+ 0    17.0
#> 10         18                   62              22 0.5   -1.22e+ 0    19.2
#> # ℹ 32 more rows
#> # ℹ 1 more variable: stack.x[3] <dbl>

# glance cannot handle rqs objects like `mod3`--use a purrr
# `map`-based workflow instead