SCM

[#6061] fGarch::qsnorm() incorrect around p=0.5

Date:
2015-03-24 00:05
Priority:
3
State:
Closed
Submitted by:
William Scott (wscott)
Assigned to:
Georgi Boshnakov (geobosh)
Hardware:
PC
Product:
None
Operating System:
All
Component:
None
Version:
None
Severity:
normal
Resolution:
Fixed
URL:
Summary:
fGarch::qsnorm() incorrect around p=0.5

Detailed description
The qsnorm() function in fGarch appears to have a bug -- the calculation of the 0.5 quantile is smaller the the 0.49 quantile or the 0.51 quantile. Ie the quantile function is not increasing in p.

Eg:

> qsnorm(c(0.49,0.5,0.51)) # should be increasing
[1] -0.10071017 -0.59415042 -0.09171829

psnorm also appears to have some trouble:

> psnorm(qsnorm(c(0.49,0.5,0.51))) # should produce 0.49 0.50 0.51
[1] 0.5065415 0.5000000 0.5100000

I am using fGarch 3010.82, and R version 3.1.1.

Comments:

Message  ↓
Date: 2022-07-27 13:38
Sender: Georgi Boshnakov

Fixed in rev6260, thanks for the report. More details in inst/NEWS.Rd.

1. qsnorm() had problems in the centre of the distribution, worsening as the skew was getting further away from 1. The error was due to wrongly branching for the two pieces of the distribution (the symmetric case was ok).

2. psnorm(), amazingly, was wrong for the single wrong value returned by qsnorm(0.5). This was due to sign() returning zero when the argument was zero, introducing discontinuity.

3. The same problems were present for the other skewed distributions: qsstd, psstd, qsged, and psged. Fixed those as well.





Date: 2022-07-17 07:12
Sender: Georgi Boshnakov

At cursory look at the code of qsnorm, the bug seems to be for p=0.5 exactly. I have put a more detailed comment there.

TODO: the other skewed dist's may have the same problem since they use similar code.

TODO: check also psnorm. Given the above, it is strange that psnorm(qsnorm(0.5)) gives the correct 0.5.

Date: 2022-07-16 15:55
Sender: Georgi Boshnakov

The bug in `qsnorm` seems to be exactly for p = 1/2 due to the discontinuity of `sign`. I have added a comment in the source of `qsnorm`. As an illustration:calculation around p=1/2:
> which(diff(qsnorm(seq((0.5 -1/2^20),(0.5 + 1/2^20), length = 2^20 + 1))) <0)
[1] 524288

Date: 2022-07-16 08:06
Sender: Georgi Boshnakov

Thanks for the report. Indeed, there seems to be severe loss of accuracy as the asymmetry, xi, increases away from 1:

> plot(function(p) qsnorm(p, xi = 1), from = 0, to = 1)
> plot(function(p) qsnorm(p, xi = 1.1), from = 0, to = 1)
> plot(function(p) qsnorm(p, xi = 1.3), from = 0, to = 1)
> plot(function(p) qsnorm(p, xi = 1.5), from = 0, to = 1)
> plot(function(p) qsnorm(p, xi = 2), from = 0, to = 1)
Warning message:
In qnorm(p = p, sd = Xi) : NaNs produced

Attached Files:

Changes

Field Old Value Date By
assigned_tonone2022-08-02 09:23geobosh
ResolutionNone2022-07-28 06:54geobosh
status_idOpen2022-07-27 13:41geobosh
close_dateNone2022-07-27 13:41geobosh
Thanks to:
Vienna University of Economics and Business Powered By FusionForge