I executed the following code:
tau <- 0.25
h <- 0.6 * n ^ (-1 / 5) * (4.5 * dnorm(qnorm(tau)) ^ 4 * qnorm(tau) /
(2 * (qnorm(tau) ^ 2 + 1)) ^ 2) ^ (1/5),
and R keeps producing NaN
. However, R actually computes (4.5 * dnorm(qnorm(tau)) ^ 4 * qnorm(tau) / (2 * (qnorm(tau) ^ 2 + 1)) ^ 2)
to be equal to -0.003655336
.
The weird thing is when I did the following
k <- -0.003655336
k ^ (1 / 3)
NaN
was produced again.
The 5-th root of a negative number is still possible. Also my pocket calculator does it. Since (-1)^5=-1, you can do it this way:
Please edit your question. And you gave yourself the answer. Is basic math. You can't give a power of a negative number to a power of a decimal number. It is an indetermination.
You are calculating the cube root of a negative number. Although, as pointed out by @mra68, a real solution exists, the general case of non-integer exponents of negative numbers results in a complex number. Since by default R assumes that you are dealing with real numbers, it produces
NaN
.Try this:
The result is not unique in the sense that there are three complex numbers
x
satisfying the conditionx^3=k
(including the case where the imaginary component is zero), but theNaN
output is consistent with the general case case of non-integer numbers as exponents of negative real numbers. It may be argued that a distinction between rational and non-rational exponents could be useful, but in floating-point calculations this is hardly possible. I would consider the occurrence ofNaN
in the case of non-integer exponents of negative numbers as a useful warning sign.