Professional Documents
Culture Documents
with R
2020/2/22
Summary statistics for a single group
set.seed(1234)
x <- rnorm(1000)
mean(x) #mean
## [1] -0.0265972
## [1] 0.9973377
var(x) #variance
## [1] 0.9946825
median(x) #median
## [1] -0.03979419
Summary statistics for a single group
quantile(x) #quantile
By default you get the minimum, the maximum, and the three
quartiles — the 0.25, 0.50, and 0.75 quantiles.
pvec <- seq(0,1,0.1)
quantile(x, pvec)
100
50
0
−3 −2 −1 0 1 2 3
x
Graphical display of distributions
I Empirical cumulative distribution
y <- rnorm(50)
n <- length(y)
plot(sort(y),(1:n)/n,type="s",ylim=c(0,1))
1.0
0.8
0.6
(1:n)/n
0.4
0.2
0.0
−2 −1 0 1 2
sort(y)
Graphical display of distributions
0
−1
−2
−2 −1 0 1 2
Graphics for grouped data
h1 <- min(Galton$mother)
h2 <- max(Galton$father)
hist(Galton$father,breaks = 100,xlim = c(h1,h2),
ylim=c(0,150),col="white")
hist(Galton$mother,breaks = 100,xlim = c(h1,h2),
ylim=c(0,150),col="grey")
Graphics for grouped data
I Parallel boxplots
boxplot(Galton[c("father","mother")])
75
70
65
60
father mother