lower and upper quartiles in boxplot in R

后端 未结 3 1178
温柔的废话
温柔的废话 2020-12-06 18:32

I have

X=c(20 ,18, 34, 45, 30, 51, 63, 52, 29, 36, 27, 24)

With boxplot, i\'m trying to plot the quantile(X,0.25)

3条回答
  •  失恋的感觉
    2020-12-06 19:20

    The values of the box are called hinges and may coincide with the quartiles (as calculated by quantile(x, c(0.25, .075))), but are calculated differently.

    From ?boxplot.stats:

    The two ‘hinges’ are versions of the first and third quartile, i.e., close to quantile(x, c(1,3)/4). The hinges equal the quartiles for odd n (where n <- length(x)) and differ for even n. Whereas the quartiles only equal observations for n %% 4 == 1 (n = 1 mod 4), the hinges do so additionally for n %% 4 == 2 (n = 2 mod 4), and are in the middle of two observations otherwise.

    To see that the values coincide with an odd number of observations, try the following code:

    set.seed(1234)
    x <- rnorm(9)
    
    boxplot(x)
    abline(h=quantile(x, c(0.25, 0.75)), col="red")
    

提交回复
热议问题