# [R] function for inverse normal transformation

Fri Jul 20 20:33:29 CEST 2012

```Hello,

Yes, Carol is comparing what can't be compared. Your code should do it,
I hope.

Em 20-07-2012 15:12, David L Carlson escreveu:
> Rui's example included z-score data (drawn from rnorm). You converted your
> data to z-scores so you need to compare your results to the z-scores not
> the original data.
>
> Change these lines:
>
> tmp.qnorm = qnorm(tmp.p/2,lower.tail=FALSE)*sign(scale(tmp))
> # sign is of scale(tmp) not tmp
> equal(scale(tmp), tmp.qnorm)
> # compare to scale(tmp) not tmp
>
> ----------------------------------------------
> David L Carlson
> Associate Professor of Anthropology
> Texas A&M University
> College Station, TX 77843-4352
>
>> -----Original Message-----
>> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
>> project.org] On Behalf Of carol white
>> Sent: Friday, July 20, 2012 7:29 AM
>> Cc: r-help at r-project.org
>> Subject: Re: [R] function for inverse normal transformation
>>
>> Thanks Rui.
>> I changed my scripts to the followings and I think that it still is not
>>
>>
>>
>>   tmp
>>   [1]  2.502519  1.828576  3.755778 17.415000  3.779296  2.956850
>> 2.379663
>>   [8]  1.103559  8.920316  2.744500  2.938480  7.522174 10.629200
>> 8.552259
>> [15]  5.425938  4.388906  0.000000  0.723887 11.337860  3.763786
>>
>>
>>   tmp.p =2*pnorm(abs(scale(tmp)),lower.tail=FALSE)
>>>    tmp.qnorm = qnorm(tmp.p/2,lower.tail=FALSE)
>>>    tmp.qnorm = qnorm(tmp.p/2,lower.tail=FALSE)*sign(tmp)
>>> equal(tmp, tmp.qnorm)
>> [1] FALSE
>>> par(mfrow = c(1,3))
>>> hist(tmp)
>>> hist(tmp.p)
>>> hist(tmp.qnorm)
>>
>>
>> ________________________________
>> To: carol white <wht_crl at yahoo.com>
>> Cc: r-help <r-help at r-project.org>
>> Sent: Friday, July 20, 2012 2:02 PM
>> Subject: Re: [R] function for inverse normal transformation
>>
>>
>> Hello,
>>
>> No it's not correct, you are computing a what seems to be a
>>      two-tailed probabiity, so the inverse should account for it. Look
>>      closely: you take the absolute value, then the upper tail
>>      probability, then multiply 2 into it. Reverse these steps to get
>> the
>>      correct value.
>>
>> # Helper function
>> equal <- function(x, y, tol=.Machine\$double.eps^0.5) all(abs(x -
>>      y)  < tol)
>>
>> m <- rnorm(5)
>> p <- 2*pnorm(abs(m), lower.tail=FALSE)
>> m2 <- qnorm(p/2, lower.tail=FALSE)*sign(m)
>>
>> equal(m, m2)
>>
>> (The helper function is just to test floating point values computed
>>      differently for equality.)
>>
>> Hope this helps,
>>
>>
>>
>> Em 20-07-2012 12:36, carol white escreveu:
>>
>> Thanks for your reply. So to derive it from a given data set, is the
>> following correct to do? my_data.p
>> =2*pnorm(abs(my_data),lower.tail=FALSE) my_data.q = qnorm(my_data.p)
>> Cheers, ________________________________ From: Duncan Murdoch
>> <murdoch.duncan at gmail.com> Cc: "r-help at stat.math.ethz.ch" <r-
>> help at stat.math.ethz.ch> Sent: Friday, July 20, 2012 1:23 PM
>> Subject: Re: [R] function for inverse normal transformation On 12-07-20
>> 6:21 AM, carol white wrote:
>>> Hi,
>> What is the function for inverse normal transformation?
>>> qnorm Duncan Murdoch
>>> Thanks, Carol     [[alternative HTML version deleted]]
>> ______________________________________________ R-help at r-project.org
>> mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
>> read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>> [[alternative HTML version deleted]]
>>>
>>>
>>> ______________________________________________ R-help at r-project.org
>> mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
>> read the posting guide http://www.R-project.org/posting-guide.html and
>> provide commented, minimal, self-contained, reproducible code.

```