3

I am using the quantreg package from R to calculate quantile regression between 2 columns : red pixel values and near infrared pixel values (target). But the problem is that it gives me different values of t each time I execute the command with the same value of tau. Is this normal?

x=c(0.211799994111061, 0.220300003886223,0.20890000462532, 0.203099995851517, 0.183400005102158)
y=c(0.328099995851517, 0.342599987983704, 0.32370001077652, 0.319000005722046, 0.311599999666214)
library('quantreg')
qr = rq(y~x, tau =0.0001)
summary(qr, se = 'boot')

enter image description here

enter image description here

Stephan Kolassa
  • 95,027
  • 13
  • 197
  • 357
Ashraf.R
  • 55
  • 5

1 Answers1

5

You are calculating standard errors by bootstrapping (se='boot'), which is a randomization algorithm. This will yield different (random) results each time you run it.

If you want a completely reproducible analysis (which is often a very good idea!), you can set the seed value of the random number generator using set.seed(), yielding reproducible results. Compare

> set.seed(1)
> summary(qr, se = 'boot')

Call: rq(formula = y ~ x, tau = 1e-04)

tau: [1] 1e-04

Coefficients:
            Value   Std. Error t value Pr(>|t|)
(Intercept) 0.15442 0.09419    1.63949 0.19964 
x           0.81034 0.45491    1.78133 0.17289 

with

> set.seed(1)
> summary(qr, se = 'boot')

Call: rq(formula = y ~ x, tau = 1e-04)

tau: [1] 1e-04

Coefficients:
            Value   Std. Error t value Pr(>|t|)
(Intercept) 0.15442 0.09419    1.63949 0.19964 
x           0.81034 0.45491    1.78133 0.17289 
Stephan Kolassa
  • 95,027
  • 13
  • 197
  • 357
  • Yes. It works now. Thank you very much. I am not very familiar with coding but I needed quantile regression before I can move on with my study – Ashraf.R Nov 03 '21 at 16:51
  • 1
    @Ashraf.R You might also want to increase the number of bootstrap resamples (default is `R = 200`) if the estimate of the standed error or t-value is important to you for some reason. – Roland Nov 04 '21 at 07:19