-1

I have vector $x=[3, 5, 7, 8, 12, 13, 14, 18, 21]$ and wanted to see summary statistics.

if I use summary(x) function in R, My anwser

 Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   3.00    7.00   12.00   11.22   14.00   21.00

But actual anwser is Q1 = 6 and Q2=16

What is the difference ?

deemel
  • 2,704
  • 4
  • 22
  • 41
SCOTT
  • 1

1 Answers1

1

x is ordered and has $N = 9$.

The median is the element of position $(N + 1) / 2 = 5$, i.e. $12$.

The half samples $\{3,\, 5,\, 7,\, 8,\, 12\}$ and $\{12,\, 13,\, 14,\, 18,\, 21\}$ have $n = 5$.

The median of the half samples, i.e. $Q_1$ and $Q_3$ of x, are the elements of position $(n + 1) / 2 = 3$, i.e. $7$ and $14$, as returned by sample(x).

ocram
  • 21,851
  • x<-c(1,2,3,4,4,5)

    summary(x)

    Min. 1st Qu. Median Mean 3rd Qu. Max. 1.000 2.250 3.500 3.167 4.000 5.000 In this case how it works please explain? @ocram

    – SCOTT May 14 '18 at 13:45
  • 1
    Please type help(quantile) at the R console and see the different approaches to that problem, that R has to offer. The heading "Types" is the most relevant one. – Bernhard May 14 '18 at 14:43