Search code examples
r-mosaic

Two tails in distribution plots


I'm learning statistics and R using the mosaic package, amongst others. For a two tailed test it would be useful if I could see(and get the results) from distribution functions without having to multiply by 2.

Is there any way do to this in the current version of mosaic?

Eg. instead of xpnorm(1.96, lower.tail = FALSE) * 2 I'd like to get the same result without multiplying by 2 and shade both tails.


Solution

  • xpnorm() intentionally follows pnorm(), so each only handles one (type of) tail. You can, however, specify multiple cut points (say c(-1.96, 1.96)) to get a picture with two tails shaded. But you will still need to some additional arithmetic to get the sum of two tail probabilities.

    library(mosaic)
    xpnorm(c(-1.96, 1.96))
    #> 
    #> If X ~ N(0, 1), then
    #>  P(X <= -1.96) = P(Z <= -1.96) = 0.025   P(X <=  1.96) = P(Z <=  1.96) = 0.975
    #>  P(X >  -1.96) = P(Z >  -1.96) = 0.975   P(X >   1.96) = P(Z >   1.96) = 0.025
    #> 
    

    #> [1] 0.0249979 0.9750021
    

    Created on 2018-08-10 by the reprex package (v0.2.0).

    Going in the other direction (if you know the probability and want to find critical values), we have introduced xcnorm() for finding end points bounding a specified central probability. Here is an example:

    library(mosaic)
    
    xcnorm(0.90)
    #> 
    #> If X ~ N(0, 1), then
    #>  P(X <= -1.644854) = 0.05    P(X <=  1.644854) = 0.95
    #>  P(X >  -1.644854) = 0.95    P(X >   1.644854) = 0.05
    #> 
    

    #> [1] -1.644854  1.644854
    

    Created on 2018-08-10 by the reprex package (v0.2.0).